Merge pull request #2932 from mstrYoda/master

add DisableNameSuffixHash parameter to edit Secret & ConfigMap
This commit is contained in:
Kubernetes Prow Robot
2020-09-16 10:29:20 -07:00
committed by GitHub
4 changed files with 33 additions and 0 deletions

View File

@@ -81,6 +81,11 @@ func newCmdAddConfigMap(
"from-env-file",
"",
"Specify the path to a file to read lines of key=val pairs to create a configmap (i.e. a Docker .env file).")
cmd.Flags().BoolVar(
&flags.DisableNameSuffixHash,
"disableNameSuffixHash",
false,
"Disable the name suffix for the configmap")
return cmd
}
@@ -126,4 +131,9 @@ func mergeFlagsIntoCmArgs(args *types.ConfigMapArgs, flags flagsAndArgs) {
args.EnvSources = append(
args.EnvSources, flags.EnvFileSource)
}
if flags.DisableNameSuffixHash {
args.Options = &types.GeneratorOptions{
DisableNameSuffixHash: true,
}
}
}

View File

@@ -26,6 +26,8 @@ type flagsAndArgs struct {
Type string
// Namespace of secret
Namespace string
// Disable name suffix
DisableNameSuffixHash bool
}
// Validate validates required fields are set to support structured generation.

View File

@@ -91,6 +91,11 @@ func newCmdAddSecret(
"namespace",
"",
"Specify the namespace of the secret")
cmd.Flags().BoolVar(
&flags.DisableNameSuffixHash,
"disableNameSuffixHash",
false,
"Disable the name suffix for the secret")
return cmd
}
@@ -139,4 +144,9 @@ func mergeFlagsIntoGeneratorArgs(args *types.GeneratorArgs, flags flagsAndArgs)
args.EnvSources = append(
args.EnvSources, flags.EnvFileSource)
}
if flags.DisableNameSuffixHash {
args.Options = &types.GeneratorOptions{
DisableNameSuffixHash: true,
}
}
}

View File

@@ -114,3 +114,14 @@ func TestMergeFlagsIntoSecretArgs_EnvSource(t *testing.T) {
t.Fatalf("expected env2")
}
}
func TestMergeFlagsIntoSecretArgs_DisableNameSuffixHash(t *testing.T) {
k := &types.Kustomization{}
args := findOrMakeSecretArgs(k, "foo", "bar", "forbidden")
mergeFlagsIntoGeneratorArgs(
&args.GeneratorArgs,
flagsAndArgs{DisableNameSuffixHash: true})
if k.SecretGenerator[0].Options.DisableNameSuffixHash != true {
t.Fatalf("expected true")
}
}