Skip to content

Commit

Permalink
Support setting helm namespace in Bookfile (#173)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Suter <[email protected]>
Co-authored-by: Kent Rancourt <[email protected]>
  • Loading branch information
moensch and krancour authored Sep 27, 2023
1 parent c345348 commit 4ad4569
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/docs/30-how-to-guides/10-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ branchConfigs:
configManagement:
helm:
releaseName: foo
namespace: foo #optional
chartPath: charts/foo
valuesPaths:
- env/test/foo/values.yaml
Expand All @@ -207,6 +208,7 @@ branchConfigs:
configManagement:
helm:
releaseName: bar
namespace: bar #optional
chartPath: charts/bar
valuesPaths:
- env/test/bar/values.yaml
Expand All @@ -217,6 +219,7 @@ branchConfigs:
configManagement:
helm:
releaseName: foo
namespace: foo #optional
chartPath: charts/foo
valuesPaths:
- env/stage/foo/values.yaml
Expand All @@ -225,6 +228,7 @@ branchConfigs:
configManagement:
helm:
releaseName: bar
namespace: bar #optional
chartPath: charts/bar
valuesPaths:
- env/stage/bar/values.yaml
Expand All @@ -235,6 +239,7 @@ branchConfigs:
configManagement:
helm:
releaseName: foo
namespace: foo #optional
chartPath: charts/foo
valuesPaths:
- env/prod/foo/values.yaml
Expand All @@ -243,6 +248,7 @@ branchConfigs:
configManagement:
helm:
releaseName: bar
namespace: bar #optional
chartPath: charts/bar
valuesPaths:
- env/prod/bar/values.yaml
Expand Down Expand Up @@ -332,6 +338,7 @@ branchConfigs:
configManagement:
helm:
releaseName: foo
namespace: foo #optional
chartPath: charts/foo
valuesPaths:
- env/${1}/foo/values.yaml
Expand All @@ -340,6 +347,7 @@ branchConfigs:
configManagement:
helm:
releaseName: bar
namespace: bar #optional
chartPath: charts/bar
valuesPaths:
- env/${1}/bar/values.yaml
Expand Down
4 changes: 4 additions & 0 deletions internal/helm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type Config struct {
// `--values` flag in the `helm template` command. By convention, if left
// unspecified, one path will be assumed: <branch name>/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
Expand Down
2 changes: 2 additions & 0 deletions internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func Render(
ctx context.Context,
releaseName string,
namespace string,
chartPath string,
valuesPaths []string,
) ([]byte, error) {
Expand All @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions rendering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -56,6 +57,7 @@ func (s *service) preRender(
manifests[appName], err = s.helmRenderFn(
ctx,
appConfig.ConfigManagement.Helm.ReleaseName,
appConfig.ConfigManagement.Helm.Namespace,
chartPath,
absValuesPaths,
)
Expand Down
2 changes: 2 additions & 0 deletions rendering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestPreRender(t *testing.T) {
context.Context,
string,
string,
string,
[]string,
) ([]byte, error) {
return nil, errors.New("something went wrong")
Expand Down Expand Up @@ -72,6 +73,7 @@ func TestPreRender(t *testing.T) {
context.Context,
string,
string,
string,
[]string,
) ([]byte, error) {
return fakeManifest, nil
Expand Down
4 changes: 4 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
"type": "string",
"pattern": "^\\w[\\w-]*\\w$"
},
"namespace": {
"type": "string",
"pattern": "^\\w[\\w-]*\\w$"
},
"chartPath": {
"$ref": "#/definitions/relativePath"
},
Expand Down
1 change: 1 addition & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type service struct {
helmRenderFn func(
ctx context.Context,
releaseName string,
namespace string,
chartPath string,
valuesPaths []string,
) ([]byte, error)
Expand Down

0 comments on commit 4ad4569

Please sign in to comment.