-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: per-chart helm configuration (#310)
- Loading branch information
Showing
14 changed files
with
450 additions
and
75 deletions.
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: [email protected]: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.