Skip to content

Commit

Permalink
OPC task working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
Senjuti256 authored and openshift-merge-bot[bot] committed Mar 19, 2024
1 parent 6b4fa1b commit 126a070
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ E2E_OPENSHIFT_PARAMS_SCRIPT ?= oc version

E2E_TKN_PARAMS_SCRIPT ?= tkn version

E2E_OPC_PARAMS_SCRIPT ?= opc version

E2E_KN_PARAMS_ARGS ?= help

E2E_KN_APPLY_PARAMS_SERVICE ?= hello
Expand Down Expand Up @@ -109,6 +111,10 @@ test-e2e-openshift: test-e2e
test-e2e-tkn: prepare-e2e-openshift
test-e2e-tkn: test-e2e

.PHONY: test-e2e-opc
test-e2e-opc: prepare-e2e-openshift
test-e2e-opc: test-e2e

# act runs the github actions workflows, so by default only running the test workflow (integration
# and end-to-end) to avoid running the release workflow accidently
act: ARGS = --workflows=./.github/workflows/test.yaml
Expand Down
13 changes: 13 additions & 0 deletions scripts/opc-client.sh
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}
15 changes: 15 additions & 0 deletions scripts/opc-common.sh
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 \

63 changes: 63 additions & 0 deletions templates/task-opc.yaml
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: {}
43 changes: 43 additions & 0 deletions test/e2e/opc-e2e.bats
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"
}
34 changes: 34 additions & 0 deletions test/e2e/resources/opc-pipeline.yaml
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)"


13 changes: 13 additions & 0 deletions test/e2e/resources/opc-pvc.yaml
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
1 change: 1 addition & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ images:
openshiftCli: registry.redhat.io/openshift4/ose-cli@sha256:3d5b31cc3fbf878015e5c3ed1d48379d74b15b77a1a823024a7a2b7cd5e2e86d
tkn: registry.redhat.io/openshift-pipelines/pipelines-cli-tkn-rhel8@sha256:72394dfaed68c4b6b490c3c971fb1d9f0139f8656f6672b55b8e02ea98d1298d
kn: registry.redhat.io/openshift-serverless-1/client-kn-rhel8:1.9.2-4
opc: quay.io/redhat-user-workloads/tekton-ecosystem-tenant/ecosystem-images/opc-ecosystem-images@sha256:97ba3f5cb6d20609de1133ea6e176884f103222b59fa8155190d3b95e7f5f43a

annotations:
tekton.dev/pipelines.minVersion: "0.17.0"
Expand Down

0 comments on commit 126a070

Please sign in to comment.