diff --git a/examples/render-helm-chart-kustomize-inline-values/kustomization.yaml b/examples/render-helm-chart-kustomize-inline-values/kustomization.yaml index 783331dfd..abc4cae03 100644 --- a/examples/render-helm-chart-kustomize-inline-values/kustomization.yaml +++ b/examples/render-helm-chart-kustomize-inline-values/kustomization.yaml @@ -10,16 +10,19 @@ generators: network: true image: gcr.io/kpt-fn/render-helm-chart:unstable helmCharts: - - name: ocp-pipeline - namespace: mynamespace - version: 0.1.16 - repo: https://bcgov.github.io/helm-charts - releaseName: moria - valuesInline: - releaseNamespace: "" - rbac: - create: true - rules: - - apiGroups: [""] - verbs: ["*"] - resources: ["*"] + - chartArgs: + name: ocp-pipeline + version: 0.1.16 + repo: https://bcgov.github.io/helm-charts + templateOptions: + releaseName: moria + namespace: mynamespace + values: + valuesInline: + releaseNamespace: "" + rbac: + create: true + rules: + - apiGroups: [""] + verbs: ["*"] + resources: ["*"] \ No newline at end of file diff --git a/examples/render-helm-chart-kustomize-values-files/.expected/diff.patch b/examples/render-helm-chart-kustomize-values-files/.expected/diff.patch new file mode 100644 index 000000000..d8e125e2b --- /dev/null +++ b/examples/render-helm-chart-kustomize-values-files/.expected/diff.patch @@ -0,0 +1,133 @@ +diff --git a/resources.yaml b/resources.yaml +new file mode 100644 +index 0000000..e2e869b +--- /dev/null ++++ b/resources.yaml +@@ -0,0 +1,127 @@ ++apiVersion: rbac.authorization.k8s.io/v1 ++kind: Role ++metadata: ++ name: moria-ocp-pipeline ++ namespace: mynamespace ++rules: ++- apiGroups: ++ - "" ++ resources: ++ - '*' ++ verbs: ++ - '*' ++--- ++apiVersion: rbac.authorization.k8s.io/v1 ++kind: RoleBinding ++metadata: ++ name: moria-ocp-pipeline ++ namespace: mynamespace ++roleRef: ++ apiGroup: rbac.authorization.k8s.io ++ kind: Role ++ name: moria-ocp-pipeline ++subjects: ++- kind: ServiceAccount ++ name: jenkins ++ namespace: mynamespace ++--- ++apiVersion: v1 ++data: ++ config: eyJleGFtcGxlIjoidmFsdWUifQ== ++kind: Secret ++metadata: ++ labels: ++ chart: ocp-pipeline-0.1.16 ++ heritage: Helm ++ release: moria ++ name: moria-config ++type: Opaque ++--- ++apiVersion: v1 ++data: ++ WebHookSecretKey: MTIzNDU2Nzg= ++kind: Secret ++metadata: ++ labels: ++ chart: ocp-pipeline-0.1.16 ++ heritage: Helm ++ release: moria ++ name: moria-git-webhook-secret ++type: Opaque ++--- ++apiVersion: build.openshift.io/v1 ++kind: BuildConfig ++metadata: ++ labels: ++ app: ocp-pipeline ++ chart: ocp-pipeline-0.1.16 ++ heritage: Helm ++ release: moria ++ name: moria-ocp-pipeline-deploy ++ namespace: null ++spec: ++ nodeSelector: {} ++ resources: ++ limits: ++ cpu: 4000m ++ memory: 8G ++ requests: ++ cpu: 2000m ++ memory: 4G ++ strategy: ++ jenkinsPipelineStrategy: ++ jenkinsfile: |- ++ def helmName = "helm-v3.1.0-linux-amd64.tar.gz" ++ def chartName = "metadata-curator" ++ def chartRepo = "http://bcgov.github.io/helm-charts" ++ def releaseName = "mc" ++ def releaseNamespace = "" ++ def forceRecreate = "false" ++ def callAnotherPipe = "false" ++ def useEnv = "false" ++ def fromEnv = "commit" ++ def setFlag = "image.tag" ++ ++ node("nodejs") { ++ stage("deploy (it's already built)") { ++ sh """ ++ curl -L -O https://get.helm.sh/${helmName} ++ tar -zxvf ${helmName} ++ cd linux-amd64 ++ ++ curl -L -O https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux32 ++ chmod ugo+x ./jq-linux32 ++ npm install -g json2yaml ++ ++ export CONF1=`oc get secret moria-config -o json | ./jq-linux32 .data.config` ++ export CONF2=`sed -e 's/^"//' -e 's/"\$//' <<<"\$CONF1"` ++ export CONF3=`echo \$CONF2 | base64 -d -` ++ export CONF=`echo \$CONF3 | json2yaml` ++ ++ echo "\$CONF" > ./config.yaml ++ oc project ${releaseNamespace} ++ ./helm repo add chart ${chartRepo} ++ ./helm repo update ++ if [ "${forceRecreate}" = "true" ]; then ++ ./helm upgrade ${releaseName} chart/${chartName} -f ./config.yaml --install --set hashLabel="${releaseName}\$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)" ++ elif [ "${useEnv}" = "true" ]; then ++ ./helm upgrade ${releaseName} chart/${chartName} -f ./config.yaml --install --set ${setFlag}=${env[fromEnv]} ++ else ++ ./helm upgrade ${releaseName} chart/${chartName} -f ./config.yaml --install ++ fi ++ ++ if [ "${callAnotherPipe}" = "true" ]; then ++ curl -d '' http://otherwebhookUrl ++ fi ++ """ ++ } ++ } ++ type: JenkinsPipeline ++ triggers: ++ - generic: ++ allowEnv: true ++ secretReference: ++ name: moria-git-webhook-secret ++ type: generic ++status: ++ lastVersion: 0 diff --git a/examples/render-helm-chart-kustomize-values-files/.expected/exec.sh b/examples/render-helm-chart-kustomize-values-files/.expected/exec.sh new file mode 100644 index 000000000..581eee80d --- /dev/null +++ b/examples/render-helm-chart-kustomize-values-files/.expected/exec.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# kustomize 4.2.0 is preinstalled in github actions +kustomize build --enable-alpha-plugins --network > resources.yaml diff --git a/examples/render-helm-chart-kustomize-values-files/.krmignore b/examples/render-helm-chart-kustomize-values-files/.krmignore new file mode 100644 index 000000000..9d7a4007d --- /dev/null +++ b/examples/render-helm-chart-kustomize-values-files/.krmignore @@ -0,0 +1 @@ +.expected diff --git a/examples/render-helm-chart-kustomize-values-files/README.md b/examples/render-helm-chart-kustomize-values-files/README.md new file mode 100644 index 000000000..5c0b08bc0 --- /dev/null +++ b/examples/render-helm-chart-kustomize-values-files/README.md @@ -0,0 +1,81 @@ +# render-helm-chart: Kustomize Values Files + +### Overview + +This example demonstrates how to declaratively invoke the `render-helm-chart` +function with kustomize using multiple values files. + +### Function invocation + +To use the function with kustomize, you can specify the `functionConfig` +in your kustomization's `generators` field. This example specifies multiple remote +values files to use instead of the default values accompanying the chart: + +kustomization.yaml: +```yaml +generators: +- |- + apiVersion: fn.kpt.dev/v1alpha1 + kind: RenderHelmChart + metadata: + name: demo + annotations: + config.kubernetes.io/function: | + container: + network: true + image: gcr.io/kpt-fn/render-helm-chart:unstable + helmCharts: + - chartArgs: + name: ocp-pipeline + version: 0.1.16 + repo: https://bcgov.github.io/helm-charts + templateOptions: + namespace: mynamespace + releaseName: moria + values: + valuesFiles: + - https://raw.githubusercontent.com/natasha41575/kpt-functions-catalog/a9c9cd765a05f7a7fb6923dbde4651b62c9c229c/examples/render-helm-chart-kustomize-values-files/file1.yaml + - https://raw.githubusercontent.com/natasha41575/kpt-functions-catalog/a9c9cd765a05f7a7fb6923dbde4651b62c9c229c/examples/render-helm-chart-kustomize-values-files/file2.yaml +``` + +Then, to build the kustomization with kustomize v4: + +```shell +kustomize build --enable-alpha-plugins --network . +``` + +### Expected result + +You should also be able to find the line `def releaseNamespace = ""` somewhere +in your output, as well as the following: + +```yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: moria-ocp-pipeline + namespace: mynamespace +rules: +- apiGroups: + - "" + resources: + - '*' + verbs: + - '*' +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: moria-ocp-pipeline + namespace: mynamespace +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: moria-ocp-pipeline +subjects: +- kind: ServiceAccount + name: jenkins + namespace: mynamespace +``` + +which demonstrates that the correct values provided via `valuesFiles` were used. diff --git a/examples/render-helm-chart-kustomize-values-files/kustomization.yaml b/examples/render-helm-chart-kustomize-values-files/kustomization.yaml new file mode 100644 index 000000000..53bb74f3d --- /dev/null +++ b/examples/render-helm-chart-kustomize-values-files/kustomization.yaml @@ -0,0 +1,23 @@ +generators: + - |- + apiVersion: fn.kpt.dev/v1alpha1 + kind: RenderHelmChart + metadata: + name: demo + annotations: + config.kubernetes.io/function: | + container: + network: true + image: gcr.io/kpt-fn/render-helm-chart:unstable + helmCharts: + - chartArgs: + name: ocp-pipeline + version: 0.1.16 + repo: https://bcgov.github.io/helm-charts + templateOptions: + namespace: mynamespace + releaseName: moria + values: + valuesFiles: + - https://raw.githubusercontent.com/natasha41575/kpt-functions-catalog/a9c9cd765a05f7a7fb6923dbde4651b62c9c229c/examples/render-helm-chart-kustomize-values-files/file1.yaml + - https://raw.githubusercontent.com/natasha41575/kpt-functions-catalog/a9c9cd765a05f7a7fb6923dbde4651b62c9c229c/examples/render-helm-chart-kustomize-values-files/file2.yaml diff --git a/examples/render-helm-chart-local/.expected/diff.patch b/examples/render-helm-chart-local/.expected/diff.patch index cc1f3a51c..dc733e5fc 100644 --- a/examples/render-helm-chart-local/.expected/diff.patch +++ b/examples/render-helm-chart-local/.expected/diff.patch @@ -47,32 +47,6 @@ index 0000000..8ba7f5c + path: / + port: http + resources: {} -diff --git a/pod_test-helloworld-chart-test-connection.yaml b/pod_test-helloworld-chart-test-connection.yaml -new file mode 100644 -index 0000000..8793304 ---- /dev/null -+++ b/pod_test-helloworld-chart-test-connection.yaml -@@ -0,0 +1,20 @@ -+# Source: helloworld-chart/templates/tests/test-connection.yaml -+apiVersion: v1 -+kind: Pod -+metadata: -+ name: "test-helloworld-chart-test-connection" -+ labels: -+ helm.sh/chart: helloworld-chart-0.1.0 -+ app.kubernetes.io/name: helloworld-chart -+ app.kubernetes.io/instance: test -+ app.kubernetes.io/version: "1.16.0" -+ app.kubernetes.io/managed-by: Helm -+ annotations: -+ "helm.sh/hook": test-success -+spec: -+ containers: -+ - name: wget -+ image: busybox -+ command: ['wget'] -+ args: ['test-helloworld-chart:80'] -+ restartPolicy: Never diff --git a/service_test-helloworld-chart.yaml b/service_test-helloworld-chart.yaml new file mode 100644 index 0000000..7d734d3 @@ -116,4 +90,4 @@ index 0000000..5800f2a + app.kubernetes.io/name: helloworld-chart + app.kubernetes.io/instance: test + app.kubernetes.io/version: "1.16.0" -+ app.kubernetes.io/managed-by: Helm ++ app.kubernetes.io/managed-by: Helm \ No newline at end of file diff --git a/examples/render-helm-chart-local/.expected/exec.sh b/examples/render-helm-chart-local/.expected/exec.sh index 1e15904b9..bb547f9ca 100644 --- a/examples/render-helm-chart-local/.expected/exec.sh +++ b/examples/render-helm-chart-local/.expected/exec.sh @@ -4,4 +4,5 @@ kpt fn eval --image-pull-policy never --image gcr.io/kpt-fn/render-helm-chart:un --mount type=bind,src="$(pwd)",dst=/tmp/charts -- \ name=helloworld-chart \ releaseName=test \ -valuesFile=/tmp/charts/helloworld-values/values.yaml +valuesFile=/tmp/charts/helloworld-values/values.yaml \ +skipTests=true \ No newline at end of file diff --git a/examples/render-helm-chart-local/README.md b/examples/render-helm-chart-local/README.md index 2641f13a1..7a9413f24 100644 --- a/examples/render-helm-chart-local/README.md +++ b/examples/render-helm-chart-local/README.md @@ -27,14 +27,25 @@ $ kpt fn eval --image gcr.io/kpt-fn/render-helm-chart:unstable \ releaseName=test ``` -You can optionally provide your own values files using `--valuesFile`. +You can optionally provide your own values files using `valuesFile`. ```shell $ kpt fn eval --image gcr.io/kpt-fn/render-helm-chart:unstable \ --mount type=bind,src=$(pwd),dst=/tmp/charts -- \ name=helloworld-chart \ releaseName=test \ -valuesFile=tmp/charts/helloworld-values/values.yaml +valuesFile=/tmp/charts/helloworld-values/values.yaml +``` + +You can optionally skip tests in the templated output with `skipTests`. + +```shell +$ kpt fn eval --image gcr.io/kpt-fn/render-helm-chart:unstable \ +--mount type=bind,src=$(pwd),dst=/tmp/charts -- \ +name=helloworld-chart \ +releaseName=test \ +valuesFile=/tmp/charts/helloworld-values/values.yaml \ +skipTests=true ``` ### Expected result @@ -52,3 +63,6 @@ $ kpt pkg tree You should be able to find `replicas: 5` in file `deployment_test-helloworld-chart.yaml`, which demonstrates that the correct values file provided by --valuesFile was used. + +If you provided the `skipTests` option, `pod_test-helloworld-chart-test-connection.yaml` +will not appear in your files. diff --git a/functions/go/render-helm-chart/README.md b/functions/go/render-helm-chart/README.md index ae3c7f370..b0c891c57 100644 --- a/functions/go/render-helm-chart/README.md +++ b/functions/go/render-helm-chart/README.md @@ -45,6 +45,8 @@ There are 2 kinds of `functionConfig` supported by this function: - `ConfigMap` - A custom resource of kind `RenderHelmChart` +Many of the fields in each functionConfig map directly to flag options provided by `helm template`. + #### `ConfigMap` To use a `ConfigMap` as the `functionConfig`, the desired parameters must be specified in the `data` field: @@ -58,26 +60,28 @@ data: repo: string releaseName: string namespace: string - valuesFile: string + nameTemplate: string includeCRDs: string + skipTests: string + valuesFile: string ``` -| Field | Description | Example -| -----------: | ----------- | ----------- -`chartHome` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts -`configHome` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config -`name` | The name of the chart | minecraft -`version` | The version of the chart | 3.1.3 -`repo` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts -`releaseName` | Replaces RELEASE_NAME in the chart template output | test -`namespace` | Sets the target namespace for a release (`.Release.Namespace` in the template) | my-namespace -`valuesFile` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where `chartHome` and `name` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml -`includeCRDs` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true" +| Field | Description | Example +| -----------: | ----------- | ----------- +`chartHome` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts +`configHome` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config +`name` | The name of the chart | minecraft +`version` | The version of the chart | 3.1.3 +`repo` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts +`releaseName` | Replaces RELEASE_NAME in the chart template output | test +`namespace` | Sets the target namespace for a release (`.Release.Namespace` in the template) | my-namespace +`nameTemplate` | Specify the template used to name the release | gatekeeper +`includeCRDs` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true" +`skipTests` | If set, skip tests from templated output. Legal values: "true", "false" (default). | "true" +`valuesFile` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where `chartHome` and `name` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml -The only required field is `name`. - #### `RenderHelmChart` A `functionConfig` of kind `RenderHelmChart` has the following supported parameters: @@ -86,34 +90,44 @@ helmGlobals: chartHome: string configHome: string helmCharts: -- name: string - version: string - repo: string - releaseName: string - namespace: string - valuesInline: map[string]interface{} - valuesFile: string - valuesMerge: string - includeCRDs: bool +- chartArgs: + name: string + version: string + repo: string + templateOptions: + apiVersions: []string + releaseName: string + namespace: string + nameTemplate: string + includeCRDs: bool + skipTests: bool + values: + valuesFiles: []string + valuesInline: map[string]interface{} + valuesMerge: string + ``` -| Field | Description | Example -| -----------: | ----------- | ----------- -`helmGlobals` | Parameters applied to all Helm charts -`helmCharts` | An array of helm chart parameters -`chartHome` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts -`configHome` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config -`name` | The name of the chart | minecraft -`version` | The version of the chart | 3.1.3 -`repo` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts -`releaseName` | Replaces RELEASE_NAME in the chart template output | test -`namespace` | Sets the target namespace for a release (`.Release.Namespace` in the template) | my-namespace -`valuesInline` | Values to use instead of default values that accompany the chart | global:
  enabled: false
