fix: make edit add label generate the labels field instead of deprecated commonLabels#6200
fix: make edit add label generate the labels field instead of deprecated commonLabels#6200jojinkb wants to merge 1 commit into
edit add label generate the labels field instead of deprecated commonLabels#6200Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jojinkb The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @jojinkb! |
|
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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
…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>
8d1bf13 to
cdf7acd
Compare
What this PR does / why we need it:
kustomize edit add label environment:devwrote the deprecatedcommonLabelsfield, sokustomize buildimmediately 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 thelabelsfield withincludeSelectors: true, which is semantically identical tocommonLabels—kustomize buildoutput is byte-identical between the two forms, but no deprecation warning is triggered:Design decisions (flagging explicitly for review):
commonLabels, the command keeps updatingcommonLabelsin place, so a single file never ends up mixing both fields.kustomize edit fixremains 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 labelnow removes keys from bothcommonLabelsand everylabelsentry (dropping entries left without pairs), so labels created by the new default remain removable and the command family stays round-trippable. Previously, labels in thelabelsfield could not be removed via the CLI at all.--without-selector/--include-templatesbehavior is unchanged.edit set labelis 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:
TestAddLabelGeneratesLabelsFieldreproduces the issue's exact scenario end to end; new table-drivenTestAddLabelDefaultsToLabelsFieldcovers the new default, appending to an existingincludeSelectorsentry, not mixing with--without-selectorentries, and thecommonLabelsback-compat path.labelsfield (with empty entries dropped), removal spanning both fields, file-level removal leaving no emptylabels:key, and the updated "neither field defined" error.go test ./commands/...(kustomize module) passes;golangci-lint run(repo-pinned v1.64.8) is clean on the changed packages.buildemits no warning;commonLabelsvs newlabelsform produce identical rendered resources; legacycommonLabelsfiles keep their format onadd./kind cleanup
/kind deprecation
This change was developed with AI assistance (Claude Code); I have reviewed and tested it.