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 <arthur.outhenin-chalandre@ledger.fr>
This commit is contained in:
Arthur Outhenin-Chalandre
2023-08-14 19:42:45 +02:00
parent d5dd5f4567
commit 790ca0e7b6
5 changed files with 40 additions and 6 deletions

View File

@@ -53,6 +53,15 @@ func (p *HelmChartInflationGeneratorPlugin) Config(
if h.GeneralConfig().HelmConfig.Command == "" { if h.GeneralConfig().HelmConfig.Command == "" {
return fmt.Errorf("must specify --helm-command") return fmt.Errorf("must specify --helm-command")
} }
// CLI args takes precedence
if h.GeneralConfig().HelmConfig.KubeVersion != "" {
p.HelmChart.KubeVersion = h.GeneralConfig().HelmConfig.KubeVersion
}
if len(h.GeneralConfig().HelmConfig.ApiVersions) != 0 {
p.HelmChart.ApiVersions = h.GeneralConfig().HelmConfig.ApiVersions
}
p.h = h p.h = h
if err = yaml.Unmarshal(config, p); err != nil { if err = yaml.Unmarshal(config, p); err != nil {
return return

View File

@@ -4,8 +4,10 @@
package types package types
type HelmConfig struct { type HelmConfig struct {
Enabled bool Enabled bool
Command string Command string
ApiVersions []string
KubeVersion string
} }
// PluginConfig holds plugin configuration. // PluginConfig holds plugin configuration.

View File

@@ -27,10 +27,12 @@ var theFlags struct {
managedByLabel bool managedByLabel bool
helm bool helm bool
} }
helmCommand string helmCommand string
loadRestrictor string helmApiVersions []string
reorderOutput string helmKubeVersion string
fnOptions types.FnPluginLoadingOptions loadRestrictor string
reorderOutput string
fnOptions types.FnPluginLoadingOptions
} }
type Help struct { type Help struct {
@@ -153,6 +155,8 @@ func HonorKustomizeFlags(kOpts *krusty.Options, flags *flag.FlagSet) *krusty.Opt
kOpts.PluginConfig.HelmConfig.Enabled = theFlags.enable.helm kOpts.PluginConfig.HelmConfig.Enabled = theFlags.enable.helm
} }
kOpts.PluginConfig.HelmConfig.Command = theFlags.helmCommand kOpts.PluginConfig.HelmConfig.Command = theFlags.helmCommand
kOpts.PluginConfig.HelmConfig.ApiVersions = theFlags.helmApiVersions
kOpts.PluginConfig.HelmConfig.KubeVersion = theFlags.helmKubeVersion
kOpts.AddManagedbyLabel = isManagedByLabelEnabled() kOpts.AddManagedbyLabel = isManagedByLabelEnabled()
return kOpts return kOpts
} }

View File

@@ -21,4 +21,14 @@ func AddFlagEnableHelm(set *pflag.FlagSet) {
"helm-command", "helm-command",
"helm", // default "helm", // default
"helm command (path to executable)") "helm command (path to executable)")
set.StringArrayVar(
&theFlags.helmApiVersions,
"helm-api-versions",
[]string{}, // default
"Kubernetes api versions used by Helm for Capabilities.APIVersions")
set.StringVar(
&theFlags.helmKubeVersion,
"helm-kube-version",
"", // default
"Kubernetes version used by Helm for Capabilities.KubeVersion")
} }

View File

@@ -59,6 +59,15 @@ func (p *plugin) Config(
if h.GeneralConfig().HelmConfig.Command == "" { if h.GeneralConfig().HelmConfig.Command == "" {
return fmt.Errorf("must specify --helm-command") return fmt.Errorf("must specify --helm-command")
} }
// CLI args takes precedence
if h.GeneralConfig().HelmConfig.KubeVersion != "" {
p.HelmChart.KubeVersion = h.GeneralConfig().HelmConfig.KubeVersion
}
if len(h.GeneralConfig().HelmConfig.ApiVersions) != 0 {
p.HelmChart.ApiVersions = h.GeneralConfig().HelmConfig.ApiVersions
}
p.h = h p.h = h
if err = yaml.Unmarshal(config, p); err != nil { if err = yaml.Unmarshal(config, p); err != nil {
return return