List of strategic merge patches (#637)

* support List of strategic merge patches

* add test for List of patches

* handle List in SliceFromBytes

* add test for List of patches with anchor/reference

* reorganize kunstruct validate
This commit is contained in:
hyww
2018-12-21 02:08:18 +08:00
committed by Jingfang Liu
parent 900152f724
commit 4b25963c93
4 changed files with 144 additions and 5 deletions

View File

@@ -101,12 +101,16 @@ func (kf *KunstructuredFactoryImpl) Set(fs fs.FileSystem, ldr ifc.Loader) {
}
// validate validates that u has kind and name
// except for kind `List`, which doesn't require a name
func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error {
kind := u.GetKind()
if kind == "" {
return fmt.Errorf("missing kind in object %v", u)
} else if kind == "List" {
return nil
}
if u.GetName() == "" {
return fmt.Errorf("missing metadata.name in object %v", u)
}
if u.GetKind() == "" {
return fmt.Errorf("missing kind in object %v", u)
}
return nil
}

View File

@@ -33,6 +33,15 @@ func TestSliceFromBytes(t *testing.T) {
"name": "winnie",
},
})
testList := factory.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "List",
"items": []interface{}{
testConfigMap.Map(),
testConfigMap.Map(),
},
})
tests := []struct {
name string
@@ -112,6 +121,24 @@ metadata:
expectedOut: nil,
expectedErr: true,
},
{
name: "List",
input: []byte(`
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
- apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
`),
expectedOut: []ifc.Kunstructured{testList},
expectedErr: false,
},
}
for _, test := range tests {