-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: add support to set labels without selector #5741
base: master
Are you sure you want to change the base?
Conversation
Welcome @Mrflatt! |
Hi @Mrflatt. Thanks for your PR. I'm waiting for a kubernetes-sigs 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-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Mrflatt The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This PR has multiple commits, and the default merge method is: merge. 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-sigs/prow repository. |
9e0ec32
to
4d88162
Compare
func (o *setLabelOptions) removeDuplicateLabels(m *types.Kustomization) { | ||
for k := range o.metadata { | ||
delete(m.CommonLabels, k) | ||
for idx, label := range m.Labels { | ||
if label.IncludeTemplates != o.includeTemplates { | ||
m.Labels = deleteLabel(k, label, m.Labels, idx) | ||
} | ||
if label.IncludeSelectors { | ||
m.Labels = deleteLabel(k, label, m.Labels, idx) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func deleteLabel(key string, label types.Label, labels []types.Label, idx int) []types.Label { | ||
delete(label.Pairs, key) | ||
if len(label.Pairs) == 0 { | ||
labels = append(labels[:idx], labels[idx+1:]...) | ||
} | ||
return labels | ||
} |
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.
Could you please add some comments explaining the mechanism of action of these functions to deduplicate existing labels?
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 there any specific reason to use assert
instead of require
for the Equal
assertions?
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.
No, all of these should be require, will change all of them.
/label tide/merge-method-squash |
4d88162
to
54e367b
Compare
54e367b
to
3290329
Compare
/test all |
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.
Hi there, @Mrflatt! 👋🏻
Thank you for your contribution!
This looks mostly LGTM. I just have one outstanding question: I noticed you wrote code to deduplicate labels when --without-selector
is specified, but this current logic still duplicates labels when you execute the following sequence of commands:
- Run
kustomize edit set label test:value1
:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization commonLabels: test: value1
- After that, run
kustomize edit set label test:value2 --without-selector
. This will remove the previously added label and replace it with an entry to thelabels
key, as expected:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization labels: - pairs: test: value2
- However, if I again run
kustomize edit set label test:value3
, this will cause a duplicate incommonLabels
:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization labels: - pairs: test: value2 commonLabels: test: value3
Would you be interested in addressing this use case as part of this PR as well?
@stormqueen1990 Yeah, will fix that also. Would solution be to remove labels and add commonLabel? Or modify labels and not add deprecated commonLabel, which would a bit change to functionality |
Hi again, @Mrflatt! In my opinion the request of the user should be honoured. So if the command issued had The main goal for my request was ensuring |
Yeap, it should be fixed. Also simplified duplicate label removing. |
Tries to solve issue: #3866
Based on existing feature merged in #4486, uses same command flags with
edit set label
Set label removes existing duplicate labels from commonLabels, and labels where includeTemplates value does not match.
Duplicate of #4478, added modifications to command flags and test