Skip to content

Commit 790ca0e

Browse files
committed
helm: add kube-version and api-versions on CLI args
It makes sense to add that as a CLI args since you could use one single kustomization file/helm chart for multiple clusters. Also it's easier to have those on the CLI if the user has some kind of tooling that will end up calling kustomize and that could pass those (i.e.: ArgoCD is doing that for Helm so it could do that for Kustomize as well that will end up calling Helm as well). Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
1 parent d5dd5f4 commit 790ca0e

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

api/internal/builtins/HelmChartInflationGenerator.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types/pluginconfig.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package types
55

66
type HelmConfig struct {
7-
Enabled bool
8-
Command string
7+
Enabled bool
8+
Command string
9+
ApiVersions []string
10+
KubeVersion string
911
}
1012

1113
// PluginConfig holds plugin configuration.

kustomize/commands/build/build.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ var theFlags struct {
2727
managedByLabel bool
2828
helm bool
2929
}
30-
helmCommand string
31-
loadRestrictor string
32-
reorderOutput string
33-
fnOptions types.FnPluginLoadingOptions
30+
helmCommand string
31+
helmApiVersions []string
32+
helmKubeVersion string
33+
loadRestrictor string
34+
reorderOutput string
35+
fnOptions types.FnPluginLoadingOptions
3436
}
3537

3638
type Help struct {
@@ -153,6 +155,8 @@ func HonorKustomizeFlags(kOpts *krusty.Options, flags *flag.FlagSet) *krusty.Opt
153155
kOpts.PluginConfig.HelmConfig.Enabled = theFlags.enable.helm
154156
}
155157
kOpts.PluginConfig.HelmConfig.Command = theFlags.helmCommand
158+
kOpts.PluginConfig.HelmConfig.ApiVersions = theFlags.helmApiVersions
159+
kOpts.PluginConfig.HelmConfig.KubeVersion = theFlags.helmKubeVersion
156160
kOpts.AddManagedbyLabel = isManagedByLabelEnabled()
157161
return kOpts
158162
}

kustomize/commands/build/flagenablehelm.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ func AddFlagEnableHelm(set *pflag.FlagSet) {
2121
"helm-command",
2222
"helm", // default
2323
"helm command (path to executable)")
24+
set.StringArrayVar(
25+
&theFlags.helmApiVersions,
26+
"helm-api-versions",
27+
[]string{}, // default
28+
"Kubernetes api versions used by Helm for Capabilities.APIVersions")
29+
set.StringVar(
30+
&theFlags.helmKubeVersion,
31+
"helm-kube-version",
32+
"", // default
33+
"Kubernetes version used by Helm for Capabilities.KubeVersion")
2434
}

plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ func (p *plugin) Config(
5959
if h.GeneralConfig().HelmConfig.Command == "" {
6060
return fmt.Errorf("must specify --helm-command")
6161
}
62+
63+
// CLI args takes precedence
64+
if h.GeneralConfig().HelmConfig.KubeVersion != "" {
65+
p.HelmChart.KubeVersion = h.GeneralConfig().HelmConfig.KubeVersion
66+
}
67+
if len(h.GeneralConfig().HelmConfig.ApiVersions) != 0 {
68+
p.HelmChart.ApiVersions = h.GeneralConfig().HelmConfig.ApiVersions
69+
}
70+
6271
p.h = h
6372
if err = yaml.Unmarshal(config, p); err != nil {
6473
return

0 commit comments

Comments
 (0)