-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix duplicate key error when adding multiple labels with --without-selector #5991
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
Fix duplicate key error when adding multiple labels with --without-selector #5991
Conversation
Hi @isarns. 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. |
Hi @isarns So, Could you add testacases to check this change will be fix that problem? |
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. |
@isarns |
/ok-to-test |
@isarns /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: isarns, koba1t The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description
Fixes a bug in the
kustomize edit add label --without-selector
command where adding multiple labels would fail with a "label already in kustomization file" error, even when the labels didn't actually exist.Fixes: #5978
Problem
When running:
The command would fail with:
Root Cause
The issue was in the
writeToLabels
function inaddmetadata.go
. The function was callingo.writeToMap(lbl.Pairs, kind)
which attempts to add all metadata pairs to thelbl.Pairs
map. However, sincelbl.Pairs
already contained pairs from previous iterations of the loop, it would find duplicates and throw the "already exists" error.Solution
Changed line 186 from:
To:
This ensures only the current key-value pair is added to the map, avoiding the duplicate key issue.
Testing
--without-selector
Type of Change