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 try to run preStopHook when the gracePeriod is 0 #49449

Merged
merged 1 commit into from
Aug 3, 2017

Conversation

dhilipkumars
Copy link

@dhilipkumars dhilipkumars commented Jul 22, 2017

What this PR does / why we need it:

  1. Sometimes when the user force deletes a POD with no gracePeriod, its possible that kubelet attempts to execute the preStopHook which will certainly fail. This PR prevents this inavitable PreStopHook failure.
kubectl delete --force --grace-period=0 po/<pod-name>
  1. This also adds UT for LifeCycle Hooks
time go test --cover -v --run "Hook" ./pkg/kubelet/kuberuntime/
.
.
.
--- PASS: TestLifeCycleHook (0.00s)
    --- PASS: TestLifeCycleHook/PreStop-CMDExec (0.00s)
    --- PASS: TestLifeCycleHook/PreStop-HTTPGet (0.00s)
    --- PASS: TestLifeCycleHook/PreStop-NoTimeToRun (0.00s)
    --- PASS: TestLifeCycleHook/PostStart-CmdExe (0.00s)
PASS
coverage: 15.3% of statements
ok      k8s.io/kubernetes/pkg/kubelet/kuberuntime       0.429s

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

Release note:

Do not try to run preStopHook when the gracePeriod is 0

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 22, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jul 22, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @dhilipkumars. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 22, 2017
@dhilipkumars
Copy link
Author

cc: @dchen1107 and @derekwaynecarr

@dhilipkumars
Copy link
Author

/sig node
/sig app-lifecycle
/area app-lifecycle

