Merge pull request #5991 from isarns/fix/labels-without-selector-duplicate-key-error

Fix duplicate key error when adding multiple labels with --without-selector
This commit is contained in:
Kubernetes Prow Robot
2025-10-12 19:36:54 -07:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -183,7 +183,7 @@ func (o *addMetadataOptions) writeToLabels(m *types.Kustomization, kind kindOfAd
}
continue
}
if err := o.writeToMap(lbl.Pairs, kind); err != nil {
if err := o.writeToMapEntry(lbl.Pairs, k, v, kind); err != nil {
return err
}
m.Labels = append(m.Labels, lbl)

View File

@@ -375,6 +375,19 @@ func TestAddLabelWithoutSelector(t *testing.T) {
},
},
},
{
name: "add multiple labels without selector",
baseLabels: []types.Label{},
options: addMetadataOptions{
labelsWithoutSelector: true,
metadata: map[string]string{"test1": "a", "test2": "b"},
},
expected: []types.Label{
{
Pairs: map[string]string{"test1": "a", "test2": "b"},
},
},
},
{
name: "overwrite label with same settings",
baseLabels: []types.Label{