-
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
warn user about resource being deleted #95544
Conversation
Hi @SaiHarshaK. 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 Once the patch is verified, the new status will be reflected by the 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. |
/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.
Note that this is not going to work for server-side apply, but I don't think we can do it client-side since we don't see the object before. Alternately, especially since it's merely a warning, we could check that on the final/merged/returned object.
@@ -538,8 +540,13 @@ See http://k8s.io/docs/reference/using-api/api-concepts/#conflicts`, err) | |||
return err | |||
} | |||
|
|||
metadata, _ = meta.Accessor(info.Object) |
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'm assuming you moved the "Accessor" above (L411) so that you would be able to access it here? so I don't think that is needed, is it?
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.
Actually both were required because it didnt receive the delete timestamp yet on 411. But change is still unncessary so reverting change to that Line
@@ -74,6 +74,8 @@ var ( | |||
|
|||
# Diff file read from stdin | |||
cat service.yaml | kubectl diff -f -`)) | |||
|
|||
warningChangesOnDeletingResource = "Warning: Detected changes to resource %[1]s which is currently being deleted.\n" |
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.
It makes me a little sad that we're duplicating this string, is there a good place to share it?
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.
is apply fine? I could just export this by capitalizing
Diff anyway imports apply too
@@ -548,6 +550,13 @@ func (o *DiffOptions) Run() error { | |||
break | |||
} | |||
} | |||
|
|||
metadata, _ := meta.Accessor(info.Object) | |||
if metadata != nil && metadata.GetDeletionTimestamp() != 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.
I'd rather check for the error than for empty metadata.
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.
When you diff a resource which hasnt yet applied i think then this throws error.
/retest |
1 similar comment
/retest |
What do you think about doing it on the post-merged resource? |
as in warning when there are multiple apply running parallely? |
No, my problem is that your current solution doesn't work for server-side apply because we don't get the resource before sending the patch. Also, you have a race-condition if the deletionTimestamp is added between the get and the actual patch is applied. Alternately, you could look at the resource that gets back from the patch, and see if it contains the deletion timestamp. |
For the 1st part does this get the object from server? |
SSA happens right before and isn't included: https://github.com/kubernetes/kubernetes/blob/52630540538c7c0949f50abe4fe960c7b17398c0/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go#L434-L491 |
Oh right, should i insert the warning block here too or some function is preferred? |
yeah, that sounds good. And for client-side apply, I would apply it 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.
That looks good, I think it's fine now. I'd maybe make a function for the error:
func WarnIfDeleting(obj runtime.Object, stderr io.Write) {
...
}
Then you wouldn't have to export the warning string, and you could re-use the same logic throughout.
@@ -133,6 +133,8 @@ var ( | |||
kubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap`)) | |||
|
|||
warningNoLastAppliedConfigAnnotation = "Warning: resource %[1]s is missing the %[2]s annotation which is required by %[3]s apply. %[3]s apply should only be used on resources created declaratively by either %[3]s create --save-config or %[3]s apply. The missing annotation will be patched automatically.\n" | |||
// WarningChangesOnDeletingResource is for warning about the resource currently being deleted on which a kubectl operation is run. |
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.
That comment is not useful. If it was, then it would probably mean that the message needs to be improved ;-)
/assign @seans3 |
Looks great to me, thanks! I'll let @seans3 lgtm. |
/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.
/lgtm
/priority backlog |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: apelisse, SaiHarshaK, soltysh 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Detect "kubectl apply" to resources currently being deleted and warn user.
Which issue(s) this PR fixes:
Ref #93363
Special notes for your reviewer:
/cc @apelisse
Not sure if i should use Fixes keyword so used Ref instead.
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: