-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: per-chart helm configuration #310
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45e8aac
feat: per-chart helm configuration
Zebradil 256291c
add schema validation
Zebradil 96dc6f0
commit forgotten file
Zebradil 21458e7
correctly handle boolean overrides
Zebradil d3a17b5
add unit tests
Zebradil 2a06bd1
add unit test for three chart overrides
Zebradil e665b15
add integration test for per-chart overrides
Zebradil 6273886
fix typo
Zebradil fc382b4
warn about configuration for non-existing charts
Zebradil 2f8fead
Merge branch 'main' into 261-feat-implement-per-chart-configuration
Zebradil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
examples/integration-tests/prototypes/per-chart-override/app-data.ytt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#@data/values | ||
--- | ||
helm: | ||
charts: | ||
- name: render-test-1 | ||
releaseName: overridden-release-name-1 | ||
- name: render-test-2 | ||
releaseName: overridden-release-name-2 |
13 changes: 13 additions & 0 deletions
13
examples/integration-tests/prototypes/per-chart-override/vendir/all.ytt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: vendir.k14s.io/v1alpha1 | ||
kind: Config | ||
directories: | ||
- path: charts/render-test-1 | ||
contents: | ||
- path: . | ||
directory: | ||
path: ../_lib/charts/render-test-chart | ||
- path: charts/render-test-2 | ||
contents: | ||
- path: . | ||
directory: | ||
path: ../_lib/charts/render-test-chart |
25 changes: 25 additions & 0 deletions
25
examples/integration-tests/rendered/argocd/mykso-dev/app-per-chart-override.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
metadata: | ||
name: app-mykso-dev-per-chart-override | ||
namespace: system-argocd | ||
finalizers: | ||
- resources-finalizer.argocd.argoproj.io | ||
spec: | ||
project: env-mykso-dev | ||
destination: | ||
name: mykso-dev | ||
namespace: per-chart-override | ||
source: | ||
path: examples/integration-tests/rendered/envs/mykso-dev/per-chart-override | ||
plugin: | ||
name: argocd-vault-plugin-v1.0.0 | ||
repoURL: git@github.com:mykso/myks.git | ||
targetRevision: main | ||
syncPolicy: | ||
automated: | ||
prune: true | ||
selfHeal: true | ||
syncOptions: | ||
- CreateNamespace=true | ||
- ServerSideApply=true |
5 changes: 5 additions & 0 deletions
5
.../rendered/envs/mykso-dev/per-chart-override/rendering-helm-overridden-release-name-1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: rendering | ||
metadata: | ||
name: helm-overridden-release-name-1 | ||
outputYaml: | ||
fromChartDefaultValues: true |
5 changes: 5 additions & 0 deletions
5
.../rendered/envs/mykso-dev/per-chart-override/rendering-helm-overridden-release-name-2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: rendering | ||
metadata: | ||
name: helm-overridden-release-name-2 | ||
outputYaml: | ||
fromChartDefaultValues: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package myks | ||
|
||
import ( | ||
"fmt" | ||
|
||
yaml "gopkg.in/yaml.v3" | ||
) | ||
|
||
type HelmConfig struct { | ||
BuildDependencies bool `yaml:"buildDependencies"` | ||
Capabilities []string `yaml:"capabilities"` | ||
IncludeCRDs bool `yaml:"includeCRDs"` | ||
KubeVersion string `yaml:"kubeVersion"` | ||
Namespace string `yaml:"namespace"` | ||
ReleaseName string | ||
|
||
Charts map[string]HelmChartOverride `yaml:"charts"` | ||
} | ||
|
||
type HelmChartOverride struct { | ||
BuildDependencies *bool `yaml:"buildDependencies"` | ||
IncludeCRDs *bool `yaml:"includeCRDs"` | ||
Namespace string `yaml:"namespace"` | ||
ReleaseName string `yaml:"releaseName"` | ||
} | ||
|
||
func newHelmConfig(dataValuesYaml string) (HelmConfig, error) { | ||
type originalChartConfig struct { | ||
BuildDependencies *bool `yaml:"buildDependencies"` | ||
IncludeCRDs *bool `yaml:"includeCRDs"` | ||
Name string `yaml:"name"` | ||
Namespace string `yaml:"namespace"` | ||
ReleaseName string `yaml:"releaseName"` | ||
} | ||
|
||
type fullHelmConfig struct { | ||
BuildDependencies bool `yaml:"buildDependencies"` | ||
Capabilities []string `yaml:"capabilities"` | ||
IncludeCRDs bool `yaml:"includeCRDs"` | ||
KubeVersion string `yaml:"kubeVersion"` | ||
Namespace string `yaml:"namespace"` | ||
Charts []originalChartConfig `yaml:"charts"` | ||
} | ||
|
||
var helmConfigWrapper struct { | ||
Helm fullHelmConfig `yaml:"helm"` | ||
} | ||
|
||
if err := yaml.Unmarshal([]byte(dataValuesYaml), &helmConfigWrapper); err != nil { | ||
return HelmConfig{}, err | ||
} | ||
|
||
helmConfig := HelmConfig{ | ||
BuildDependencies: helmConfigWrapper.Helm.BuildDependencies, | ||
Capabilities: helmConfigWrapper.Helm.Capabilities, | ||
IncludeCRDs: helmConfigWrapper.Helm.IncludeCRDs, | ||
KubeVersion: helmConfigWrapper.Helm.KubeVersion, | ||
Namespace: helmConfigWrapper.Helm.Namespace, | ||
} | ||
|
||
if len(helmConfigWrapper.Helm.Charts) == 0 { | ||
return helmConfig, nil | ||
} | ||
|
||
chartConfigs := map[string]HelmChartOverride{} | ||
for i, chart := range helmConfigWrapper.Helm.Charts { | ||
if chart.Name == "" { | ||
return HelmConfig{}, fmt.Errorf("helm.charts[%d].name is required", i) | ||
} | ||
if _, ok := chartConfigs[chart.Name]; ok { | ||
return HelmConfig{}, fmt.Errorf("helm.charts[%d].name is not unique", i) | ||
} | ||
chartConfigs[chart.Name] = HelmChartOverride{ | ||
BuildDependencies: chart.BuildDependencies, | ||
IncludeCRDs: chart.IncludeCRDs, | ||
Namespace: chart.Namespace, | ||
ReleaseName: chart.ReleaseName, | ||
} | ||
} | ||
helmConfig.Charts = chartConfigs | ||
|
||
return helmConfig, nil | ||
} | ||
|
||
func (cfg *HelmConfig) getChartConfig(chartName string) HelmConfig { | ||
chartConfig := HelmConfig{ | ||
BuildDependencies: cfg.BuildDependencies, | ||
IncludeCRDs: cfg.IncludeCRDs, | ||
Namespace: cfg.Namespace, | ||
} | ||
|
||
if cc, ok := cfg.Charts[chartName]; ok { | ||
if cc.Namespace != "" { | ||
chartConfig.Namespace = cc.Namespace | ||
} | ||
if cc.ReleaseName != "" { | ||
chartConfig.ReleaseName = cc.ReleaseName | ||
} | ||
if cc.BuildDependencies != nil { | ||
chartConfig.BuildDependencies = *cc.BuildDependencies | ||
} | ||
if cc.IncludeCRDs != nil { | ||
chartConfig.IncludeCRDs = *cc.IncludeCRDs | ||
} | ||
} | ||
|
||
return chartConfig | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also validate for charts being part of the config, but not of the actual app. Of course, this would lead to a lot of errors/warnings, if you define your chart-specific configuration in the env-data.ytt.yaml. Nevertheless, this feature seems more likely to be used in the app-data.ytt.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an interesting idea. I think we can give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented. This is how it looks like.
Currently, there is no central place for config validation (and it will require significant changes to the overall program structure to implement it), this is why it is duplicated in the
sync
andrender
steps and printed twice. But I think we can live with that :-)Later, if these warnings are too annoying, we can add a switch to disable it.