-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: (helm) - do not add owner references to resources that contain the Helm keep resource-policy annotation #4389
Conversation
…he Helm keep resource-policy annotation Signed-off-by: Mike Ng <ming@redhat.com>
I followed the |
internal/helm/client/client.go
Outdated
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 { |
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.
Can you refactor this into a helper
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()) { |
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 as suggested and added unit tests.
Signed-off-by: Mike Ng <ming@redhat.com>
internal/helm/client/client.go
Outdated
if annotations != nil { | ||
resourcePolicyType, ok := annotations[kube.ResourcePolicyAnno] | ||
if ok { | ||
resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | ||
return resourcePolicyType == kube.KeepPolicy | ||
} | ||
} | ||
|
||
return false |
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.
Minor nit, but in order to minimize indentation, could you refactor to this?
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 |
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 as suggested. Locally tested again and it seems fine.
Signed-off-by: Mike Ng <ming@redhat.com>
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
/lgtm |
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: Rein van 't Veer <reinvantveer@gmail.com>
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: Rein van 't Veer <reinvantveer@gmail.com>
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: reinvantveer <rein.van.t.veer@geodan.nl>
…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>
…he Helm keep resource-policy annotation (operator-framework#4389) Signed-off-by: rearl <rearl@secureworks.com>
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
keep
annotation.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