diff --git a/kustomize/commands/edit/add/addmetadata.go b/kustomize/commands/edit/add/addmetadata.go index 25b1a5aac..71f1d96e1 100644 --- a/kustomize/commands/edit/add/addmetadata.go +++ b/kustomize/commands/edit/add/addmetadata.go @@ -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) diff --git a/kustomize/commands/edit/add/addmetadata_test.go b/kustomize/commands/edit/add/addmetadata_test.go index 9a52e133e..1671bff75 100644 --- a/kustomize/commands/edit/add/addmetadata_test.go +++ b/kustomize/commands/edit/add/addmetadata_test.go @@ -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{