-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubernetes actions task in
kubectl
The task `kubectl-actions` is a generic task which can be used to perform k8s-actions. We take the whole script as a `params` whereas the existing task `kubectl-deploy` only works for deploying the pod and fulfills the specific criteria. Signed-off-by: vinamra28 <[email protected]>
- Loading branch information
Showing
6 changed files
with
212 additions
and
51 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
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,18 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: TaskRun | ||
metadata: | ||
name: kubectl-run | ||
spec: | ||
taskRef: | ||
name: kubectl-actions | ||
params: | ||
- name: script | ||
value: | | ||
kubectl get pods | ||
echo "---------" | ||
kubectl get deploy | ||
workspaces: | ||
- name: kubeconfig-dir | ||
emptyDir: {} | ||
- name: manifest-dir | ||
emptyDir: {} |
File renamed without changes.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: TaskRun | ||
metadata: | ||
|
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,26 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: update-deployment-image | ||
spec: | ||
params: | ||
- name: BASE_IMAGE | ||
default: gcr.io/cloud-builders/kubectl | ||
description: The base image for the task. | ||
type: string | ||
- name: REPLACEMENT_IMAGE | ||
description: The name of the image that needs to be replaced. | ||
type: string | ||
- name: DEPLOYMENT_NAME | ||
description: The name of the deployment in which image needs to be replaced. | ||
type: string | ||
steps: | ||
- name: patch-image | ||
image: $(params.BASE_IMAGE) | ||
script: | | ||
kubectl patch deployment $(params.DEPLOYMENT_NAME) --patch='{"spec":{"template":{"spec":{ | ||
"containers":[{ | ||
"name": "$(params.DEPLOYMENT_NAME)", | ||
"image":"$(params.REPLACEMENT_IMAGE)" | ||
}] | ||
}}}}' |
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,36 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: kubectl-actions | ||
spec: | ||
workspaces: | ||
- name: manifest-dir | ||
- name: kubeconfig-dir | ||
params: | ||
- name: script | ||
description: The Kubernetes CLI script to run | ||
type: string | ||
default: "kubectl $@" | ||
- name: args | ||
description: The Kubernetes CLI arguments to run | ||
type: array | ||
default: | ||
- "help" | ||
- name: image | ||
default: gcr.io/cloud-builders/kubectl #image is huge | ||
description: Kubectl wrapper image | ||
steps: | ||
- name: kubectl | ||
image: $(params.image) | ||
workingDir: $(workspaces.manifest-dir.path) | ||
script: | | ||
#!/usr/bin/env bash | ||
if [[ -f $(workspaces.kubeconfig-dir.path)/kubeconfig ]]; then | ||
export KUBECONFIG=$(workspaces.kubeconfig-dir.path)/kubeconfig | ||
fi | ||
$(params.script) | ||
args: | ||
- "$(params.args)" |