1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-24 06:15:46 +00:00

Copy task tkn from 0.3 to 0.4

This commit is contained in:
Shubham 2022-08-04 13:40:00 +05:30 committed by tekton-robot
parent 5154298489
commit 20d11165b9
7 changed files with 217 additions and 0 deletions

74
task/tkn/0.4/README.md Normal file
View File

@ -0,0 +1,74 @@
# tkn
This task performs operations on Tekton resources using
[`tkn`](https://github.com/tektoncd/cli).
## Install the Task
```bash
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/tkn/0.3/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/main/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`.
## Platforms
The Task can be run on `linux/amd64`, `linux/s390x` and `linux/ppc64le` platforms.
## 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/main/task/tkn/0.3/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
```

View File

@ -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

View File

@ -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

View File

@ -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=

View File

@ -0,0 +1,30 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: tkn-account
namespace: tkn-0-3
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tkn-role
namespace: tkn-0-3
rules:
- apiGroups: ["tekton.dev"]
resources: ["*"]
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: tkn-binding
namespace: tkn-0-3
subjects:
- kind: ServiceAccount
name: tkn-account
namespace: tkn-0-3
roleRef:
kind: Role
name: tkn-role
apiGroup: rbac.authorization.k8s.io

View File

@ -0,0 +1,14 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: tkn-run-without-workspace
spec:
serviceAccountName: tkn-account
taskRef:
name: tkn
params:
- name: SCRIPT
value: |
tkn task list
echo "-----------"
tkn task describe tkn

46
task/tkn/0.4/tkn.yaml Normal file
View File

@ -0,0 +1,46 @@
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: tkn
labels:
app.kubernetes.io/version: "0.3"
annotations:
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/categories: CLI
tekton.dev/tags: cli
tekton.dev/displayName: "Tekton CLI"
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
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:d17fec04f655551464a47dd59553c9b44cf660cc72dbcdbd52c0b8e8668c0579
- 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)"]