add DisableNameSuffixHash for secret and configmap

This commit is contained in:
mstrYoda
2020-08-26 13:22:26 +03:00
parent 0be4a61f64
commit c1cd872df6
4 changed files with 33 additions and 0 deletions

View File

@@ -81,6 +81,11 @@ func newCmdAddConfigMap(
"from-env-file", "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).") "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 return cmd
} }
@@ -126,4 +131,9 @@ func mergeFlagsIntoCmArgs(args *types.ConfigMapArgs, flags flagsAndArgs) {
args.EnvSources = append( args.EnvSources = append(
args.EnvSources, flags.EnvFileSource) args.EnvSources, flags.EnvFileSource)
} }
if flags.DisableNameSuffixHash {
args.Options = &types.GeneratorOptions{
DisableNameSuffixHash: true,
}
}
} }

View File

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

View File

@@ -91,6 +91,11 @@ func newCmdAddSecret(
"namespace", "namespace",
"", "",
"Specify the namespace of the secret") "Specify the namespace of the secret")
cmd.Flags().BoolVar(
&flags.DisableNameSuffixHash,
"disableNameSuffixHash",
false,
"Disable the name suffix for the secret")
return cmd return cmd
} }
@@ -139,4 +144,9 @@ func mergeFlagsIntoGeneratorArgs(args *types.GeneratorArgs, flags flagsAndArgs)
args.EnvSources = append( args.EnvSources = append(
args.EnvSources, flags.EnvFileSource) 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") 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")
}
}