diff --git a/api/krusty/configmaps_test.go b/api/krusty/configmaps_test.go index b161d88b35..8c375e2237 100644 --- a/api/krusty/configmaps_test.go +++ b/api/krusty/configmaps_test.go @@ -291,6 +291,8 @@ resources: configMapGenerator: - name: project behavior: merge + options: + disableNameSuffixHash: true literals: - ANOTHER_ENV_VARIABLE="bar" `) diff --git a/api/krusty/generatorplugin_test.go b/api/krusty/generatorplugin_test.go new file mode 100644 index 0000000000..d04c8dd2ba --- /dev/null +++ b/api/krusty/generatorplugin_test.go @@ -0,0 +1,135 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package krusty_test + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" + "sigs.k8s.io/kustomize/kyaml/filesys" +) + +func TestGeneratorHashSuffixWithMergeBehavior(t *testing.T) { + fSys := filesys.MakeFsOnDisk() + generatorFilename := "generateWithHashRequest.sh" + + th := kusttest_test.MakeHarnessWithFs(t, fSys) + o := th.MakeOptionsPluginsEnabled() + o.PluginConfig.FnpLoadingOptions.EnableExec = true + + tmpDir, err := filesys.NewTmpConfirmedDir() + assert.NoError(t, err) + th.WriteK(tmpDir.String(), ` +resources: +- configmap.yaml +generators: +- |- + kind: Executable + metadata: + name: demo + annotations: + config.kubernetes.io/function: | + exec: + path: ./`+generatorFilename+` +`) + + th.WriteF(filepath.Join(tmpDir.String(), "configmap.yaml"), ` +apiVersion: v1 +kind: ConfigMap +metadata: + name: cmap +data: + a: b +`) + th.WriteF(filepath.Join(tmpDir.String(), generatorFilename), `#!/bin/sh + +cat < 0 { + // not delete BuildAnnotationsGenAddHashSuffix to work with kustomize.config.k8s.io/needs-hash annotation in generator options + if BuildAnnotations[i] == utils.BuildAnnotationsGenAddHashSuffix { + continue + } if v, ok := maps[0][BuildAnnotations[i]]; ok { result[BuildAnnotations[i]] = v continue