tests:
  enabled: false -`valuesFile` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where `chartHome` and `name` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml -`valuesMerge` | ValuesMerge specifies how to treat ValuesInline with respect to Values. Legal values: 'merge', 'override' (default), 'replace'. | replace -`includeCRDs` | Specifies if Helm should also generate CustomResourceDefinitions. Defaults to false. | true - -The only required field is `name`. +| Field | Description | Example +| -----------: | ----------- | ----------- +`helmGlobals` | Parameters applied to all Helm charts +`helmCharts` | An array of helm chart parameters +`chartArgs` | Arguments that describe the chart being rendered. +`templateOptions` | A collection of fields that map to flag options of `helm template`. +`chartHome` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts +`configHome` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config +`name` | The name of the chart | minecraft +`version` | The version of the chart | 3.1.3 +`repo` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts +`releaseName` | Replaces RELEASE_NAME in the chart template output | test +`namespace` | Sets the target namespace for a release (`.Release.Namespace` in the template) | my-namespace +`nameTemplate` | Specify the template used to name the release | gatekeeper +`includeCRDs` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true" +`skipTests` | If set, skip tests from templated output. Legal values: "true", "false" (default). | "true" +`values` | Values to use instead of the default values that accompany the chart. This can be defined inline or in a file. +`valuesInline` | Values defined inline to use instead of default values that accompany the chart | global:
  enabled: false
tests:
  enabled: false +`valuesFiles` | Remote or local filepaths to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where `chartHome` and `name` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml +`valuesMerge` | ValuesMerge specifies how to treat ValuesInline with respect to ValuesFiles. Legal values: 'merge', 'override' (default), 'replace'. | replace diff --git a/functions/go/render-helm-chart/generated/docs.go b/functions/go/render-helm-chart/generated/docs.go index 753bcc6a6..fd02be991 100644 --- a/functions/go/render-helm-chart/generated/docs.go +++ b/functions/go/render-helm-chart/generated/docs.go @@ -28,6 +28,8 @@ There are 2 kinds of ` + "`" + `functionConfig` + "`" + ` supported by this func - ` + "`" + `ConfigMap` + "`" + ` - A custom resource of kind ` + "`" + `RenderHelmChart` + "`" + ` +Many of the fields in each functionConfig map directly to flag options provided by ` + "`" + `helm template` + "`" + `. + ` + "`" + `ConfigMap` + "`" + `: To use a ` + "`" + `ConfigMap` + "`" + ` as the ` + "`" + `functionConfig` + "`" + `, the desired parameters must be specified in the ` + "`" + `data` + "`" + ` field: @@ -40,24 +42,26 @@ specified in the ` + "`" + `data` + "`" + ` field: repo: string releaseName: string namespace: string - valuesFile: string + nameTemplate: string includeCRDs: string + skipTests: string + valuesFile: string -| Field | Description | Example -| -----------: | ----------- | ----------- -` + "`" + `chartHome` + "`" + ` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts -` + "`" + `configHome` + "`" + ` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config -` + "`" + `name` + "`" + ` | The name of the chart | minecraft -` + "`" + `version` + "`" + ` | The version of the chart | 3.1.3 -` + "`" + `repo` + "`" + ` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts -` + "`" + `releaseName` + "`" + ` | Replaces RELEASE_NAME in the chart template output | test -` + "`" + `namespace` + "`" + ` | Sets the target namespace for a release (` + "`" + `.Release.Namespace` + "`" + ` in the template) | my-namespace -` + "`" + `valuesFile` + "`" + ` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where ` + "`" + `chartHome` + "`" + ` and ` + "`" + `name` + "`" + ` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml -` + "`" + `includeCRDs` + "`" + ` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true" - +| Field | Description | Example +| -----------: | ----------- | ----------- +` + "`" + `chartHome` + "`" + ` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts +` + "`" + `configHome` + "`" + ` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config +` + "`" + `name` + "`" + ` | The name of the chart | minecraft +` + "`" + `version` + "`" + ` | The version of the chart | 3.1.3 +` + "`" + `repo` + "`" + ` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts +` + "`" + `releaseName` + "`" + ` | Replaces RELEASE_NAME in the chart template output | test +` + "`" + `namespace` + "`" + ` | Sets the target namespace for a release (` + "`" + `.Release.Namespace` + "`" + ` in the template) | my-namespace +` + "`" + `nameTemplate` + "`" + ` | Specify the template used to name the release | gatekeeper +` + "`" + `includeCRDs` + "`" + ` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true" +` + "`" + `skipTests` + "`" + ` | If set, skip tests from templated output. Legal values: "true", "false" (default). | "true" +` + "`" + `valuesFile` + "`" + ` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where ` + "`" + `chartHome` + "`" + ` and ` + "`" + `name` + "`" + ` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml -The only required field is ` + "`" + `name` + "`" + `. ` + "`" + `RenderHelmChart` + "`" + `: A ` + "`" + `functionConfig` + "`" + ` of kind ` + "`" + `RenderHelmChart` + "`" + ` has the following supported parameters: @@ -66,33 +70,43 @@ A ` + "`" + `functionConfig` + "`" + ` of kind ` + "`" + `RenderHelmChart` + "`" chartHome: string configHome: string helmCharts: - - name: string - version: string - repo: string - releaseName: string - namespace: string - valuesInline: map[string]interface{} - valuesFile: string - valuesMerge: string - includeCRDs: bool - -| Field | Description | Example -| -----------: | ----------- | ----------- -` + "`" + `helmGlobals` + "`" + ` | Parameters applied to all Helm charts -` + "`" + `helmCharts` + "`" + ` | An array of helm chart parameters -` + "`" + `chartHome` + "`" + ` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts -` + "`" + `configHome` + "`" + ` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config -` + "`" + `name` + "`" + ` | The name of the chart | minecraft -` + "`" + `version` + "`" + ` | The version of the chart | 3.1.3 -` + "`" + `repo` + "`" + ` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts -` + "`" + `releaseName` + "`" + ` | Replaces RELEASE_NAME in the chart template output | test -` + "`" + `namespace` + "`" + ` | Sets the target namespace for a release (` + "`" + `.Release.Namespace` + "`" + ` in the template) | my-namespace -` + "`" + `valuesInline` + "`" + ` | Values to use instead of default values that accompany the chart | global:
  enabled: false
tests:
  enabled: false -` + "`" + `valuesFile` + "`" + ` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where ` + "`" + `chartHome` + "`" + ` and ` + "`" + `name` + "`" + ` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml -` + "`" + `valuesMerge` + "`" + ` | ValuesMerge specifies how to treat ValuesInline with respect to Values. Legal values: 'merge', 'override' (default), 'replace'. | replace -` + "`" + `includeCRDs` + "`" + ` | Specifies if Helm should also generate CustomResourceDefinitions. Defaults to false. | true - -The only required field is ` + "`" + `name` + "`" + `. + - chartArgs: + name: string + version: string + repo: string + templateOptions: + apiVersions: []string + releaseName: string + namespace: string + nameTemplate: string + includeCRDs: bool + skipTests: bool + values: + valuesFiles: []string + valuesInline: map[string]interface{} + valuesMerge: string + + +| Field | Description | Example +| -----------: | ----------- | ----------- +` + "`" + `helmGlobals` + "`" + ` | Parameters applied to all Helm charts +` + "`" + `helmCharts` + "`" + ` | An array of helm chart parameters +` + "`" + `chartArgs` + "`" + ` | Arguments that describe the chart being rendered. +` + "`" + `templateOptions` + "`" + ` | A collection of fields that map to flag options of ` + "`" + `helm template` + "`" + `. +` + "`" + `chartHome` + "`" + ` | A filepath to a directory of charts. The function will look for the chart in this local directory before attempting to pull the chart from a specified repo. Defaults to "tmp/charts". When run in a container, this path MUST have the prefix "tmp/". | tmp/charts +` + "`" + `configHome` + "`" + ` | Defines a value that the function should pass to helm via the HELM_CONFIG_HOME environment variable. If omitted, {tmpDir}/helm is used, where {tmpDir} is some temporary directory created by the function for the benefit of helm. This option is not supported when running in a container. It is supported only in exec mode (e.g. with kustomize) | /tmp/helm/config +` + "`" + `name` + "`" + ` | The name of the chart | minecraft +` + "`" + `version` + "`" + ` | The version of the chart | 3.1.3 +` + "`" + `repo` + "`" + ` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts +` + "`" + `releaseName` + "`" + ` | Replaces RELEASE_NAME in the chart template output | test +` + "`" + `namespace` + "`" + ` | Sets the target namespace for a release (` + "`" + `.Release.Namespace` + "`" + ` in the template) | my-namespace +` + "`" + `nameTemplate` + "`" + ` | Specify the template used to name the release | gatekeeper +` + "`" + `includeCRDs` + "`" + ` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true" +` + "`" + `skipTests` + "`" + ` | If set, skip tests from templated output. Legal values: "true", "false" (default). | "true" +` + "`" + `values` + "`" + ` | Values to use instead of the default values that accompany the chart. This can be defined inline or in a file. +` + "`" + `valuesInline` + "`" + ` | Values defined inline to use instead of default values that accompany the chart | global:
  enabled: false
tests:
  enabled: false +` + "`" + `valuesFiles` + "`" + ` | Remote or local filepaths to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where ` + "`" + `chartHome` + "`" + ` and ` + "`" + `name` + "`" + ` are the parameters defined above. | Using a local values file: path/to/your/values.yaml

Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml +` + "`" + `valuesMerge` + "`" + ` | ValuesMerge specifies how to treat ValuesInline with respect to ValuesFiles. Legal values: 'merge', 'override' (default), 'replace'. | replace ` var RenderHelmChartExamples = ` To render a remote minecraft chart, you can run the following command: diff --git a/functions/go/render-helm-chart/main.go b/functions/go/render-helm-chart/main.go index a8cb53f4a..1d5d0dc90 100644 --- a/functions/go/render-helm-chart/main.go +++ b/functions/go/render-helm-chart/main.go @@ -80,7 +80,7 @@ func (f *helmChartInflatorFunction) Config(rn *kyaml.RNode) error { } switch kind { case fnConfigKind: - err = f.ConfigHelmArgs(nil, []byte(y)) + err = f.RenderHelmChartArgs([]byte(y)) if err != nil { return err } @@ -157,8 +157,7 @@ func (f *helmChartInflatorFunction) getKind(rn *kyaml.RNode) (string, error) { return meta.Kind, nil } -func (f *helmChartInflatorFunction) ConfigHelmArgs( - _ *resmap.PluginHelpers, c []byte) (err error) { +func (f *helmChartInflatorFunction) RenderHelmChartArgs(c []byte) (err error) { args := &builtins.HelmArgs{} if err = kyaml.Unmarshal(c, args); err != nil { return @@ -207,14 +206,19 @@ func (f *helmChartInflatorFunction) ConfigMapArgs( if val, ok := m["namespace"]; ok { p.Namespace = val } - if val, ok := m["valuesFile"]; ok { - p.ValuesFile = val - } if val, ok := m["includeCRDs"]; ok { if val == "true" { p.IncludeCRDs = true } } + if val, ok := m["skipTests"]; ok { + if val == "true" { + p.SkipTests = true + } + } + if val, ok := m["valuesFile"]; ok { + p.ValuesFiles = []string{val} + } if err := p.ValidateArgs(); err != nil { return err } diff --git a/functions/go/render-helm-chart/metadata.yaml b/functions/go/render-helm-chart/metadata.yaml index 96d40d755..d3776bac8 100644 --- a/functions/go/render-helm-chart/metadata.yaml +++ b/functions/go/render-helm-chart/metadata.yaml @@ -9,6 +9,7 @@ examplePackageURLs: - https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/render-helm-chart-crds - https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/render-helm-chart-remote-values-file - https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/render-helm-chart-kustomize-inline-values + - https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/render-helm-chart-kustomize-values-files emails: - kpt-team@google.com license: Apache-2.0 diff --git a/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/builtins/HelmChartInflationGenerator.go b/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/builtins/HelmChartInflationGenerator.go index 16bb38540..393ccf7cc 100644 --- a/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/builtins/HelmChartInflationGenerator.go +++ b/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/builtins/HelmChartInflationGenerator.go @@ -6,6 +6,8 @@ package builtins import ( "bytes" + "crypto/md5" + "encoding/hex" "fmt" "io/ioutil" "net/http" @@ -62,18 +64,14 @@ func (p *HelmChartInflationGeneratorPlugin) establishTmpDir() (err error) { } func (p *HelmChartInflationGeneratorPlugin) ValidateArgs() (err error) { - if p.Name == "" { - return fmt.Errorf("chart name cannot be empty") - } - // ChartHome might be written to by the function in a container, // so it must be under the `/tmp` directory if p.ChartHome == "" { p.ChartHome = "tmp/charts" } - if p.ValuesFile == "" { - p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml") + if len(p.ValuesFiles) == 0 { + p.ValuesFiles = append(p.ValuesFiles, filepath.Join(p.ChartHome, p.Name, "values.yaml")) } if err = p.errIfIllegalValuesMerge(); err != nil { @@ -135,12 +133,40 @@ func (p *HelmChartInflationGeneratorPlugin) runHelmCommand( return stdout.Bytes(), err } -// createNewMergedValuesFile replaces/merges original values file with ValuesInline. -func (p *HelmChartInflationGeneratorPlugin) createNewMergedValuesFile() ( - path string, err error) { +// createNewMergedValuesFiles replaces/merges original values file with ValuesInline. +func (p *HelmChartInflationGeneratorPlugin) createNewMergedValuesFiles(path string) ( + string, error) { + pValues, err := ioutil.ReadFile(path) + if err != nil { + if u, urlErr := url.Parse(path); urlErr == nil { + if (u.Scheme == "http" || u.Scheme == "https") { + resp, err := http.Get(path) + if err != nil { + return "", err + } + defer resp.Body.Close() + pValues, err = ioutil.ReadAll(resp.Body) + if err != nil { + return "", err + } + } else { // url scheme is not http or https + return "", fmt.Errorf("unsupported URL scheme: %s", path) + } + } else { // invalid path and invalid URL + return "", fmt.Errorf( + "could not read provided values file %q: when reading as file path, received error %v; when reading as URL, received error %v", + path, err, urlErr) + } + } else { + // we want to pass in the absolute path into writeValuesBytes + path, err = filepath.Abs(path) + if err != nil { + return "", err + } + } if p.ValuesMerge == valuesMergeOptionMerge || p.ValuesMerge == valuesMergeOptionOverride { - if err = p.replaceValuesInline(); err != nil { + if err = p.replaceValuesInline(pValues); err != nil { return "", err } } @@ -149,14 +175,11 @@ func (p *HelmChartInflationGeneratorPlugin) createNewMergedValuesFile() ( if err != nil { return "", err } - return p.writeValuesBytes(b) + return p.writeValuesBytes(b, path) } -func (p *HelmChartInflationGeneratorPlugin) replaceValuesInline() error { - pValues, err := ioutil.ReadFile(p.ValuesFile) - if err != nil { - return err - } +func (p *HelmChartInflationGeneratorPlugin) replaceValuesInline(pValues []byte) error { + var err error chValues := make(map[string]interface{}) if err = yaml.Unmarshal(pValues, &chValues); err != nil { return err @@ -172,39 +195,16 @@ func (p *HelmChartInflationGeneratorPlugin) replaceValuesInline() error { return err } -// copyValuesFile to avoid branching. TODO: get rid of this. -func (p *HelmChartInflationGeneratorPlugin) copyValuesFile() (string, error) { - var b []byte - var err error - b, err = ioutil.ReadFile(p.ValuesFile) - if err != nil { - path := p.ValuesFile - if u, err := url.Parse(path); err == nil && (u.Scheme == "http" || u.Scheme == "https") { - var hc *http.Client - hc = &http.Client{} - - resp, err := hc.Get(path) - if err != nil { - return "", err - } - defer resp.Body.Close() - b, err = ioutil.ReadAll(resp.Body) - if err != nil { - return "", err - } - } - } - return p.writeValuesBytes(b) -} - // Write a absolute path file in the tmp file system. func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes( - b []byte) (string, error) { + b []byte, path string) (string, error) { if err := p.establishTmpDir(); err != nil { return "", fmt.Errorf("cannot create tmp dir to write helm values") } - path := filepath.Join(p.tmpDir, p.Name+"-kustomize-values.yaml") - return path, ioutil.WriteFile(path, b, 0644) + // use a hash of the provided path to generate a unique, valid filename + hash := md5.Sum([]byte(path)) + newPath := filepath.Join(p.tmpDir, p.Name+"-kustomize-values-"+hex.EncodeToString(hash[:])+".yaml") + return newPath, ioutil.WriteFile(newPath, b, 0644) } func (p *HelmChartInflationGeneratorPlugin) cleanup() { @@ -218,23 +218,21 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er if err = p.checkHelmVersion(); err != nil { return nil, err } - if path, exists := p.chartExistsLocally(); !exists { - if p.Repo == "" { - return nil, fmt.Errorf( - "no repo specified for pull, no chart found at '%s'", path) - } + if _, exists := p.chartExistsLocally(); !exists { if _, err := p.runHelmCommand(p.pullCommand()); err != nil { return nil, err } } - if len(p.ValuesInline) > 0 { - p.ValuesFile, err = p.createNewMergedValuesFile() - } else { - p.ValuesFile, err = p.copyValuesFile() - } - if err != nil { - return nil, err + var valuesFiles []string + for _, valuesFile := range p.ValuesFiles { + file, err := p.createNewMergedValuesFiles(valuesFile) + if err != nil { + return nil, err + } + valuesFiles = append(valuesFiles, file) } + p.ValuesFiles = valuesFiles + var stdout []byte stdout, err = p.runHelmCommand(p.templateCommand()) if err != nil { @@ -263,9 +261,17 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string { if p.Namespace != "" { args = append(args, "--namespace", p.Namespace) } - args = append(args, filepath.Join(p.absChartHome(), p.Name)) - if p.ValuesFile != "" { - args = append(args, "--values", p.ValuesFile) + if p.NameTemplate != "" { + args = append(args, "--name-template", p.NameTemplate) + } + if p.Name != "" { + args = append(args, filepath.Join(p.absChartHome(), p.Name)) + } + for _, valuesFile := range p.ValuesFiles { + args = append(args, "-f", valuesFile) + } + for _, apiVer := range p.ApiVersions { + args = append(args, "--api-versions", apiVer) } if p.ReleaseName == "" { // AFAICT, this doesn't work as intended due to a bug in helm. @@ -273,9 +279,15 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string { // I've tried placing the flag before and after the name argument. args = append(args, "--generate-name") } + if p.Description != "" { + args = append(args, "--description", p.Description) + } if p.IncludeCRDs { args = append(args, "--include-crds") } + if p.SkipTests { + args = append(args, "--skip-tests") + } return args } @@ -283,9 +295,13 @@ func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string { args := []string{ "pull", "--untar", - "--untardir", p.absChartHome(), - "--repo", p.Repo, - p.Name} + "--untardir", p.absChartHome()} + if p.Repo != "" { + args = append(args, "--repo", p.Repo) + } + if p.Name != "" { + args = append(args, p.Name) + } if p.Version != "" { args = append(args, "--version", p.Version) } diff --git a/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/types/helmchartargs.go b/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/types/helmchartargs.go index 14520d5c1..81aba35cb 100644 --- a/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/types/helmchartargs.go +++ b/functions/go/render-helm-chart/third_party/sigs.k8s.io/kustomize/api/types/helmchartargs.go @@ -29,6 +29,16 @@ type HelmGlobals struct { } type HelmChart struct { + // ChartArgs encapsulates information about the chart being inflated, including + // the chart's name, version, and repo. + ChartArgs `json:"chartArgs,omitempty" yaml:"chartArgs,omitempty"` + + // TemplateOptions are fields that become flags to `helm template` when + // the helm chart is being rendered. + TemplateOptions `json:"templateOptions,omitempty" yaml:"templateOptions,omitempty"` +} + +type ChartArgs struct { // Name is the name of the chart, e.g. 'minecraft'. Name string `json:"name,omitempty" yaml:"name,omitempty"` @@ -39,6 +49,11 @@ type HelmChart struct { // This is the argument to helm's `--repo` flag, e.g. // `https://itzg.github.io/minecraft-server-charts`. Repo string `json:"repo,omitempty" yaml:"repo,omitempty"` +} + +type TemplateOptions struct { + // ApiVersions is the kubernetes apiversions used for Capabilities.APIVersions + ApiVersions []string `json:"apiVerions,omitempty" yaml:"apiVersions,omitempty"` // ReleaseName replaces RELEASE-NAME in chart template output, // making a particular inflation of a chart unique with respect to @@ -53,10 +68,28 @@ type HelmChart struct { // in the helm template Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` - // ValuesFile is local file path to a values file to use _instead of_ + // Description is a custom description to add when rendering the helm chart. + Description string `json:"description,omitempty" yaml:"description,omitempty"` + + // NameTemplate is for specifying the name template used to name the release. + NameTemplate string `json:"nameTemplate,omitempty" yaml:"nameTemplate,omitempty"` + + // IncludeCRDs specifies if Helm should also generate CustomResourceDefinitions. + // Defaults to false. + IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` + + // SkipTests skips tests from templated output. + SkipTests bool `json:"skipTests,omitempty" yaml:"skipTests,omitempty"` + + // Values are values that are specified inline or in a yaml file to use. + Values `json:"values,omitempty" yaml:"values,omitempty"` +} + +type Values struct { + // ValuesFiles is a list of local file paths to values files to use instead of // the default values that accompanied the chart. // The default values are in '{ChartHome}/{Name}/values.yaml'. - ValuesFile string `json:"valuesFile,omitempty" yaml:"valuesFile,omitempty"` + ValuesFiles []string `json:"valuesFiles,omitempty" yaml:"valuesFiles,omitempty"` // ValuesInline holds value mappings specified directly, // rather than in a separate file. @@ -66,55 +99,4 @@ type HelmChart struct { // Legal values: 'merge', 'override', 'replace'. // Defaults to 'override'. ValuesMerge string `json:"valuesMerge,omitempty" yaml:"valuesMerge,omitempty"` - - // IncludeCRDs specifies if Helm should also generate CustomResourceDefinitions. - // Defaults to false. - IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` -} - -// HelmChartArgs contains arguments to helm. -// Deprecated. Use HelmGlobals and HelmChart instead. -type HelmChartArgs struct { - ChartName string `json:"chartName,omitempty" yaml:"chartName,omitempty"` - ChartVersion string `json:"chartVersion,omitempty" yaml:"chartVersion,omitempty"` - ChartRepoURL string `json:"chartRepoUrl,omitempty" yaml:"chartRepoUrl,omitempty"` - ChartHome string `json:"chartHome,omitempty" yaml:"chartHome,omitempty"` - ChartRepoName string `json:"chartRepoName,omitempty" yaml:"chartRepoName,omitempty"` - HelmBin string `json:"helmBin,omitempty" yaml:"helmBin,omitempty"` - HelmHome string `json:"helmHome,omitempty" yaml:"helmHome,omitempty"` - Values string `json:"values,omitempty" yaml:"values,omitempty"` - ValuesLocal map[string]interface{} `json:"valuesLocal,omitempty" yaml:"valuesLocal,omitempty"` - ValuesMerge string `json:"valuesMerge,omitempty" yaml:"valuesMerge,omitempty"` - ReleaseName string `json:"releaseName,omitempty" yaml:"releaseName,omitempty"` - ReleaseNamespace string `json:"releaseNamespace,omitempty" yaml:"releaseNamespace,omitempty"` - ExtraArgs []string `json:"extraArgs,omitempty" yaml:"extraArgs,omitempty"` -} - -// SplitHelmParameters splits helm parameters into -// per-chart params and global chart-independent parameters. -func SplitHelmParameters( - oldArgs []HelmChartArgs) (charts []HelmChart, globals HelmGlobals) { - for _, old := range oldArgs { - charts = append(charts, makeHelmChartFromHca(&old)) - if old.HelmHome != "" { - // last non-empty wins - globals.ConfigHome = old.HelmHome - } - if old.ChartHome != "" { - // last non-empty wins - globals.ChartHome = old.ChartHome - } - } - return charts, globals -} - -func makeHelmChartFromHca(old *HelmChartArgs) (c HelmChart) { - c.Name = old.ChartName - c.Version = old.ChartVersion - c.Repo = old.ChartRepoURL - c.ValuesFile = old.Values - c.ValuesInline = old.ValuesLocal - c.ValuesMerge = old.ValuesMerge - c.ReleaseName = old.ReleaseName - return }