-
Notifications
You must be signed in to change notification settings - Fork 223
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
add support for declarative deletion #13
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Liujingfang1 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 |
// - prune skips this resource | ||
// - delete skips this resource | ||
|
||
PreventDeletion = "PreventDeletion" |
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 has the following
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.
done
internal/pkg/constants/constants.go
Outdated
// kubectl.kubernetes.io/presence: EnsureDoesNotExist | ||
// Will be deleted or skipped in apply. | ||
// | ||
// It has following effect in each command |
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 has the
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.
done
|
||
// HasAnnotation checks if an unstructured has a given annotation key | ||
func HasAnnotation(u *unstructured.Unstructured, key string) bool { | ||
annotation := u.GetAnnotations() |
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.
check if the map is 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.
done
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 I was wrong, looks like this always returns an empty map?
// MatchAnnotations checks if an unstructured matches a key, value pair in its annotation | ||
func MatchAnnotations(u *unstructured.Unstructured, annotations map[string]string) bool { | ||
s := labels.SelectorFromSet(labels.Set(annotations)) | ||
if s.Matches(labels.Set(u.GetAnnotations())) { |
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.
check if annotations is 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.
done
/lgtm |
add support for declarative deletion
Add two annotations
In apply command, any resource annotated by
EnsureDoesNotExist
won't be applied.In prune or delete command, any resource annotated by
PreventDeletion
won't be deleted.