Support for ignoring specific Resources via annotation.

Resources annotated with `config.kubernetes.io/local-config` will be ignored by Kustomize
This commit is contained in:
Phillip Wittrock
2019-10-29 16:41:45 -07:00
parent f2368201d9
commit 8bf98dd255
2 changed files with 38 additions and 1 deletions

View File

@@ -52,7 +52,9 @@ func (kf *KunstructuredFactoryImpl) SliceFromBytes(
if err != nil {
return nil, err
}
result = append(result, &UnstructAdapter{Unstructured: out})
if !kf.skipResource(out) {
result = append(result, &UnstructAdapter{Unstructured: out})
}
}
}
if err != io.EOF {
@@ -116,6 +118,22 @@ func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error
return nil
}
// nonKustomizableResourceAnnotation if set on a Resource will cause Kustomize to
// ignore the Resource rather than Kustomize it.
const ignoredByKustomizeResourceAnnotation = "config.kubernetes.io/local-config"
// skipResource returns true if the Resource should not be accumulated
func (kf *KunstructuredFactoryImpl) skipResource(u unstructured.Unstructured) bool {
an := u.GetAnnotations()
if an == nil {
// annotation unset
return false
}
// check if the Resource has opt-ed out of kustomize
_, found := an[ignoredByKustomizeResourceAnnotation]
return found
}
func checkListItemNil(in interface{}) (bool, string) {
switch v := in.(type) {
case map[string]interface{}: