mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 09:40:49 +00:00
Allow nil label and annotaion
This fix is to allow value of lable or annoation to be nil
This commit is contained in:
@@ -76,7 +76,9 @@ func (o *mapTransformer) Transform(m resmap.ResMap) error {
|
|||||||
|
|
||||||
func (o *mapTransformer) addMap(in interface{}) (interface{}, error) {
|
func (o *mapTransformer) addMap(in interface{}) (interface{}, error) {
|
||||||
m, ok := in.(map[string]interface{})
|
m, ok := in.(map[string]interface{})
|
||||||
if !ok {
|
if in == nil {
|
||||||
|
m = map[string]interface{}{}
|
||||||
|
} else if !ok {
|
||||||
return nil, fmt.Errorf("%#v is expected to be %T", in, m)
|
return nil, fmt.Errorf("%#v is expected to be %T", in, m)
|
||||||
}
|
}
|
||||||
for k, v := range o.m {
|
for k, v := range o.m {
|
||||||
|
|||||||
@@ -583,3 +583,48 @@ func TestAnnotationsRun(t *testing.T) {
|
|||||||
t.Fatalf("actual doesn't match expected: %v", err)
|
t.Fatalf("actual doesn't match expected: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAnnotaionsRunWithNullValue(t *testing.T) {
|
||||||
|
m := resmap.ResMap{
|
||||||
|
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "cm1",
|
||||||
|
"annotations": nil,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := resmap.ResMap{
|
||||||
|
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "cm1",
|
||||||
|
"annotations": map[string]interface{}{
|
||||||
|
"anno-key1": "anno-value1",
|
||||||
|
"anno-key2": "anno-value2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
at, err := NewAnnotationsMapTransformer(
|
||||||
|
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"},
|
||||||
|
defaultTransformerConfig.CommonAnnotations)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
err = at.Transform(m)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(m, expected) {
|
||||||
|
err = expected.ErrorIfNotEqual(m)
|
||||||
|
t.Fatalf("actual doesn't match expected: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user