mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
Merge pull request #522 from Liujingfang1/name
make sure the objects loaded have name and kind
This commit is contained in:
@@ -18,6 +18,7 @@ package kunstruct
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@@ -52,6 +53,10 @@ func (kf *KunstructurerFactoryImpl) SliceFromBytes(
|
||||
var out unstructured.Unstructured
|
||||
err = decoder.Decode(&out)
|
||||
if err == nil {
|
||||
err = kf.validate(out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, &UnstructAdapter{Unstructured: out})
|
||||
}
|
||||
}
|
||||
@@ -94,3 +99,14 @@ func (kf *KunstructurerFactoryImpl) Set(fs fs.FileSystem, ldr ifc.Loader) {
|
||||
kf.cmfactory = configmapandsecret.NewConfigMapFactory(fs, ldr)
|
||||
kf.secfactory = configmapandsecret.NewSecretFactory(fs, ldr.Root())
|
||||
}
|
||||
|
||||
// validate validates that u has kind and name
|
||||
func (kf *KunstructurerFactoryImpl) validate(u unstructured.Unstructured) error {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -100,6 +100,18 @@ WOOOOOOOOOOOOOOOOOOOOOOOOT: woot
|
||||
expectedOut: []ifc.Kunstructured{},
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "Missing .metadata.name in object",
|
||||
input: []byte(`
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
annotations:
|
||||
foo: bar
|
||||
`),
|
||||
expectedOut: nil,
|
||||
expectedErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Reference in New Issue
Block a user