-
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
6b4fa1b
commit 126a070
Showing
8 changed files
with
188 additions
and
0 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,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]})/opc-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/v1 | ||
kind: Task | ||
metadata: | ||
name: opc | ||
labels: | ||
app.kubernetes.io/version: {{ .Chart.Version }} | ||
{{- if .Values.annotations }} | ||
annotations: | ||
{{- .Values.annotations | toYaml | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
description: >- | ||
The opc task makes it easy to work with Tekton resources in OpenShift Pipelines. | ||
workspaces: | ||
- name: kubeconfig_dir | ||
optional: true | ||
description: >- | ||
An optional workspace that allows you to provide a .kube/config | ||
file for opc to access the cluster. The file should be placed at | ||
the root of the Workspace with name kubeconfig. | ||
params: | ||
- name: SCRIPT | ||
description: opc CLI script to execute | ||
type: string | ||
default: "opc $@" | ||
- name: ARGS | ||
type: array | ||
description: opc 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 . "opc-" ) | nindent 4 }} | ||
|
||
- name: opc | ||
image: {{ .Values.images.opc }} | ||
env: | ||
- name: HOME | ||
value: /tekton/home | ||
command: | ||
- /scripts/opc-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,43 @@ | ||
#!/usr/bin/env bats | ||
|
||
source ./test/helper/helper.sh | ||
|
||
# E2E tests parameters for the test pipeline | ||
|
||
# Testing the tkn task, | ||
@test "[e2e] opc task" { | ||
[ -n "${E2E_OPC_PARAMS_SCRIPT}" ] | ||
|
||
run kubectl delete taskrun --all | ||
assert_success | ||
|
||
run tkn task start opc \ | ||
--param="SCRIPT=${E2E_OPC_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Pipeline | ||
metadata: | ||
labels: | ||
name: task-opc | ||
name: task-opc | ||
spec: | ||
workspaces: | ||
- name: kubeconfig_dir | ||
optional: true | ||
|
||
params: | ||
- name: SCRIPT | ||
type: string | ||
default: "opc $@" | ||
- name: ARGS | ||
type: array | ||
default: ["--help"] | ||
|
||
tasks: | ||
- name: task-opc | ||
taskRef: | ||
name: task-opc | ||
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-opc | ||
name: task-opc | ||
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