feat: add support to set labels without selector
Tries to solve issue: https://github.com/kubernetes-sigs/kustomize/issues/3866
Based on existing feature merged in https://github.com/kubernetes-sigs/kustomize/pull/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 https://github.com/kubernetes-sigs/kustomize/pull/4478, added modifications to command flags and test
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: Mrflatt / name: Lauri Huotari (d71902f304d752e466b843c73ec7b09826e4b926)
Welcome @Mrflatt!
It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.
You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.
You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.
You may want to refer to our testing guide if you run into trouble with your tests not passing.
If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to Kubernetes. :smiley:
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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
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.
This PR has multiple commits, and the default merge method is: merge. You can request commits to be squashed using the label: tide/merge-method-squash
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.
/label tide/merge-method-squash
/test all
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-selectoris 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: value1After that, run
kustomize edit set label test:value2 --without-selector. This will remove the previously added label and replace it with an entry to thelabelskey, as expected:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization labels: - pairs: test: value2However, 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: value3Would 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
@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 --without-selector specified, the labels field should be retained; otherwise, the commonLabels field should be retained.
The main goal for my request was ensuring kustomize edit fix will still work after using this command. It will fail if there are duplicates between these two fields (which makes sense).
@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
--without-selectorspecified, thelabelsfield should be retained; otherwise, thecommonLabelsfield should be retained.The main goal for my request was ensuring
kustomize edit fixwill still work after using this command. It will fail if there are duplicates between these two fields (which makes sense).
Yeap, it should be fixed. Also simplified duplicate label removing.
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle stale - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle rotten - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
/remove-lifecycle rotten
/retest all
@stormqueen1990: The /retest command does not accept any targets.
The following commands are available to trigger required jobs:
/test kustomize-presubmit-master
Use /test all to run all jobs.
In response to this:
/retest all
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.
/test all
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle stale - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle rotten - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
/remove-lifecycle rotten
@stormqueen1990: The /retest command does not accept any targets.
The following commands are available to trigger required jobs:
/test kustomize-presubmit-master
Use /test all to run all jobs.
In response to this:
/lgtm /retest all
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 Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
/ok-to-test
Hi @Mrflatt Could you fix failed lint and tests?
Hi @Mrflatt Could you fix failed lint and tests?
Should I remove deleting from deprecated CommonLabels or suppress linting failure?
New changes are detected. LGTM label has been removed.
Hi @Mrflatt Could you fix failed lint and tests?
Should I remove deleting from deprecated
CommonLabelsor suppress linting failure?
If I understand correctly, if we remove the deleting from commonLabels then that would cause duplicates as pointed out by @stormqueen1990, right? If thats the case I would suggest suppressing the linter for now.
I agree. It's better to suppress the linter failures.
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle stale - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
Thank you for providing this option to finally close #3866 @Mrflatt!
Would you be so kind to have a look at the last linting error? It would be really great to see this merged.
Thank you for your effort!
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle rotten - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten