-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not return an error from Systemd.ForceStop(svc) if svc is already stopped #11667
Conversation
/ok-to-test |
@@ -123,7 +125,14 @@ func (s *Systemd) Stop(svc string) error { | |||
|
|||
// ForceStop terminates a service with prejudice | |||
func (s *Systemd) ForceStop(svc string) error { | |||
_, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) | |||
rr, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) | |||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this if statement isn't really necessary, return err
will return nil if err is nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with @sharifelgamal this "if" is not needed !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
lets us to avoid matching substrings in strings.Contains
. Also the whole logic is clearer with this shortcut - if systemctl
returned ok - return immediately as no extra processing required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this "if statement" adds to the code complexity in terms of number of If statments. and makes the code harder to read without gaining anything meaningful in terms of cpu cycles.
this is not inline with go style used in minikube, I suggest getting rid of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, how it makes the code harder to read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilya-zuyev
because following the code we dont expect to check for err nil and return while it already returns,
a typical go reader with following the styles is used to look at the return and it is obvisous if it is nil it returns nil too.
while this might be easier for the one writing this code to explicitly add the If statement here, for the go reviewer is not common to see it
"Gocyclo calculates cyclomatic complexities of functions in Go source code. The cyclomatic complexity of a function is calculated according to the following rules: 1 is the base complexity of a function +1 for each 'if', 'for', 'case', '&&' or '||' Go Report Card warns on functions with cyclomatic complexity > 1"
plus it adds to the go "gocyclo" score https://goreportcard.com/report/github.com/kubernetes/minikube
so the less If statments, the better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because following the code we dont expect to check for err nil and return while it already returns, a typical go reader with following the styles is used to look at the return and it is obvisous if it is nil it returns nil too.
I don't understand this sentence
Cyclomatic complexity metric evaluates the number of branches inside the function, its goal is to prevent functions overgrow. This method is 7 lines long, talking about cyclomatic complexity makes no sense here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not inline with minikube code style, it doesn't make sense to check for "nil" and return while we are returning in next line anyways, this an example of code seems easier to "write" but overtime will make it harder to "maintain"
I suggest reading more minikube code or https://www.kubernetes.dev/docs/guide/coding-convention/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't personally think this is more complex, it's just an awkward line of code for a small optimization.
kvm2 driver with docker runtime
Times for minikube (PR 11667) start: 47.3s 47.2s 46.3s 46.1s 50.1s Times for minikube ingress: 36.3s 34.2s 34.7s 33.8s 33.6s docker driver with docker runtime
Times for minikube start: 23.4s 20.6s 21.5s 21.5s 21.4s Times for minikube ingress: 27.0s 32.0s 28.0s 29.0s 28.5s docker driver with containerd runtime
Times for minikube start: 32.0s 48.9s 47.2s 43.2s 47.4s |
@@ -123,7 +125,14 @@ func (s *Systemd) Stop(svc string) error { | |||
|
|||
// ForceStop terminates a service with prejudice | |||
func (s *Systemd) ForceStop(svc string) error { | |||
_, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) | |||
rr, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) | |||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with @sharifelgamal this "if" is not needed !
@@ -123,7 +125,14 @@ func (s *Systemd) Stop(svc string) error { | |||
|
|||
// ForceStop terminates a service with prejudice | |||
func (s *Systemd) ForceStop(svc string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding this to openRC too
https://github.com/medyagh/minikube/blob/1bac30bbe7caa5b8c64b35cfb97c197ffe08840a/pkg/minikube/sysinit/openrc.go#L166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what to do there. This PR is targeting a very specific systemd issue
@@ -123,7 +125,14 @@ func (s *Systemd) Stop(svc string) error { | |||
|
|||
// ForceStop terminates a service with prejudice | |||
func (s *Systemd) ForceStop(svc string) error { | |||
_, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) | |||
rr, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) | |||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this "if statement" adds to the code complexity in terms of number of If statments. and makes the code harder to read without gaining anything meaningful in terms of cpu cycles.
this is not inline with go style used in minikube, I suggest getting rid of it
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ilya-zuyev, medyagh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
plz pull upstream and then it is good to go |
kvm2 driver with docker runtime
Times for minikube start: 48.6s 45.8s 45.8s 46.4s 51.6s Times for minikube ingress: 32.8s 35.2s 33.2s 35.7s 35.2s docker driver with docker runtime
Times for minikube start: 22.9s 21.0s 21.4s 22.0s 21.2s Times for minikube ingress: 28.5s 31.0s 28.5s 37.0s 30.5s docker driver with containerd runtime
Times for minikube start: 31.8s 43.5s 46.7s 43.0s 42.8s |
These are the flake rates of all failed tests on KVM_Linux_containerd.
|
@ilya-zuyev
|
kvm2 driver with docker runtime
Times for minikube ingress: 35.8s 35.7s 33.8s 34.7s 35.8s Times for minikube start: 56.0s 51.8s 51.5s 51.9s 51.0s docker driver with docker runtime
Times for minikube (PR 11667) start: 21.7s 21.3s 22.8s 22.7s 22.2s Times for minikube ingress: 30.5s 29.0s 29.0s 28.6s 29.1s docker driver with containerd runtime
Times for minikube start: 47.7s 44.4s 47.5s 43.5s 43.4s |
Fixes #11622