-
Notifications
You must be signed in to change notification settings - Fork 40.5k
fix bug on kubectl deleting uninitialized resources #51186
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
fix bug on kubectl deleting uninitialized resources #51186
Conversation
Hi @dixudx. 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. |
pkg/kubectl/delete.go
Outdated
@@ -226,6 +226,17 @@ func (reaper *ReplicaSetReaper) Stop(namespace, name string, timeout time.Durati | |||
timeout = Timeout + time.Duration(10*rs.Spec.Replicas)*time.Second | |||
} | |||
|
|||
_, err = reaper.updateReplicaSetWithRetries(namespace, name, func(rs *extensions.ReplicaSet) { | |||
// set replicaset's initializers to 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.
chasing disabling initializers on everything seems very error-prone. @smarterclayton, what would you expect to happen 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.
I definitely think that this is a bug in the reaper. Why do we still have the reaper?
A normal user isn't going to be able to perform this operation, so this isn't the correct fix. I think if the object hasn't been initialized yet the reaper should just call delete.
/ok-to-test |
@dixudx could you explain what's the reason of the deletion failure? Is it because kubectl is waiting for the controller's status (like observedGeneration, replicas etc) to update? If that's the case, you can early return in the Scale() call. That way you don't need an extra GET/UPDATE. The entire problem will be gone when we move |
@caesarxuchao Yes, current
Yes, this is a nicer way to solve this problem. That means we have to make special pass for
@liggitt @caesarxuchao WDYT? |
@dixudx that looks right to me. @smarterclayton the removal of the reapers is tracked at: #50340 |
95bddf0
to
493f063
Compare
ping @caesarxuchao @smarterclayton @liggitt Updated. PTAL. Thanks. |
/retest |
Much simpler |
/retest |
pkg/kubectl/delete.go
Outdated
@@ -400,6 +400,9 @@ func (reaper *DeploymentReaper) Stop(namespace, name string, timeout time.Durati | |||
d.Spec.RevisionHistoryLimit = &rhl | |||
d.Spec.Replicas = 0 | |||
d.Spec.Paused = true | |||
if d.Initializers != nil { | |||
d.Initializers = 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.
We can't assume kubectl user has the permission to set initializers. Just get the deployment at the beginnig at Stop and delete it immediately if initializers!=nil.
Could you add some tests? Maybe one test case for |
493f063
to
7448365
Compare
7448365
to
41c8799
Compare
@caesarxuchao Add the tests. PTAL. |
hack/make-rules/test-cmd-util.sh
Outdated
# Pre-condition: no deployment exists | ||
kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" '' | ||
# Create a deployment | ||
kubectl create -f hack/testdata/deployment-with-initializer.yaml "${kube_flags[@]}" |
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.
#51436 disabled the initializer field if the feature gate is off, perhaps you need to enable the feature gate in this test.
d5471b5
to
5e120cf
Compare
/lgtm |
/assign @liggitt @fabianofranz for approval Thanks. |
@caesarxuchao: GitHub didn't allow me to assign the following users: for, approval. Note that only kubernetes members can be assigned. In response to this:
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. |
This is a bug fix, so it's ok we don't get approval before the code freeze deadline. |
ping @liggitt @fabianofranz for approval. Thanks. |
/approve |
@fabianofranz @pwittrock for approval and approved-for-milestone tagging if this is required for 1.8 |
/test pull-kubernetes-e2e-kops-aws |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: caesarxuchao, dixudx, fabianofranz, liggitt Associated issue: 51185 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 |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 51186, 50350, 51751, 51645, 51837) |
@dixudx: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. |
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 #51185Special notes for your reviewer:
/assign @caesarxuchao @ahmetb
Release note: