-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad7a16b
commit f177db3
Showing
11 changed files
with
523 additions
and
214 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
133 changes: 133 additions & 0 deletions
133
examples/render-helm-chart-kustomize-values-files/.expected/diff.patch
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,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 |
4 changes: 4 additions & 0 deletions
4
examples/render-helm-chart-kustomize-values-files/.expected/exec.sh
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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# kustomize 4.2.0 is preinstalled in github actions | ||
kustomize build --enable-alpha-plugins --network > resources.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 @@ | ||
.expected |
81 changes: 81 additions & 0 deletions
81
examples/render-helm-chart-kustomize-values-files/README.md
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,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. |
23 changes: 23 additions & 0 deletions
23
examples/render-helm-chart-kustomize-values-files/kustomization.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,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 |
Oops, something went wrong.