Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eaas-provision-space task #1064

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions task/eaas-provision-space/0.1/README.md
Original file line number Diff line number Diff line change
@@ -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.|

84 changes: 84 additions & 0 deletions task/eaas-provision-space/0.1/eaas-provision-space.yaml
Original file line number Diff line number Diff line change
@@ -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 <<EOF > 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
8 changes: 8 additions & 0 deletions task/eaas-provision-space/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See the OWNERS docs: https://go.k8s.io/owners

approvers:
- amisstea
- oamsalem
- avi-biton
- yftacherzog
- hmariset