Skip to content

Commit

Permalink
render-helm-chart function changes
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jan 25, 2022
1 parent ad7a16b commit f177db3
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["*"]
133 changes: 133 additions & 0 deletions examples/render-helm-chart-kustomize-values-files/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
81 changes: 81 additions & 0 deletions examples/render-helm-chart-kustomize-values-files/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f177db3

Please sign in to comment.