Skip to content

fix: make edit add label generate the labels field instead of deprecated commonLabels#6200

Open
jojinkb wants to merge 1 commit into
kubernetes-sigs:masterfrom
jojinkb:fix-edit-add-label-deprecated
Open

fix: make edit add label generate the labels field instead of deprecated commonLabels#6200
jojinkb wants to merge 1 commit into
kubernetes-sigs:masterfrom
jojinkb:fix-edit-add-label-deprecated

Conversation

@jojinkb

@jojinkb jojinkb commented Jul 25, 2026

Copy link
Copy Markdown

What this PR does / why we need it:

kustomize edit add label environment:dev wrote the deprecated commonLabels field, so kustomize build immediately printed a deprecation warning about configuration the CLI itself had just generated (#5726, triage/accepted).

With this change, edit add label (no flags) appends to the labels field with includeSelectors: true, which is semantically identical to commonLabelskustomize build output is byte-identical between the two forms, but no deprecation warning is triggered:

# kustomization.yaml after `kustomize edit add label environment:dev`
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
labels:
- includeSelectors: true
  pairs:
    environment: dev

Design decisions (flagging explicitly for review):

  • Backward compatibility: if the kustomization file already uses commonLabels, the command keeps updating commonLabels in place, so a single file never ends up mixing both fields. kustomize edit fix remains the migration path. This means existing files/scripts see no change; only freshly-generated configuration switches to the non-deprecated field, per the maintainer guidance on the issue ("update the existing command to do so"). The alternative — a new opt-in flag — would keep emitting deprecated config by default, which is what the issue asks to stop.
  • edit remove label now removes keys from both commonLabels and every labels entry (dropping entries left without pairs), so labels created by the new default remain removable and the command family stays round-trippable. Previously, labels in the labels field could not be removed via the CLI at all.
  • --without-selector / --include-templates behavior is unchanged. edit set label is intentionally untouched, since feat: add support to set labels without selector #6039 covers it (only overlap is an identical one-line help-string change).

Which issue(s) this PR fixes:

Fixes #5726

Testing:

  • New TestAddLabelGeneratesLabelsField reproduces the issue's exact scenario end to end; new table-driven TestAddLabelDefaultsToLabelsField covers the new default, appending to an existing includeSelectors entry, not mixing with --without-selector entries, and the commonLabels back-compat path.
  • New remove-side tests: removal from the labels field (with empty entries dropped), removal spanning both fields, file-level removal leaving no empty labels: key, and the updated "neither field defined" error.
  • All 6 new/updated tests fail without the fix. go test ./commands/... (kustomize module) passes; golangci-lint run (repo-pinned v1.64.8) is clean on the changed packages.
  • Manually verified with a built binary: fresh file gets the issue's expected output; build emits no warning; commonLabels vs new labels form produce identical rendered resources; legacy commonLabels files keep their format on add.

/kind cleanup
/kind deprecation

This change was developed with AI assistance (Claude Code); I have reviewed and tested it.

@kubernetes-prow kubernetes-prow Bot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. labels Jul 25, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jojinkb
Once this PR has been reviewed and has the lgtm label, please assign koba1t for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 25, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @jojinkb!

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

@kubernetes-prow

Copy link
Copy Markdown
Contributor

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

Details

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.

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 25, 2026
…cated commonLabels

`kustomize edit add label` wrote the deprecated commonLabels field,
so kustomize immediately warned about the configuration it had just
generated. The command now appends to the labels field with
includeSelectors: true by default, which is semantically identical to
commonLabels. Kustomization files that already use commonLabels keep
being updated in place so a single file never mixes both fields;
`kustomize edit fix` remains the migration path.

`edit remove label` now removes keys from both commonLabels and the
labels field, dropping labels entries left without any pairs, so
labels created by the new default remain removable.

Signed-off-by: Jojin <jojin.kb@gmail.com>
@jojinkb
jojinkb force-pushed the fix-edit-add-label-deprecated branch from 8d1bf13 to cdf7acd Compare July 25, 2026 09:46
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/deprecation Categorizes issue or PR as related to a feature/enhancement marked for deprecation. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kustomize edit add label generates deprecated config

1 participant