Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kube version override #1662

Merged
merged 13 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ zarf prepare find-images [PACKAGE] [flags]

```
-h, --help help for find-images
--kube-version string Override the default helm template KubeVersion when performing a package chart template
-p, --repo-chart-path string If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"
--set stringToString Specify package variables to set on the command line (KEY=value). Note, if using a config file, this will be set by [package.create.set]. (default [])
```
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
)

var repoHelmChartPath string
var repoHelmChartPath, kubeVersionOverride string
var prepareCmd = &cobra.Command{
Use: "prepare",
Aliases: []string{"prep"},
Expand Down Expand Up @@ -109,7 +109,7 @@ var prepareFindImages = &cobra.Command{
defer pkgClient.ClearTempPaths()

// Find all the images the package might need
if err := pkgClient.FindImages(baseDir, repoHelmChartPath); err != nil {
if err := pkgClient.FindImages(baseDir, repoHelmChartPath, kubeVersionOverride); err != nil {
message.Fatalf(err, "Unable to find images for the package definition %s", baseDir)
}
},
Expand Down Expand Up @@ -149,6 +149,8 @@ func init() {
prepareFindImages.Flags().StringVarP(&repoHelmChartPath, "repo-chart-path", "p", "", lang.CmdPrepareFlagRepoChartPath)
// use the package create config for this and reset it here to avoid overwriting the config.CreateOptions.SetVariables
prepareFindImages.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(V_PKG_CREATE_SET), lang.CmdPrepareFlagSet)
// allow for the override of the default helm KubeVersion
prepareFindImages.Flags().StringVar(&kubeVersionOverride, "kube-version", "", lang.CmdPrepareFlagKubeVersion)

prepareTransformGitLinks.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", config.ZarfGitPushUser, lang.CmdPrepareFlagGitAccount)
}
1 change: 1 addition & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ zarf init --git-push-password={PASSWORD} --git-push-username={USERNAME} --git-ur
CmdPrepareFlagSet = "Specify package variables to set on the command line (KEY=value). Note, if using a config file, this will be set by [package.create.set]."
CmdPrepareFlagRepoChartPath = `If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"`
CmdPrepareFlagGitAccount = "User or organization name for the git account that the repos are created under."
CmdPrepareFlagKubeVersion = "Override the default helm template KubeVersion when performing a package chart template"

// zarf tools
CmdToolsShort = "Collection of additional tools to make airgap easier"
Expand Down
9 changes: 8 additions & 1 deletion src/internal/packager/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/defenseunicorns/zarf/src/pkg/message"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"

"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/release"
Expand Down Expand Up @@ -160,7 +161,13 @@ func (h *Helm) TemplateChart() (string, error) {
// TODO: Further research this with regular/OCI charts
client.Verify = false
client.InsecureSkipTLSverify = config.CommonOptions.Insecure

if h.KubeVersion != "" {
parsedKubeVersion, err := chartutil.ParseKubeVersion(h.KubeVersion)
if err != nil {
return "", fmt.Errorf("invalid kube version '%s': %s", h.KubeVersion, err)
}
client.KubeVersion = parsedKubeVersion
}
client.ReleaseName = h.Chart.ReleaseName

// If no release name is specified, use the chart name.
Expand Down
1 change: 1 addition & 0 deletions src/internal/packager/helm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Helm struct {
Component types.ZarfComponent
Cluster *cluster.Cluster
Cfg *types.PackagerConfig
KubeVersion string

actionConfig *action.Configuration
}
Expand Down
5 changes: 3 additions & 2 deletions src/pkg/packager/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

// FindImages iterates over a Zarf.yaml and attempts to parse any images.
func (p *Packager) FindImages(baseDir, repoHelmChartPath string) error {
func (p *Packager) FindImages(baseDir, repoHelmChartPath string, kubeVersionOverride string) error {

var originalDir string

Expand Down Expand Up @@ -153,11 +153,12 @@ func (p *Packager) FindImages(baseDir, repoHelmChartPath string) error {
BasePath: componentPath.Base,
Chart: chart,
ChartLoadOverride: override,
KubeVersion: kubeVersionOverride,
}
template, err := helmCfg.TemplateChart()

if err != nil {
message.Errorf(err, "Problem rendering the helm template for %s", chart.URL)
message.Errorf(err, "Problem rendering the helm template for %s: %s", chart.URL, err.Error())
continue
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/e2e/00_use_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func TestUseCLI(t *testing.T) {
assert.NoError(t, err, stdOut, stdErr)
assert.Contains(t, stdOut, "nginx:1.16.0", "The chart image should be found by Zarf")

// Test `zarf prepare find-images` on a chart that has a `kubeVersion` declaration greater than the default (v1.20.0)
_, stdErr, err = e2e.ExecZarfCommand("prepare", "find-images", "src/test/test-packages/00-kube-version-override")
require.Contains(t, stdErr, "Problem rendering the helm template for https://charts.jetstack.io/", "The kubeVersion declaration should prevent this from templating")

// Test `zarf prepare find-images` with `--kube-version` specified and greater than the declared minimum (v1.21.0)
stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "find-images", "--kube-version=v1.22.0", "src/test/test-packages/00-kube-version-override")
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdOut, "quay.io/jetstack/cert-manager-controller:v1.11.1", "The chart image should be found by Zarf")

// Test for expected failure when given a bad component input
_, _, err = e2e.ExecZarfCommand("init", "--confirm", "--components=k3s,foo,logging")
assert.Error(t, err)
Expand Down
13 changes: 13 additions & 0 deletions src/test/test-packages/00-kube-version-override/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: ZarfPackageConfig
metadata:
name: cert-manager
description: Cloud native certificate management
components:
- name: cert-manager-component
description: Cloud native certificate management
required: true
charts:
- name: cert-manager
version: v1.11.1
namespace: cert-manager
url: https://charts.jetstack.io/