-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,9 @@ package sysinit | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"k8s.io/minikube/pkg/minikube/assets" | ||
) | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. this if statement isn't really necessary, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @ilya-zuyev "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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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 commentThe 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. |
||
return nil | ||
} | ||
if strings.Contains(rr.Output(), fmt.Sprintf("Unit %s not loaded", svc)) { | ||
// already stopped | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
|
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