@k8s-ci-robot k8s-ci-robot added sig/node Categorizes an issue or PR as relevant to SIG Node. area/app-lifecycle labels Jul 22, 2017
@@ -28,6 +28,8 @@ import (
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
"strings"
Copy link
Member

Choose a reason for hiding this comment

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

Need running gofmt.

Copy link
Author

Choose a reason for hiding this comment

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

they are go fmt'ed but gofmt wouldnt re-arrange imports, now fixed.

@dhilipkumars
Copy link
Author

/sig node-reviewers

@@ -20,6 +20,7 @@ import (
"path/filepath"
"testing"
"time"
"strings"
Copy link
Member

Choose a reason for hiding this comment

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

This is not still right. Should use gofmt to update.

Copy link
Author

Choose a reason for hiding this comment

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

okay got the problem, I was doing go fmt instead of gofmt, now fixed. PTAL

@dhilipkumars
Copy link
Author

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 28, 2017
@resouer
Copy link
Contributor

resouer commented Jul 29, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 29, 2017
Copy link
Contributor

@resouer resouer left a comment

Choose a reason for hiding this comment

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

Please fix CI first, then I will review

@dhilipkumars
Copy link
Author

/test pull-kubernetes-verify
/test pull-kubernetes-bazel

@dhilipkumars
Copy link
Author

/test pull-kubernetes-e2e-gce-etcd3

@dhilipkumars
Copy link
Author

/test pull-kubernetes-e2e-gce-etcd3

1 similar comment
@dhilipkumars
Copy link
Author

/test pull-kubernetes-e2e-gce-etcd3

@dhilipkumars
Copy link
Author

@resouer looks like a flake the failures are unrelated.

/test pull-kubernetes-e2e-gce-etcd3

@dhilipkumars
Copy link
Author

dhilipkumars commented Jul 29, 2017

Flake #49761

@dhilipkumars
Copy link
Author

/retest

@resouer
Copy link
Contributor

resouer commented Jul 30, 2017

/test pull-kubernetes-e2e-gce-etcd3

Copy link
Contributor

@resouer resouer left a comment

Choose a reason for hiding this comment

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

lgtm, let's run test again

@resouer
Copy link
Contributor

resouer commented Jul 31, 2017

Kindly ping @tallclair @Random-Liu , the code lgtm, please take a final look, thanks!

@dhilipkumars
Copy link
Author

/test pull-kubernetes-e2e-kops-aw

1 similar comment
@dhilipkumars
Copy link
Author

/test pull-kubernetes-e2e-kops-aw

@dhilipkumars
Copy link
Author

/retest

@resouer
Copy link
Contributor

resouer commented Aug 1, 2017

The pull-kubernetes-e2e-kops-aws is flake, I noticed it fails in many PRs.

@dhilipkumars
Copy link
Author

Flake: #48223

@dhilipkumars
Copy link
Author

/retest

1 similar comment
@dhilipkumars
Copy link
Author

/retest

Copy link
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

Just needs a little cleanup, logic looks good.

@@ -75,7 +75,6 @@ func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS
if err != nil {
return nil, err
}

Copy link
Member

Choose a reason for hiding this comment

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

nit: try not to include stray changes like this.

//TestCase 1: Configured and works as expected
t.Run("PreStop-CMDExec", func(t *testing.T) {
testPod.Spec.Containers[0].Lifecycle = cmdLifeCycle
//m.executePreStopHook(testPod, cID, &testPod.Spec.Containers[0], gracePeriod)
Copy link
Member

Choose a reason for hiding this comment

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

delete this

//m.executePreStopHook(testPod, cID, &testPod.Spec.Containers[0], gracePeriod)
m.killContainer(testPod, cID, "foo", "testKill", &gracePeriod)
if fakeRunner.Cmd[0] != cmdLifeCycle.PreStop.Exec.Command[0] {
t.Errorf("CMD Prestop hook is no invoked")
Copy link
Member

Choose a reason for hiding this comment

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

s/is no/was not/


m.runner = lcHanlder

//TestCase 1: Configured and works as expected
Copy link
Member

Choose a reason for hiding this comment

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

Nit: delete the enumeration in the comment (they just become annoying to update when test cases are added). Just the description part is sufficient.


//TestCase 3: When there is no time to run PreStopHook
t.Run("PreStop-NoTimeToRun", func(t *testing.T) {
defer func() { gracePeriod = 30 }()
Copy link
Member

Choose a reason for hiding this comment

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

rather than overriding this, just define a local version

gracePeriod = 0

m.killContainer(testPod, cID, "foo", "testKill", &gracePeriod)
//m.executePreStopHook(testPod, cID, &testPod.Spec.Containers[0], gracePeriod)
Copy link
Member

Choose a reason for hiding this comment

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

delete

//TestCase 4: Post Start script
t.Run("PostStart-CmdExe", func(t *testing.T) {

//Fake all the things you need before trying to create a container
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a space after //, here and everywhere.

},
}

//Now try to create a container, which should inturn invoke PostStart Hook
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/inturn/in turn/

}

})
//TearDown
Copy link
Member

Choose a reason for hiding this comment

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

delete

@dhilipkumars
Copy link
Author

@tallclair Thanks for the review, could you PTAL now?

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 2, 2017
@tallclair
Copy link
Member

Thanks for the clean up.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 2, 2017
@tallclair
Copy link
Member

/lgtm cancel

Please squash your commits.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 2, 2017
@dhilipkumars
Copy link
Author

@tallclair Done.

@dhilipkumars
Copy link
Author

/test pull-kubernetes-e2e-kops-aws

@dhilipkumars
Copy link
Author

/retest

@tallclair
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 3, 2017
@tallclair tallclair added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Aug 3, 2017
@tallclair
Copy link
Member

I've updated this with a release note, because it is user facing behavior.

/approve no-issue

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dhilipkumars, resouer, tallclair

Associated issue requirement bypassed by: tallclair

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 3, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 50103, 49677, 49449, 43586, 48969)

@k8s-github-robot k8s-github-robot merged commit 6843ca5 into kubernetes:master Aug 3, 2017
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. area/app-lifecycle cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants