diff --git a/task/helm-upgrade-from-repo/0.4/README.md b/task/helm-upgrade-from-repo/0.4/README.md new file mode 100644 index 0000000000..f6fd255da4 --- /dev/null +++ b/task/helm-upgrade-from-repo/0.4/README.md @@ -0,0 +1,67 @@ +# Helm + +These tasks will install / upgrade a helm chart into your Kubernetes / OpenShift Cluster using [Helm](https://github.com/helm/helm). + +## Install the Task + +Install `helm-upgrade-from-repo` task: + +``` +kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/helm-upgrade-from-repo/0.4/raw +``` + +#### Workspaces + +* **source**: A [Workspace](https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md) volume containing the helm chart. + +### helm install / upgrade from repo + +``` +kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/helm-upgrade-from-repo/0.4/raw +``` + +#### Parameters + +- **chart_name**: The directory in the source repository where the installable chart should be found. +- **release_version**: The version of the release (*default: v1.0.0*) +- **release_name**: The name of the release (*default: helm-release*) +- **release_namespace**: The namespace in which the release is to be installed (*default: ""*) +- **overwrite_values**: The values to be overwritten (*default: ""*) +- **helm_image**: The helm image which should be used (default: lachlanevenson/k8s-helm:v3.5.0) +- **upgrade_extra_params**: Extra parameters passed for the helm upgrade command (*default: ""*) + +#### Platforms + +The Task can be run on `linux/amd64`, `linux/s390x`, `linux/arm64` and `linux/ppc64le` platforms. + +## Usage + +### PipelineRun + +An example `Pipeline` with a `PipelineRun` can be found in the subdirectory `tests`. + +### TaskRun + +This `TaskRun` runs the task to retrieve a Git repo and then installs/updates the helm chart that is in the Git repo. + +```yaml +# example upgrade from repo +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + name: example-helm-upgrade-from-repo +spec: + taskRef: + name: helm-upgrade-from-repo + params: + - name: helm_repo + value: https://kubernetes-charts.storage.googleapis.com + - name: chart_name + value: stable/envoy + - name: release_version + value: v1.0.0 + - name: release_name + value: helm-repo-sample + - name: overwrite_values + value: autoscaling.enabled=true,autoscaling.maxReplicas=3 +``` diff --git a/task/helm-upgrade-from-repo/0.4/helm-upgrade-from-repo.yaml b/task/helm-upgrade-from-repo/0.4/helm-upgrade-from-repo.yaml new file mode 100644 index 0000000000..26c13bf3aa --- /dev/null +++ b/task/helm-upgrade-from-repo/0.4/helm-upgrade-from-repo.yaml @@ -0,0 +1,54 @@ +# This Task will do a helm upgrade based on the given helm repo and chart +apiVersion: tekton.dev/v1 +kind: Task +metadata: + name: helm-upgrade-from-repo + labels: + app.kubernetes.io/version: "0.4" + annotations: + tekton.dev/categories: Deployment + tekton.dev/pipelines.minVersion: "1.4.0" + tekton.dev/tags: helm + tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le,linux/arm64" +spec: + description: >- + These tasks will install / upgrade a helm chart into your Kubernetes / + OpenShift Cluster using Helm + + params: + - name: helm_repo + description: "Specify a specific helm repo" + - name: chart_name + description: "Specify chart name that will be deployed" + - name: release_version + description: The helm release version in semantic versioning format + default: "v1.0.0" + - name: release_name + description: The helm release name + default: "helm-release" + - name: release_namespace + description: The helm release namespace + default: "" + - name: overwrite_values + description: "Specify the values you want to overwrite, comma separated: autoscaling.enabled=true,replicas=1" + default: "" + - name: helm_image + description: "Specify a specific helm image" + default: "docker.io/lachlanevenson/k8s-helm@sha256:0a068ae407e21d1836c6a89a1e9e81af1e55fa56890998e33d5caabdbb51e77b" # tag: v3.10.2 + - name: upgrade_extra_params + description: "Extra parameters passed for the helm upgrade command" + default: "" + steps: + - name: upgrade-from-repo + image: $(params.helm_image) + script: | + echo current installed helm releases + helm list --namespace "$(params.release_namespace)" + echo parsing helms repo name... + REPO=`echo "$(params.chart_name)" | cut -d "/" -f 1` + echo adding helm repo... + helm repo add $REPO "$(params.helm_repo)" + echo adding updating repo... + helm repo update + echo installing helm chart... + helm upgrade --wait --install --namespace "$(params.release_namespace)" $(params.release_name) $(params.chart_name) --debug --set "$(params.overwrite_values)" $(params.upgrade_extra_params) diff --git a/task/helm-upgrade-from-repo/0.4/samples/helm-upgrade-from-repo-task-run.yaml.tmpl b/task/helm-upgrade-from-repo/0.4/samples/helm-upgrade-from-repo-task-run.yaml.tmpl new file mode 100644 index 0000000000..fc2824ec96 --- /dev/null +++ b/task/helm-upgrade-from-repo/0.4/samples/helm-upgrade-from-repo-task-run.yaml.tmpl @@ -0,0 +1,18 @@ +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + name: example-helm-upgrade-from-repo +spec: + taskRef: + name: helm-upgrade-from-repo + params: + - name: helm_repo + value: https://charts.helm.sh/stable + - name: chart_name + value: stable/envoy + - name: release_version + value: v1.0.0 + - name: release_name + value: helm-repo-sample + - name: overwrite_values + value: autoscaling.enabled=true,autoscaling.maxReplicas=3 \ No newline at end of file diff --git a/task/helm-upgrade-from-repo/0.4/tests/pre-apply-task-hook.sh b/task/helm-upgrade-from-repo/0.4/tests/pre-apply-task-hook.sh new file mode 100755 index 0000000000..4bb7ad3104 --- /dev/null +++ b/task/helm-upgrade-from-repo/0.4/tests/pre-apply-task-hook.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Add service account +kubectl -n ${tns} create serviceaccount helm-pipeline-run-sa + +# Add edit role to service account +kubectl -n ${tns} create rolebinding helm-pipeline-run-sa-edit --clusterrole edit --serviceaccount ${tns}:helm-pipeline-run-sa -o yaml --dry-run=client | kubectl apply -f - diff --git a/task/helm-upgrade-from-repo/0.4/tests/run.yaml b/task/helm-upgrade-from-repo/0.4/tests/run.yaml new file mode 100644 index 0000000000..84d75ab8d8 --- /dev/null +++ b/task/helm-upgrade-from-repo/0.4/tests/run.yaml @@ -0,0 +1,32 @@ +--- +apiVersion: tekton.dev/v1 +kind: Pipeline +metadata: + name: helm-upgrade-test-pipeline +spec: + tasks: + - name: helm-upgrade-from-repo + taskRef: + name: helm-upgrade-from-repo + params: + - name: helm_repo + value: https://dunefro.github.io/sample-charts/ + - name: chart_name + value: sample-charts/sample-nginx + - name: release_version + value: v1.0.0 + - name: release_name + value: helm-repo-sample + - name: overwrite_values + value: autoscaling.enabled=false,autoscaling.maxReplicas=3 + - name: upgrade_extra_params + value: "--force" +--- +apiVersion: tekton.dev/v1 +kind: PipelineRun +metadata: + name: helm-upgrade-test-pipeline-run +spec: + serviceAccountName: helm-pipeline-run-sa + pipelineRef: + name: helm-upgrade-test-pipeline