fix: (helm) - do not add owner references to resources that contain the Helm keep resource-policy annotation#4389
Merged
joelanford merged 3 commits intooperator-framework:masterfrom Jan 13, 2021
mikeshng:fix-helm-keep
Merged
fix: (helm) - do not add owner references to resources that contain the Helm keep resource-policy annotation#4389joelanford merged 3 commits intooperator-framework:masterfrom mikeshng:fix-helm-keep
joelanford merged 3 commits intooperator-framework:masterfrom
mikeshng:fix-helm-keep
Conversation
…he Helm keep resource-policy annotation Signed-off-by: Mike Ng <ming@redhat.com>
Contributor
Author
|
I followed the |
estroz
reviewed
Jan 11, 2021
Comment on lines
+151
to
+160
| containsKeepAnno := false | ||
| if u.GetAnnotations() != nil { | ||
| resourcePolicyType, ok := u.GetAnnotations()[kube.ResourcePolicyAnno] | ||
| if ok { | ||
| resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | ||
| containsKeepAnno = resourcePolicyType == kube.KeepPolicy | ||
| } | ||
| } | ||
|
|
||
| if useOwnerRef && !containsKeepAnno { |
Member
There was a problem hiding this comment.
Can you refactor this into a helper
Suggested change
| containsKeepAnno := false | |
| if u.GetAnnotations() != nil { | |
| resourcePolicyType, ok := u.GetAnnotations()[kube.ResourcePolicyAnno] | |
| if ok { | |
| resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | |
| containsKeepAnno = resourcePolicyType == kube.KeepPolicy | |
| } | |
| } | |
| if useOwnerRef && !containsKeepAnno { | |
| if useOwnerRef && !containsResourcePolicyKeep(u.GetAnnotations()) { |
Contributor
Author
There was a problem hiding this comment.
Done as suggested and added unit tests.
10 tasks
Signed-off-by: Mike Ng <ming@redhat.com>
joelanford
reviewed
Jan 12, 2021
Comment on lines
+168
to
+176
| if annotations != nil { | ||
| resourcePolicyType, ok := annotations[kube.ResourcePolicyAnno] | ||
| if ok { | ||
| resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | ||
| return resourcePolicyType == kube.KeepPolicy | ||
| } | ||
| } | ||
|
|
||
| return false |
Member
There was a problem hiding this comment.
Minor nit, but in order to minimize indentation, could you refactor to this?
Suggested change
| if annotations != nil { | |
| resourcePolicyType, ok := annotations[kube.ResourcePolicyAnno] | |
| if ok { | |
| resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | |
| return resourcePolicyType == kube.KeepPolicy | |
| } | |
| } | |
| return false | |
| if annotations == nil { | |
| return false | |
| } | |
| resourcePolicyType, ok := annotations[kube.ResourcePolicyAnno] | |
| if !ok { | |
| return false | |
| } | |
| resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | |
| return resourcePolicyType == kube.KeepPolicy |
Contributor
Author
There was a problem hiding this comment.
Done as suggested. Locally tested again and it seems fine.
Signed-off-by: Mike Ng <ming@redhat.com>
Member
|
/lgtm |
reinvantveer
pushed a commit
to reinvantveer/operator-sdk
that referenced
this pull request
Feb 4, 2021
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: Rein van 't Veer <reinvantveer@gmail.com>
reinvantveer
pushed a commit
to reinvantveer/operator-sdk
that referenced
this pull request
Feb 5, 2021
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: Rein van 't Veer <reinvantveer@gmail.com>
reinvantveer
pushed a commit
to reinvantveer/operator-sdk
that referenced
this pull request
Feb 5, 2021
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: reinvantveer <rein.van.t.veer@geodan.nl>
reinvantveer
pushed a commit
to reinvantveer/operator-sdk
that referenced
this pull request
Feb 5, 2021
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: Rein van 't Veer <reinvantveer@gmail.com> Signed-off-by: reinvantveer <rein.van.t.veer@geodan.nl>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Mike Ng ming@redhat.com
Description of the change:
Helm operator: updated the ownerRefInjectingClient to not inject the owner references if it contains the annotation:
see https://helm.sh/docs/howto/charts_tips_and_tricks/ for more details about the
keepannotation.Motivation for the change:
For the Helm operator delete CR, namespace scope resources with the Helm keep annotation are being GC'ed by Kubernetes.
This change is to make sure those resources are not owned by the CR so they won't get GC'ed.
Closes: #4378
After this change, I can no longer reproduces the issue described in #4378
Checklist
If the pull request includes user-facing changes, extra documentation is required:
changelog/fragments(seechangelog/fragments/00-template.yaml)website/content/en/docs