-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Conversation
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 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. |
cc: @dchen1107 and @derekwaynecarr |
/sig node |
@@ -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" |
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.
Need running gofmt
.
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.
they are go fmt'ed but gofmt wouldnt re-arrange imports, now fixed.
/sig node-reviewers |
@@ -20,6 +20,7 @@ import ( | |||
"path/filepath" | |||
"testing" | |||
"time" | |||
"strings" |
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 still right. Should use gofmt
to update.
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.
okay got the problem, I was doing go fmt
instead of gofmt
, now fixed. PTAL
/kind bug |
/ok-to-test |
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.
Please fix CI first, then I will review
/test pull-kubernetes-verify |
/test pull-kubernetes-e2e-gce-etcd3 |
/test pull-kubernetes-e2e-gce-etcd3 |
1 similar comment
/test pull-kubernetes-e2e-gce-etcd3 |
@resouer looks like a flake the failures are unrelated. /test pull-kubernetes-e2e-gce-etcd3 |
Flake #49761 |
/retest |
/test pull-kubernetes-e2e-gce-etcd3 |
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.
lgtm, let's run test again
Kindly ping @tallclair @Random-Liu , the code lgtm, please take a final look, thanks! |
/test pull-kubernetes-e2e-kops-aw |
1 similar comment
/test pull-kubernetes-e2e-kops-aw |
/retest |
The pull-kubernetes-e2e-kops-aws is flake, I noticed it fails in many PRs. |
Flake: #48223 |
/retest |
1 similar comment
/retest |
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 needs a little cleanup, logic looks good.
@@ -75,7 +75,6 @@ func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS | |||
if err != nil { | |||
return nil, 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.
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) |
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.
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") |
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.
s/is no/was not/
|
||
m.runner = lcHanlder | ||
|
||
//TestCase 1: Configured and works as expected |
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.
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 }() |
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.
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) |
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.
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 |
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.
nit: add a space after //
, here and everywhere.
}, | ||
} | ||
|
||
//Now try to create a container, which should inturn invoke PostStart Hook |
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.
nit: s/inturn/in turn/
} | ||
|
||
}) | ||
//TearDown |
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.
delete
@tallclair Thanks for the review, could you PTAL now? |
Thanks for the clean up. /lgtm |
/lgtm cancel Please squash your commits. |
d773155
to
25bc76d
Compare
Add UT for lifeCycle hooks
@tallclair Done. |
/test pull-kubernetes-e2e-kops-aws |
/retest |
/lgtm |
I've updated this with a release note, because it is user facing behavior. /approve no-issue |
[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 |
Automatic merge from submit-queue (batch tested with PRs 50103, 49677, 49449, 43586, 48969) |
What this PR does / why we need it:
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: