mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
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:
@@ -52,9 +52,11 @@ func (kf *KunstructuredFactoryImpl) SliceFromBytes(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !kf.skipResource(out) {
|
||||||
result = append(result, &UnstructAdapter{Unstructured: out})
|
result = append(result, &UnstructAdapter{Unstructured: out})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -116,6 +118,22 @@ func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error
|
|||||||
return nil
|
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) {
|
func checkListItemNil(in interface{}) (bool, string) {
|
||||||
switch v := in.(type) {
|
switch v := in.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
|
|||||||
@@ -105,6 +105,25 @@ metadata:
|
|||||||
expectedOut: []ifc.Kunstructured{testConfigMap, testConfigMap},
|
expectedOut: []ifc.Kunstructured{testConfigMap, testConfigMap},
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "localConfigYaml",
|
||||||
|
input: []byte(`
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: winnie-skip
|
||||||
|
annotations:
|
||||||
|
# this annotation causes the Resource to be ignored by kustomize
|
||||||
|
config.kubernetes.io/local-config: ""
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: winnie
|
||||||
|
`),
|
||||||
|
expectedOut: []ifc.Kunstructured{testConfigMap},
|
||||||
|
expectedErr: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "garbageInOneOfTwoObjects",
|
name: "garbageInOneOfTwoObjects",
|
||||||
input: []byte(`
|
input: []byte(`
|
||||||
|
|||||||
Reference in New Issue
Block a user