diff --git a/task/eaas-provision-space/0.1/README.md b/task/eaas-provision-space/0.1/README.md new file mode 100644 index 0000000000..ec32e9bade --- /dev/null +++ b/task/eaas-provision-space/0.1/README.md @@ -0,0 +1,16 @@ +# eaas-provision-space task + +Provisions an ephemeral namespace on an EaaS cluster using a SpaceRequest. This namespace can then be used to provision other ephemeral environments for testing. + +## Parameters +|name|description|default value|required| +|---|---|---|---| +|ownerKind|The type of resource that should own the generated SpaceRequest. Deletion of this resource will trigger deletion of the SpaceRequest. Supported values: `PipelineRun`, `TaskRun`.|PipelineRun|false| +|ownerName|The name of the resource that should own the generated SpaceRequest. This should either be passed the value of `$(context.pipelineRun.name)` or `$(context.taskRun.name)` depending on the value of `ownerKind`.||true| +|ownerUid|The uid of the resource that should own the generated SpaceRequest. This should either be passed the value of `$(context.pipelineRun.uid)` or `$(context.taskRun.uid)` depending on the value of `ownerKind`.||true| + +## Results +|name|description| +|---|---| +|secretRef|Name of a Secret containing a kubeconfig used to access the provisioned space.| + diff --git a/task/eaas-provision-space/0.1/eaas-provision-space.yaml b/task/eaas-provision-space/0.1/eaas-provision-space.yaml new file mode 100644 index 0000000000..ddce52f10b --- /dev/null +++ b/task/eaas-provision-space/0.1/eaas-provision-space.yaml @@ -0,0 +1,84 @@ +--- +apiVersion: tekton.dev/v1 +kind: Task +metadata: + name: eaas-provision-space +spec: + description: >- + Provisions an ephemeral namespace on an EaaS cluster using a SpaceRequest. + This namespace can then be used to provision other ephemeral environments for testing. + params: + - name: ownerKind + type: string + default: PipelineRun + description: >- + The type of resource that should own the generated SpaceRequest. + Deletion of this resource will trigger deletion of the SpaceRequest. + Supported values: `PipelineRun`, `TaskRun`. + - name: ownerName + type: string + description: >- + The name of the resource that should own the generated SpaceRequest. + This should either be passed the value of `$(context.pipelineRun.name)` + or `$(context.taskRun.name)` depending on the value of `ownerKind`. + - name: ownerUid + type: string + description: >- + The uid of the resource that should own the generated SpaceRequest. + This should either be passed the value of `$(context.pipelineRun.uid)` + or `$(context.taskRun.uid)` depending on the value of `ownerKind`. + results: + - name: secretRef + description: Name of a Secret containing a kubeconfig used to access the provisioned space. + type: string + steps: + - name: request-space + image: registry.redhat.io/openshift4/ose-cli:4.13@sha256:73df37794ffff7de1101016c23dc623e4990810390ebdabcbbfa065214352c7c + env: + - name: NAMESPACE + value: $(context.taskRun.namespace) + - name: OWNER_KIND + value: $(params.ownerKind) + - name: OWNER_NAME + value: $(params.ownerName) + - name: OWNER_UID + value: $(params.ownerUid) + - name: TIER_NAME + value: appstudio-env # Temporary until the EaaS tier is ready + script: | + #!/bin/bash + set -eo pipefail + + case "$OWNER_KIND" in + PipelineRun|TaskRun) + ;; + *) + echo "Unsupported value for ownerKind param" + exit 1 + ;; + esac + + cat < space_request.yaml + apiVersion: toolchain.dev.openshift.com/v1alpha1 + kind: SpaceRequest + metadata: + generateName: eaas-spacerequest- + namespace: $NAMESPACE + ownerReferences: + - apiVersion: tekton.dev/v1 + kind: $OWNER_KIND + name: $OWNER_NAME + uid: $OWNER_UID + spec: + tierName: $TIER_NAME + EOF + + NAME=$(oc create -f space_request.yaml -o=jsonpath='{.metadata.name}') + + if oc wait spacerequests $NAME --for=condition=Ready --timeout=5m; then + secretRef=$(oc get spacerequests $NAME -o=jsonpath='{.status.namespaceAccess[0].secretRef}') + echo "SecretRef: $secretRef" + echo -n "$secretRef" > $(results.secretRef.path) + else + exit 1 + fi diff --git a/task/eaas-provision-space/OWNERS b/task/eaas-provision-space/OWNERS new file mode 100644 index 0000000000..7265cfc9b8 --- /dev/null +++ b/task/eaas-provision-space/OWNERS @@ -0,0 +1,8 @@ +# See the OWNERS docs: https://go.k8s.io/owners + +approvers: +- amisstea +- oamsalem +- avi-biton +- yftacherzog +- hmariset