From 0e6ff3c2137a1140d2b422cfd6cc45333eb87a0f Mon Sep 17 00:00:00 2001 From: Samuel Suter Date: Wed, 27 Sep 2023 01:22:05 -0600 Subject: [PATCH] Support setting helm namespace in Bookfile Signed-off-by: Samuel Suter --- docs/docs/30-how-to-guides/10-configuration.mdx | 8 ++++++++ internal/helm/config.go | 4 ++++ internal/helm/helm.go | 2 ++ rendering.go | 2 ++ rendering_test.go | 2 ++ schema.json | 4 ++++ service.go | 1 + 7 files changed, 23 insertions(+) diff --git a/docs/docs/30-how-to-guides/10-configuration.mdx b/docs/docs/30-how-to-guides/10-configuration.mdx index 394a58b..6da5ebd 100644 --- a/docs/docs/30-how-to-guides/10-configuration.mdx +++ b/docs/docs/30-how-to-guides/10-configuration.mdx @@ -199,6 +199,7 @@ branchConfigs: configManagement: helm: releaseName: foo + namespace: foo #optional chartPath: charts/foo valuesPaths: - env/test/foo/values.yaml @@ -207,6 +208,7 @@ branchConfigs: configManagement: helm: releaseName: bar + namespace: bar #optional chartPath: charts/bar valuesPaths: - env/test/bar/values.yaml @@ -217,6 +219,7 @@ branchConfigs: configManagement: helm: releaseName: foo + namespace: foo #optional chartPath: charts/foo valuesPaths: - env/stage/foo/values.yaml @@ -225,6 +228,7 @@ branchConfigs: configManagement: helm: releaseName: bar + namespace: bar #optional chartPath: charts/bar valuesPaths: - env/stage/bar/values.yaml @@ -235,6 +239,7 @@ branchConfigs: configManagement: helm: releaseName: foo + namespace: foo #optional chartPath: charts/foo valuesPaths: - env/prod/foo/values.yaml @@ -243,6 +248,7 @@ branchConfigs: configManagement: helm: releaseName: bar + namespace: bar #optional chartPath: charts/bar valuesPaths: - env/prod/bar/values.yaml @@ -332,6 +338,7 @@ branchConfigs: configManagement: helm: releaseName: foo + namespace: foo #optional chartPath: charts/foo valuesPaths: - env/${1}/foo/values.yaml @@ -340,6 +347,7 @@ branchConfigs: configManagement: helm: releaseName: bar + namespace: bar #optional chartPath: charts/bar valuesPaths: - env/${1}/bar/values.yaml diff --git a/internal/helm/config.go b/internal/helm/config.go index 36f4fef..46a28cc 100644 --- a/internal/helm/config.go +++ b/internal/helm/config.go @@ -17,6 +17,10 @@ type Config struct { // `--values` flag in the `helm template` command. By convention, if left // unspecified, one path will be assumed: /values.yaml. ValuesPaths []string `json:"valuesPaths,omitempty"` + // Namespace is the Kubernetes namespace in which the Helm chart will be + // rendered. This is used as an argument in the `helm template` command. By + // convention, if left unspecified, the value `default` is assumed. + Namespace string `json:"namespace,omitempty"` } // Expand expands all file/directory paths referenced by this configuration diff --git a/internal/helm/helm.go b/internal/helm/helm.go index 8501fbc..2c2b3c8 100644 --- a/internal/helm/helm.go +++ b/internal/helm/helm.go @@ -18,6 +18,7 @@ import ( func Render( ctx context.Context, releaseName string, + namespace string, chartPath string, valuesPaths []string, ) ([]byte, error) { @@ -31,6 +32,7 @@ func Render( "", // Repo root "", // Revision &apiclient.ManifestRequest{ + Namespace: namespace, // Both of these fields need to be non-nil Repo: &argoappv1.Repository{}, ApplicationSource: &argoappv1.ApplicationSource{ diff --git a/rendering.go b/rendering.go index 5c0b6e6..4b35129 100644 --- a/rendering.go +++ b/rendering.go @@ -45,6 +45,7 @@ func (s *service) preRender( appLogger = appLogger.WithFields(log.Fields{ "configManagement": "helm", "releaseName": appConfig.ConfigManagement.Helm.ReleaseName, + "namespace": appConfig.ConfigManagement.Helm.Namespace, "chartPath": chartPath, "valuesPaths": valuesPaths, }) @@ -56,6 +57,7 @@ func (s *service) preRender( manifests[appName], err = s.helmRenderFn( ctx, appConfig.ConfigManagement.Helm.ReleaseName, + appConfig.ConfigManagement.Helm.Namespace, chartPath, absValuesPaths, ) diff --git a/rendering_test.go b/rendering_test.go index 7959efb..1b0c8bf 100644 --- a/rendering_test.go +++ b/rendering_test.go @@ -42,6 +42,7 @@ func TestPreRender(t *testing.T) { context.Context, string, string, + string, []string, ) ([]byte, error) { return nil, errors.New("something went wrong") @@ -72,6 +73,7 @@ func TestPreRender(t *testing.T) { context.Context, string, string, + string, []string, ) ([]byte, error) { return fakeManifest, nil diff --git a/schema.json b/schema.json index 44eb63e..039d68e 100644 --- a/schema.json +++ b/schema.json @@ -102,6 +102,10 @@ "type": "string", "pattern": "^\\w[\\w-]*\\w$" }, + "namespace": { + "type": "string", + "pattern": "^\\w[\\w-]*\\w$" + }, "chartPath": { "$ref": "#/definitions/relativePath" }, diff --git a/service.go b/service.go index a5a0709..91c87cc 100644 --- a/service.go +++ b/service.go @@ -35,6 +35,7 @@ type service struct { helmRenderFn func( ctx context.Context, releaseName string, + namespace string, chartPath string, valuesPaths []string, ) ([]byte, error)