From 790ca0e7b66aae32c4ab6258709f15be471b15b4 Mon Sep 17 00:00:00 2001 From: Arthur Outhenin-Chalandre Date: Mon, 14 Aug 2023 19:42:45 +0200 Subject: [PATCH] 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 --- api/internal/builtins/HelmChartInflationGenerator.go | 9 +++++++++ api/types/pluginconfig.go | 6 ++++-- kustomize/commands/build/build.go | 12 ++++++++---- kustomize/commands/build/flagenablehelm.go | 10 ++++++++++ .../HelmChartInflationGenerator.go | 9 +++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/api/internal/builtins/HelmChartInflationGenerator.go b/api/internal/builtins/HelmChartInflationGenerator.go index 40437a215..d0380f0c5 100644 --- a/api/internal/builtins/HelmChartInflationGenerator.go +++ b/api/internal/builtins/HelmChartInflationGenerator.go @@ -53,6 +53,15 @@ func (p *HelmChartInflationGeneratorPlugin) Config( if h.GeneralConfig().HelmConfig.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 if err = yaml.Unmarshal(config, p); err != nil { return diff --git a/api/types/pluginconfig.go b/api/types/pluginconfig.go index 741e5debc..aa511ae79 100644 --- a/api/types/pluginconfig.go +++ b/api/types/pluginconfig.go @@ -4,8 +4,10 @@ package types type HelmConfig struct { - Enabled bool - Command string + Enabled bool + Command string + ApiVersions []string + KubeVersion string } // PluginConfig holds plugin configuration. diff --git a/kustomize/commands/build/build.go b/kustomize/commands/build/build.go index 3e884a612..5914f8959 100644 --- a/kustomize/commands/build/build.go +++ b/kustomize/commands/build/build.go @@ -27,10 +27,12 @@ var theFlags struct { managedByLabel bool helm bool } - helmCommand string - loadRestrictor string - reorderOutput string - fnOptions types.FnPluginLoadingOptions + helmCommand string + helmApiVersions []string + helmKubeVersion string + loadRestrictor string + reorderOutput string + fnOptions types.FnPluginLoadingOptions } 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.Command = theFlags.helmCommand + kOpts.PluginConfig.HelmConfig.ApiVersions = theFlags.helmApiVersions + kOpts.PluginConfig.HelmConfig.KubeVersion = theFlags.helmKubeVersion kOpts.AddManagedbyLabel = isManagedByLabelEnabled() return kOpts } diff --git a/kustomize/commands/build/flagenablehelm.go b/kustomize/commands/build/flagenablehelm.go index 1a328ce67..a379d180a 100644 --- a/kustomize/commands/build/flagenablehelm.go +++ b/kustomize/commands/build/flagenablehelm.go @@ -21,4 +21,14 @@ func AddFlagEnableHelm(set *pflag.FlagSet) { "helm-command", "helm", // default "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") } diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go index 01adb29f5..f72047c41 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go @@ -59,6 +59,15 @@ func (p *plugin) Config( if h.GeneralConfig().HelmConfig.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 if err = yaml.Unmarshal(config, p); err != nil { return