diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index 098a624a8..36501a976 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -75,6 +75,14 @@ func (kt *KustTarget) Load() error { return nil } +// Kustomization returns a copy of the immutable, internal kustomization object. +func (kt *KustTarget) Kustomization() types.Kustomization { + var result types.Kustomization + b, _ := json.Marshal(*kt.kustomization) + json.Unmarshal(b, &result) + return result +} + func loadKustFile(ldr ifc.Loader) ([]byte, error) { var content []byte match := 0 diff --git a/api/internal/target/kusttarget_test.go b/api/internal/target/kusttarget_test.go index fc903f484..c739d7010 100644 --- a/api/internal/target/kusttarget_test.go +++ b/api/internal/target/kusttarget_test.go @@ -37,6 +37,16 @@ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +`, + }, + "commented": { + content: ` +# Licensed to the Blah Blah Software Foundation +# ... +# yada yada yada. + +commonLabels: + app: nginx `, }, "implicitHeader": { @@ -60,9 +70,6 @@ commonLabels: resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())) for tn, tc := range testCases { - if tn != "nonsenseLatin" { - continue - } t.Run(tn, func(t *testing.T) { if tc.content != "" { th.WriteK("/", tc.content) @@ -73,6 +80,13 @@ commonLabels: require.Contains(t, err.Error(), tc.errContains) } else { require.Nilf(t, err, "got error: %v", err) + k := kt.Kustomization() + require.Condition(t, func() bool { + return len(k.CommonLabels) == 1 + }, "expecting a labels entry") + require.Condition(t, func() bool { + return k.CommonLabels["app"] == "nginx" + }, "expecting app:nginx") } }) }