Skip to content

Commit de01137

Browse files
authored
Merge pull request #5991 from isarns/fix/labels-without-selector-duplicate-key-error
Fix duplicate key error when adding multiple labels with --without-selector
2 parents 278dd6e + 4d37afe commit de01137

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

kustomize/commands/edit/add/addmetadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (o *addMetadataOptions) writeToLabels(m *types.Kustomization, kind kindOfAd
183183
}
184184
continue
185185
}
186-
if err := o.writeToMap(lbl.Pairs, kind); err != nil {
186+
if err := o.writeToMapEntry(lbl.Pairs, k, v, kind); err != nil {
187187
return err
188188
}
189189
m.Labels = append(m.Labels, lbl)

kustomize/commands/edit/add/addmetadata_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,19 @@ func TestAddLabelWithoutSelector(t *testing.T) {
375375
},
376376
},
377377
},
378+
{
379+
name: "add multiple labels without selector",
380+
baseLabels: []types.Label{},
381+
options: addMetadataOptions{
382+
labelsWithoutSelector: true,
383+
metadata: map[string]string{"test1": "a", "test2": "b"},
384+
},
385+
expected: []types.Label{
386+
{
387+
Pairs: map[string]string{"test1": "a", "test2": "b"},
388+
},
389+
},
390+
},
378391
{
379392
name: "overwrite label with same settings",
380393
baseLabels: []types.Label{

0 commit comments

Comments
 (0)