From 754187d1d2d75563240bbc0c4e114b05fd1dd785 Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Tue, 12 Apr 2022 12:45:31 +0200 Subject: [PATCH] Support no-hooks flag Fixes https://github.com/k3s-io/helm-controller/issues/97 Signed-off-by: Bastian Hofmann --- pkg/apis/helm.cattle.io/v1/types.go | 1 + pkg/helm/controller.go | 3 +++ pkg/helm/controller_test.go | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/pkg/apis/helm.cattle.io/v1/types.go b/pkg/apis/helm.cattle.io/v1/types.go index 05599960..07af891b 100644 --- a/pkg/apis/helm.cattle.io/v1/types.go +++ b/pkg/apis/helm.cattle.io/v1/types.go @@ -30,6 +30,7 @@ type HelmChartSpec struct { JobImage string `json:"jobImage,omitempty"` Timeout *metav1.Duration `json:"timeout,omitempty"` FailurePolicy string `json:"failurePolicy,omitempty"` + NoHooks bool `json:"noHooks,omitempty"` } type HelmChartStatus struct { diff --git a/pkg/helm/controller.go b/pkg/helm/controller.go index 9c85a600..4dc42189 100644 --- a/pkg/helm/controller.go +++ b/pkg/helm/controller.go @@ -462,6 +462,9 @@ func args(chart *helmv1.HelmChart) []string { if spec.Version != "" { args = append(args, "--version", spec.Version) } + if spec.NoHooks { + args = append(args, "--no-hooks") + } for _, k := range keys(spec.Set) { val := spec.Set[k] diff --git a/pkg/helm/controller_test.go b/pkg/helm/controller_test.go index 40abc09d..e2de9501 100644 --- a/pkg/helm/controller_test.go +++ b/pkg/helm/controller_test.go @@ -65,6 +65,21 @@ func TestInstallArgs(t *testing.T) { stringArgs) } +func TestInstallArgsWithNoHooks(t *testing.T) { + assert := assert.New(t) + chart := NewChart() + chart.Spec.NoHooks = true + stringArgs := strings.Join(args(chart), " ") + assert.Equal("install "+ + "--no-hooks "+ + "--set-string acme.dnsProvider.name=cloudflare "+ + "--set-string global.clusterCIDR=10.42.0.0/16\\,fd42::/48 "+ + "--set-string global.systemDefaultRegistry= "+ + "--set rbac.enabled=true "+ + "--set ssl.enabled=false", + stringArgs) +} + func TestDeleteArgs(t *testing.T) { assert := assert.New(t) chart := NewChart()