kustomize icon indicating copy to clipboard operation
kustomize copied to clipboard

feat: add support to set labels without selector

Open Mrflatt opened this issue 1 year ago • 25 comments

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

Mrflatt avatar Aug 03 '24 08:08 Mrflatt

CLA Signed

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:

k8s-ci-robot avatar Aug 03 '24 08:08 k8s-ci-robot

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.

k8s-ci-robot avatar Aug 03 '24 08:08 k8s-ci-robot

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.

k8s-ci-robot avatar Aug 03 '24 09:08 k8s-ci-robot

/label tide/merge-method-squash

stormqueen1990 avatar Aug 28 '24 21:08 stormqueen1990

/test all

stormqueen1990 avatar Sep 03 '24 20:09 stormqueen1990

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 the labels 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 in commonLabels:

    
    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

Mrflatt avatar Sep 04 '24 03:09 Mrflatt

@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 avatar Sep 09 '24 18:09 stormqueen1990

@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).

Yeap, it should be fixed. Also simplified duplicate label removing.

Mrflatt avatar Sep 09 '24 20:09 Mrflatt

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Dec 08 '24 20:12 k8s-triage-robot

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Jan 07 '25 20:01 k8s-triage-robot

/remove-lifecycle rotten

stormqueen1990 avatar Jan 17 '25 15:01 stormqueen1990

/retest all

stormqueen1990 avatar Jan 17 '25 21:01 stormqueen1990

@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.

k8s-ci-robot avatar Jan 17 '25 21:01 k8s-ci-robot

/test all

stormqueen1990 avatar Jan 17 '25 21:01 stormqueen1990

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Apr 19 '25 06:04 k8s-triage-robot

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar May 19 '25 07:05 k8s-triage-robot

/remove-lifecycle rotten

stormqueen1990 avatar May 19 '25 22:05 stormqueen1990

@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.

k8s-ci-robot avatar May 19 '25 22:05 k8s-ci-robot

[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.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar May 19 '25 22:05 k8s-ci-robot

/ok-to-test

koba1t avatar May 19 '25 22:05 koba1t

Hi @Mrflatt Could you fix failed lint and tests?

koba1t avatar May 20 '25 01:05 koba1t

Hi @Mrflatt Could you fix failed lint and tests?

Should I remove deleting from deprecated CommonLabels or suppress linting failure?

Mrflatt avatar May 20 '25 05:05 Mrflatt

New changes are detected. LGTM label has been removed.

k8s-ci-robot avatar May 20 '25 05:05 k8s-ci-robot

Hi @Mrflatt Could you fix failed lint and tests?

Should I remove deleting from deprecated CommonLabels or 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.

sarab97 avatar Jun 24 '25 20:06 sarab97

I agree. It's better to suppress the linter failures.

koba1t avatar Jul 09 '25 17:07 koba1t

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Oct 09 '25 18:10 k8s-triage-robot

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!

crumohr avatar Oct 18 '25 12:10 crumohr

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

k8s-triage-robot avatar Nov 17 '25 12:11 k8s-triage-robot