-
Notifications
You must be signed in to change notification settings - Fork 5
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
4cc47a1
commit bf3838e
Showing
8 changed files
with
190 additions
and
1 deletion.
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,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
shopt -s inherit_errexit | ||
set -eu -o pipefail | ||
|
||
source "$(dirname ${BASH_SOURCE[0]})/common.sh" | ||
source "$(dirname ${BASH_SOURCE[0]})/tkn-common.sh" | ||
|
||
[[ "${WORKSPACES_KUBECONFIG_DIR_BOUND}" == "true" ]] && \ | ||
[[ -f ${WORKSPACES_KUBECONFIG_DIR_PATH}/kubeconfig ]] && \ | ||
export KUBECONFIG=${WORKSPACES_KUBECONFIG_DIR_PATH}/kubeconfig | ||
|
||
${PARAMS_SCRIPT} |
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,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
declare -rx PARAMS_SCRIPT="${PARAMS_SCRIPT:-}" | ||
|
||
declare -rx WORKSPACES_KUBECONFIG_DIR_PATH="${WORKSPACES_KUBECONFIG_DIR_PATH:-}" | ||
declare -rx WORKSPACES_KUBECONFIG_DIR_BOUND="${WORKSPACES_KUBECONFIG_DIR_BOUND:-}" | ||
|
||
# | ||
# Asserting Environment | ||
# | ||
|
||
exported_or_fail \ | ||
WORKSPACES_KUBECONFIG_DIR_BOUND \ | ||
PARAMS_SCRIPT \ | ||
|
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,63 @@ | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: tkn | ||
labels: | ||
app.kubernetes.io/version: {{ .Chart.Version }} | ||
{{- if .Values.annotations }} | ||
annotations: | ||
{{- .Values.annotations | toYaml | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
description: >- | ||
This task performs operations on Tekton resources using tkn. | ||
workspaces: | ||
- name: kubeconfig_dir | ||
optional: true | ||
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. | ||
params: | ||
- name: SCRIPT | ||
description: tkn CLI script to execute | ||
type: string | ||
default: "tkn $@" | ||
- name: ARGS | ||
type: array | ||
description: tkn CLI arguments to run | ||
default: ["--help"] | ||
|
||
stepTemplate: | ||
env: | ||
{{- $variables := list | ||
"params.SCRIPT" | ||
"workspaces.kubeconfig_dir.bound" | ||
"workspaces.kubeconfig_dir.path" | ||
}} | ||
{{- include "environment" ( list $variables ) | nindent 6 }} | ||
|
||
steps: | ||
{{- include "load_scripts" ( list . "tkn-" ) | nindent 4 }} | ||
|
||
- name: tkn | ||
image: {{ .Values.images.tkn }} | ||
env: | ||
- name: HOME | ||
value: /tekton/home | ||
command: | ||
- /scripts/tkn-client.sh | ||
args: ["$(params.ARGS)"] | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 65532 | ||
volumeMounts: | ||
- name: scripts-dir | ||
mountPath: /scripts | ||
|
||
volumes: | ||
- name: scripts-dir | ||
emptyDir: {} |
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,34 @@ | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
labels: | ||
name: task-tkn | ||
name: task-tkn | ||
spec: | ||
workspaces: | ||
- name: kubeconfig_dir | ||
optional: true | ||
|
||
params: | ||
- name: SCRIPT | ||
type: string | ||
default: "tkn $@" | ||
- name: ARGS | ||
type: array | ||
default: ["--help"] | ||
|
||
tasks: | ||
- name: task-tkn | ||
taskRef: | ||
name: task-tkn | ||
workspaces: | ||
- name: kubeconfig_dir | ||
workspace: kubeconfig_dir | ||
params: | ||
- name: SCRIPT | ||
value: "$(params.SCRIPT)" | ||
- name: ARGS | ||
value: "$(params.ARGS)" | ||
|
||
|
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,13 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
labels: | ||
name: task-tkn | ||
name: task-tkn | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 250Mi |
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,43 @@ | ||
#!/usr/bin/env bats | ||
|
||
source ./test/helper/helper.sh | ||
|
||
# E2E tests parameters for the test pipeline | ||
|
||
# Testing the tkn task, | ||
@test "[e2e] tkn task" { | ||
[ -n "${E2E_TKN_PARAMS_SCRIPT}" ] | ||
|
||
run kubectl delete taskrun --all | ||
assert_success | ||
|
||
run tkn task start tkn \ | ||
--param="SCRIPT=${E2E_TKN_PARAMS_SCRIPT}" \ | ||
--use-param-defaults \ | ||
--skip-optional-workspace \ | ||
--showlog >&3 | ||
assert_success | ||
|
||
# waiting a few seconds before asserting results | ||
sleep 15 | ||
|
||
# assering the taskrun status, making sure all steps have been successful | ||
declare tmpl_file="${BASE_DIR}/go-template.tpl" | ||
# the following template is able to extract information from TaskRun and PipelineRun resources, | ||
# and as well supports the current Tekton Pipeline version using a different `.task.results` | ||
# attribute | ||
cat >${tmpl_file} <<EOS | ||
{{- range .status.conditions }} | ||
{{- if and (eq .type "Succeeded") (eq .status "True") }} | ||
{{- printf "%s\n" .message -}} | ||
{{- end -}} | ||
{{- end }} | ||
{{- range .status.results }} | ||
{{- printf "%s=%s\n" .name .value -}} | ||
{{- end -}} | ||
EOS | ||
|
||
run tkn taskrun describe --last --output=go-template-file --template=${tmpl_file} | ||
assert_success | ||
assert_output "All Steps have completed executing" | ||
} |
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