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

Support setting helm namespace in Bookfile #173

Merged
merged 4 commits into from
Sep 27, 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
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 @@
func Render(
ctx context.Context,
releaseName string,
namespace string,
chartPath string,
valuesPaths []string,
) ([]byte, error) {
Expand All @@ -31,6 +32,7 @@
"", // Repo root
"", // Revision
&apiclient.ManifestRequest{
Namespace: namespace,

Check warning on line 35 in internal/helm/helm.go

View check run for this annotation

Codecov / codecov/patch

internal/helm/helm.go#L35

Added line #L35 was not covered by tests
// 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