diff --git a/api/internal/localizer/localizer.go b/api/internal/localizer/localizer.go index 61c2fb109..d117396fd 100644 --- a/api/internal/localizer/localizer.go +++ b/api/internal/localizer/localizer.go @@ -130,6 +130,12 @@ func (lc *localizer) localizeNativeFields(kust *types.Kustomization) error { paths []string locFn func(string) (string, error) }{ + "bases": { + // Allow use of deprecated field + //nolint:staticcheck + kust.Bases, + lc.localizeDir, + }, "components": { kust.Components, lc.localizeDir, @@ -144,11 +150,11 @@ func (lc *localizer) localizeNativeFields(kust *types.Kustomization) error { }, } { for i, path := range field.paths { - newPath, err := field.locFn(path) + locPath, err := field.locFn(path) if err != nil { return errors.WrapPrefixf(err, "unable to localize %s path", fieldName) } - field.paths[i] = newPath + field.paths[i] = locPath } } @@ -165,7 +171,6 @@ func (lc *localizer) localizeNativeFields(kust *types.Kustomization) error { if err := lc.localizePatches(kust.Patches); err != nil { return errors.WrapPrefixf(err, "unable to localize patches") } - // Allow use of deprecated field //nolint:staticcheck if err := lc.localizePatches(kust.PatchesJson6902); err != nil { return errors.WrapPrefixf(err, "unable to localize patchesJson6902") @@ -194,19 +199,25 @@ func (lc *localizer) localizeNativeFields(kust *types.Kustomization) error { } } - // TODO(annasong): localize all other kustomization fields: resources, bases, configMapGenerator.env, secretGenerator.env + // TODO(annasong): localize all other kustomization fields: resources return nil } // localizeGenerator localizes the file paths on generator. -func (lc *localizer) localizeGenerator(generator *types.GeneratorArgs) error { +func (lc *localizer) localizeGenerator(generator *types.GeneratorArgs) (err error) { + var locEnvSrc string + if generator.EnvSource != "" { + locEnvSrc, err = lc.localizeFile(generator.EnvSource) + if err != nil { + return errors.WrapPrefixf(err, "unable to localize generator env file") + } + } locEnvs := make([]string, len(generator.EnvSources)) for i, env := range generator.EnvSources { - newPath, err := lc.localizeFile(env) + locEnvs[i], err = lc.localizeFile(env) if err != nil { return errors.WrapPrefixf(err, "unable to localize generator envs file") } - locEnvs[i] = newPath } locFiles := make([]string, len(generator.FileSources)) for i, file := range generator.FileSources { @@ -223,6 +234,7 @@ func (lc *localizer) localizeGenerator(generator *types.GeneratorArgs) error { } locFiles[i] = newFile } + generator.EnvSource = locEnvSrc generator.EnvSources = locEnvs generator.FileSources = locFiles return nil diff --git a/api/internal/localizer/localizer_test.go b/api/internal/localizer/localizer_test.go index 681778187..bbfc5b08c 100644 --- a/api/internal/localizer/localizer_test.go +++ b/api/internal/localizer/localizer_test.go @@ -186,13 +186,15 @@ func TestLoadGVKNN(t *testing.T) { } func TestLoadLegacyFields(t *testing.T) { - // TODO(annasong): add referenced files when implement legacy field localization kustomization := map[string]string{ + // TODO(annasong): Adjust test once localize handles helm. "kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1 -bases: -- beta -configMapGenerator: -- env: env.properties +helmChartInflationGenerator: +- chartName: minecraft + chartRepoUrl: https://kubernetes-charts.storage.googleapis.com + chartVersion: v1.2.0 + releaseName: test + values: values.yaml imageTags: - name: postgres newName: my-registry/my-postgres @@ -485,7 +487,8 @@ func TestLocalizeConfigMapGenerator(t *testing.T) { kustAndData := map[string]string{ "kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1 configMapGenerator: -- envs: +- env: single.env + envs: - standard.env namespace: my options: @@ -499,6 +502,9 @@ kind: Kustomization metadata: name: test `, + "single.env": `MAY=contain +MORE=than +ONE=pair`, "standard.env": `SIZE=0.1 IS_GLOBAL=true`, "key.properties": "value", @@ -521,14 +527,16 @@ secretGenerator: - key type: kubernetes.io/tls - literals: - - APPLE=b3Jhbmdl - - PLUM=cGx1b3Q= + - APPLE=orange + - PLUM=pluot name: no-files +- env: more-fruit `, "crt": "tls.crt=LS0tLS1CRUd...0tLQo=", "key": "tls.key=LS0tLS1CRUd...0tLQo=", - "b/value.properties": "dmFsdWU=", - "b/value": "dmFsdWU=", + "more-fruit": "GRAPE=lime", + "b/value.properties": "value", + "b/value": "value", } checkLocalizeInTargetSuccess(t, kustAndData) } @@ -972,6 +980,20 @@ kind: Kustomization checkFSys(t, expected, actual) } +func TestLocalizeBases(t *testing.T) { + kustAndBases := map[string]string{ + "kustomization.yaml": `bases: +- b +- c/d +`, + "b/kustomization.yaml": `kind: Kustomization +`, + "c/d/kustomization.yaml": `kind: Kustomization +`, + } + checkLocalizeInTargetSuccess(t, kustAndBases) +} + func TestLocalizeComponents(t *testing.T) { kustAndComponents := map[string]string{ "kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1