Skip to content
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

Merged
merged 3 commits into from
Jun 22, 2021

Conversation

ilya-zuyev
Copy link
Contributor

Fixes #11622

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 15, 2021
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 15, 2021
@ilya-zuyev
Copy link
Contributor Author

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jun 15, 2021
@@ -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 {
Copy link
Collaborator

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

Copy link
Member

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 !

Copy link
Contributor Author

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

Copy link
Member

@medyagh medyagh Jun 18, 2021

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

Copy link
Contributor Author

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?

Copy link
Member

@medyagh medyagh Jun 21, 2021

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

Copy link
Contributor Author

@ilya-zuyev ilya-zuyev Jun 21, 2021

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.

Copy link
Member

@medyagh medyagh Jun 21, 2021

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/

Copy link
Collaborator

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.

@minikube-pr-bot
Copy link

kvm2 driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 47.4s    | 47.4s               |
| enable ingress | 34.5s    | 35.6s               |
+----------------+----------+---------------------+

Times for minikube (PR 11667) start: 47.3s 47.2s 46.3s 46.1s 50.1s
Times for minikube start: 47.8s 47.0s 46.4s 47.1s 48.6s

Times for minikube ingress: 36.3s 34.2s 34.7s 33.8s 33.6s
Times for minikube (PR 11667) ingress: 36.2s 34.7s 35.7s 37.2s 34.2s

docker driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 21.7s    | 21.7s               |
| enable ingress | 28.9s    | 29.2s               |
+----------------+----------+---------------------+

Times for minikube start: 23.4s 20.6s 21.5s 21.5s 21.4s
Times for minikube (PR 11667) start: 21.3s 22.4s 21.5s 21.0s 22.2s

Times for minikube ingress: 27.0s 32.0s 28.0s 29.0s 28.5s
Times for minikube (PR 11667) ingress: 29.0s 30.5s 30.5s 28.0s 28.0s

docker driver with containerd runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 43.8s    | 45.6s               |
| enable ingress |          |                     |
+----------------+----------+---------------------+

Times for minikube start: 32.0s 48.9s 47.2s 43.2s 47.4s
Times for minikube (PR 11667) start: 46.8s 42.5s 47.6s 43.5s 47.7s

@@ -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 {
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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 {
Copy link
Member

@medyagh medyagh Jun 18, 2021

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

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@medyagh
Copy link
Member

medyagh commented Jun 21, 2021

plz pull upstream and then it is good to go

@minikube-pr-bot
Copy link

kvm2 driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 47.6s    | 47.1s               |
| enable ingress | 34.4s    | 34.4s               |
+----------------+----------+---------------------+

Times for minikube start: 48.6s 45.8s 45.8s 46.4s 51.6s
Times for minikube (PR 11667) start: 47.1s 46.9s 47.2s 47.1s 47.4s

Times for minikube ingress: 32.8s 35.2s 33.2s 35.7s 35.2s
Times for minikube (PR 11667) ingress: 35.2s 35.2s 34.2s 34.2s 33.2s

docker driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 21.7s    | 21.2s               |
| enable ingress | 31.1s    | 31.9s               |
+----------------+----------+---------------------+

Times for minikube start: 22.9s 21.0s 21.4s 22.0s 21.2s
Times for minikube (PR 11667) start: 20.6s 21.1s 21.5s 21.2s 21.4s

Times for minikube ingress: 28.5s 31.0s 28.5s 37.0s 30.5s
Times for minikube (PR 11667) ingress: 29.0s 30.5s 32.5s 31.0s 36.5s

docker driver with containerd runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 41.6s    | 44.7s               |
| enable ingress |          |                     |
+----------------+----------+---------------------+

Times for minikube start: 31.8s 43.5s 46.7s 43.0s 42.8s
Times for minikube (PR 11667) start: 46.6s 42.8s 43.2s 47.1s 43.9s

@minikube-bot
Copy link
Collaborator

These are the flake rates of all failed tests on Docker_Linux_containerd.

Failed Tests Flake Rate (%)
TestPause/serial/Pause 14.29 (chart)
TestPause/serial/VerifyStatus 14.29 (chart)
TestPause/serial/PauseAgain 19.48 (chart)

@minikube-bot
Copy link
Collaborator

These are the flake rates of all failed tests on KVM_Linux_containerd.

Failed Tests Flake Rate (%)
TestErrorSpam/setup 100.00 (chart)

@medyagh
Copy link
Member

medyagh commented Jun 22, 2021

@ilya-zuyev
this PR doesnt seem to fix the failed test
https://storage.googleapis.com/minikube-builds/logs/11667/5a3ad1e/KVM_Linux_containerd.html#fail_TestErrorSpam%2fsetup

error_spam_test.go:108: minikube stderr:
E0622 01:56:15.187503    9483 docker.go:159] "Failed to stop" err="sudo systemctl stop -f docker.service: Process exited with status 5\nstdout:\n\nstderr:\nFailed to stop docker.service: Unit docker.service not loaded.\n" service="docker.service"

@medyagh medyagh self-requested a review June 22, 2021 04:03
@minikube-pr-bot
Copy link

kvm2 driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 52.4s    | 49.7s               |
| enable ingress | 35.2s    | 36.0s               |
+----------------+----------+---------------------+

Times for minikube ingress: 35.8s 35.7s 33.8s 34.7s 35.8s
Times for minikube (PR 11667) ingress: 40.4s 35.7s 35.2s 34.2s 34.7s

Times for minikube start: 56.0s 51.8s 51.5s 51.9s 51.0s
Times for minikube (PR 11667) start: 51.5s 49.0s 47.2s 51.6s 49.0s

docker driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 22.1s    | 22.1s               |
| enable ingress | 29.2s    | 31.0s               |
+----------------+----------+---------------------+

Times for minikube (PR 11667) start: 21.7s 21.3s 22.8s 22.7s 22.2s
Times for minikube start: 22.3s 22.7s 21.7s 22.4s 21.4s

Times for minikube ingress: 30.5s 29.0s 29.0s 28.6s 29.1s
Times for minikube (PR 11667) ingress: 29.5s 33.5s 32.5s 31.0s 28.5s

docker driver with containerd runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 11667) |
+----------------+----------+---------------------+
| minikube start | 45.3s    | 45.1s               |
| enable ingress |          |                     |
+----------------+----------+---------------------+

Times for minikube start: 47.7s 44.4s 47.5s 43.5s 43.4s
Times for minikube (PR 11667) start: 47.2s 43.2s 47.7s 43.4s 44.1s

@ilya-zuyev ilya-zuyev merged commit d4fe773 into kubernetes:master Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
6 participants