Merge pull request #4929 from koba1t/refactor/cleanup_Unmarshal_kustomization

Error on duplicate fields in Kustomization
This commit is contained in:
Kubernetes Prow Robot
2023-01-06 10:37:59 -08:00
committed by GitHub
22 changed files with 39 additions and 117 deletions

View File

@@ -104,7 +104,7 @@ func (lc *localizer) load() (*types.Kustomization, string, error) {
var kust types.Kustomization
err = (&kust).Unmarshal(content)
if err != nil {
return nil, "", errors.WrapPrefixf(err, "invalid kustomization")
return nil, "", errors.Wrap(err)
}
// Localize intentionally does not replace legacy fields to return a localized kustomization

View File

@@ -212,7 +212,8 @@ suffix: invalid`,
})
err := Run("/a", "", "", fSysTest)
require.EqualError(t, err, `unable to localize target "/a": invalid kustomization: json: unknown field "suffix"`)
require.EqualError(t, err,
`unable to localize target "/a": invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)
checkFSys(t, fSysExpected, fSysTest)
}

View File

@@ -139,10 +139,7 @@ commonLabels:
func TestMakeCustomizedResMap(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/whatever", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: foo-
th.WriteK("/whatever", `namePrefix: foo-
nameSuffix: -bar
namespace: ns1
commonLabels:
@@ -301,10 +298,7 @@ metadata:
func TestConfigurationsOverrideDefault(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/merge-config", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: foo-
th.WriteK("/merge-config", `namePrefix: foo-
nameSuffix: -bar
namespace: ns1
resources:
@@ -401,10 +395,7 @@ metadata:
func TestDuplicateExternalGeneratorsForbidden(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/generator", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
generators:
th.WriteK("/generator", `generators:
- |-
apiVersion: generators.example/v1
kind: ManifestGenerator
@@ -437,10 +428,7 @@ generators:
func TestDuplicateExternalTransformersForbidden(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/transformer", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
transformers:
th.WriteK("/transformer", `transformers:
- |-
apiVersion: transformers.example.co/v1
kind: ValueAnnotator