diff --git a/examples/integration-tests/envs/dev/env-data.ytt.yaml b/examples/integration-tests/envs/dev/env-data.ytt.yaml index 3234a9da..df486aef 100644 --- a/examples/integration-tests/envs/dev/env-data.ytt.yaml +++ b/examples/integration-tests/envs/dev/env-data.ytt.yaml @@ -15,3 +15,4 @@ environment: - proto: ytt-render-test name: ytt-installation - proto: static-test + - proto: helm-myks-context diff --git a/examples/integration-tests/prototypes/helm-myks-context/helm/test-chart-name.yaml b/examples/integration-tests/prototypes/helm-myks-context/helm/test-chart-name.yaml new file mode 100644 index 00000000..cdaeb5ed --- /dev/null +++ b/examples/integration-tests/prototypes/helm-myks-context/helm/test-chart-name.yaml @@ -0,0 +1,4 @@ +#@ load("@ytt:data", "data") +--- +outputYaml: + myksContext: #@ data.values.myks.context diff --git a/examples/integration-tests/prototypes/helm-myks-context/vendir/base.ytt.yaml b/examples/integration-tests/prototypes/helm-myks-context/vendir/base.ytt.yaml new file mode 100644 index 00000000..e61dcc39 --- /dev/null +++ b/examples/integration-tests/prototypes/helm-myks-context/vendir/base.ytt.yaml @@ -0,0 +1,12 @@ +#@ load("@ytt:data", "data") + +#@ app = data.values.application +--- +apiVersion: vendir.k14s.io/v1alpha1 +kind: Config +directories: + - path: charts/test-chart-name + contents: + - path: . + directory: + path: ../_lib/charts/render-test-chart diff --git a/examples/integration-tests/rendered/argocd/mykso-dev/app-helm-myks-context.yaml b/examples/integration-tests/rendered/argocd/mykso-dev/app-helm-myks-context.yaml new file mode 100644 index 00000000..f57c3441 --- /dev/null +++ b/examples/integration-tests/rendered/argocd/mykso-dev/app-helm-myks-context.yaml @@ -0,0 +1,25 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + finalizers: + - resources-finalizer.argocd.argoproj.io + name: app-mykso-dev-helm-myks-context + namespace: system-argocd +spec: + destination: + name: mykso-dev + namespace: helm-myks-context + project: env-mykso-dev + source: + path: examples/integration-tests/rendered/envs/mykso-dev/helm-myks-context + 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 diff --git a/examples/integration-tests/rendered/envs/mykso-dev/helm-myks-context/rendering-helm-test-chart-name.yaml b/examples/integration-tests/rendered/envs/mykso-dev/helm-myks-context/rendering-helm-test-chart-name.yaml new file mode 100644 index 00000000..bf45bc47 --- /dev/null +++ b/examples/integration-tests/rendered/envs/mykso-dev/helm-myks-context/rendering-helm-test-chart-name.yaml @@ -0,0 +1,11 @@ +kind: rendering +metadata: + name: helm-test-chart-name +outputYaml: + fromChartDefaultValues: true + myksContext: + app: helm-myks-context + helm: + chart: test-chart-name + prototype: prototypes/helm-myks-context + step: render diff --git a/internal/myks/assets/data-schema.ytt.yaml b/internal/myks/assets/data-schema.ytt.yaml index e5d673fd..1f592e91 100644 --- a/internal/myks/assets/data-schema.ytt.yaml +++ b/internal/myks/assets/data-schema.ytt.yaml @@ -146,3 +146,7 @@ myks: prototype: '' #! rendering step: init, argocd, global_ytt, helm, ytt-pkg, ytt step: '' + #! information related to the helm step + helm: + #! name of the helm chart currently being processed + chart: '' diff --git a/internal/myks/render.go b/internal/myks/render.go index e7c70e81..4cf88f3b 100644 --- a/internal/myks/render.go +++ b/internal/myks/render.go @@ -163,6 +163,7 @@ func genRenderedResourceFileName(resource map[string]any, includeNamespace bool) // from the `helm` or `ytt` directories of the prototype and the application. func (a *Application) prepareValuesFile(dirName string, resourceName string) (string, error) { valuesFileName := filepath.Join(dirName, resourceName+".yaml") + yttArgs := []string{"-v", "myks.context.helm.chart=" + resourceName} var valuesFiles []string @@ -185,7 +186,8 @@ func (a *Application) prepareValuesFile(dirName string, resourceName string) (st return "", nil } - resourceValuesYaml, err := a.ytt(renderStepName, "collect data values file", concatenate(a.yttDataFiles, valuesFiles)) + // render zero or more yaml documents - values files + resourceValuesYaml, err := a.ytt(renderStepName, "collect data values file", concatenate(a.yttDataFiles, valuesFiles), yttArgs...) if err != nil { return "", err } @@ -201,6 +203,8 @@ func (a *Application) prepareValuesFile(dirName string, resourceName string) (st return "", err } + // merge previously rendered yaml documents into one, + // in the way Helm would do that with all values files resourceValues, err := a.mergeValuesYaml(renderStepName, a.expandServicePath(valuesFileName)) if err != nil { return "", err