Skip to content

Commit

Permalink
Add imageContentSources to eaas-create-ephemeral-cluster-hypershift-aws
Browse files Browse the repository at this point in the history
The user may choose to pass the value as a quoted string with explicit
newlines ("\n") or by using the "|" operator, among other options. A tool
like `yq` is therefore necessary since basic variable expansion within a
heredoc isn't adequate at preventing issues with malformed yaml.

As a result. the container image was changed to one which provides both the
`yq` and `kubectl` binaries. This is a more upstream friendly image
since it's publicly pullable.

Signed-off-by: Alex Misstear <[email protected]>
  • Loading branch information
amisstea committed Nov 11, 2024
1 parent 156fddc commit 0eb4b04
Showing 1 changed file with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ spec:
description: >-
This StepAction provisions an ephemeral cluster using Hypershift with 3 worker nodes in AWS.
It does so by creating a ClusterTemplateInstance in a space on an EaaS cluster.
image: registry.redhat.io/openshift4/ose-cli@sha256:15da03b04318bcc842060b71e9dd6d6c2595edb4e8fdd11b0c6781eeb03ca182
image: public.ecr.aws/bitnami/kubectl:1.31.2@sha256:df433ab6de9adfb0223df79167719099726f946a68c1784d7739a8b6b63cd137
workingDir: /opt/bitnami
params:
- name: eaasSpaceSecretRef
type: string
Expand All @@ -32,10 +33,18 @@ spec:
type: string
default: 30m
description: How long to wait for cluster provisioning to complete.
- name: imageContentSources
type: string
default: ""
description: >-
Alternate registry information containing a list of sources and their mirrors in yaml format.
See: https://hypershift-docs.netlify.app/how-to/disconnected/image-content-sources
results:
- name: clusterName
description: The name of the generated ClusterTemplateInstance resource.
env:
- name: HOME
value: /opt/bitnami
- name: INSTANCE_TYPE
value: "$(params.instanceType)"
- name: VERSION
Expand All @@ -51,40 +60,45 @@ spec:
value: "$(params.insecureSkipTLSVerify)"
- name: TIMEOUT
value: "$(params.timeout)"
- name: IMAGE_CONTENT_SOURCES
value: "$(params.imageContentSources)"
script: |
#!/bin/bash
set -eo pipefail
cat <<EOF > cti.yaml
---
apiVersion: clustertemplate.openshift.io/v1alpha1
kind: ClusterTemplateInstance
metadata:
generateName: cluster-
spec:
clusterTemplateRef: hypershift-aws-cluster
parameters:
- name: instanceType
value: $INSTANCE_TYPE
- name: version
value: $VERSION
- name: timeout
value: $TIMEOUT
parameters: []
EOF
yq -i '.spec.parameters += {"name": "instanceType", "value": strenv(INSTANCE_TYPE)}' cti.yaml
yq -i '.spec.parameters += {"name": "version", "value": strenv(VERSION)}' cti.yaml
yq -i '.spec.parameters += {"name": "timeout", "value": strenv(TIMEOUT)}' cti.yaml
yq -i '.spec.parameters += {"name": "imageContentSources", "value": strenv(IMAGE_CONTENT_SOURCES)}' cti.yaml
echo "Creating the following resource:"
cat cti.yaml
trap 'rm -f "$KUBECONFIG"' EXIT
echo "$KUBECONFIG_VALUE" > $KUBECONFIG
OC=(oc --insecure-skip-tls-verify="$INSECURE_SKIP_TLS_VERIFY")
CTI_NAME=$("${OC[@]}" create -f cti.yaml -o=jsonpath='{.metadata.name}')
KUBECTL=(kubectl --insecure-skip-tls-verify="$INSECURE_SKIP_TLS_VERIFY")
CTI_NAME=$("${KUBECTL[@]}" create -f cti.yaml -o=jsonpath='{.metadata.name}')
echo "Created ClusterTemplateInstance $CTI_NAME"
echo -n $CTI_NAME > $(step.results.clusterName.path)
echo "Waiting for ClusterTemplateInstance to be ready ($TIMEOUT timeout)"
if "${OC[@]}" wait cti "$CTI_NAME" --for=jsonpath='{.status.phase}'=Ready --timeout="$TIMEOUT"; then
if "${KUBECTL[@]}" wait cti "$CTI_NAME" --for=jsonpath='{.status.phase}'=Ready --timeout="$TIMEOUT"; then
echo "Successfully provisioned $CTI_NAME"
exit 0
else
"${OC[@]}" get cti "$CTI_NAME" -o yaml
"${KUBECTL[@]}" get cti "$CTI_NAME" -o yaml
echo "Failed to provision $CTI_NAME"
exit 1
fi

0 comments on commit 0eb4b04

Please sign in to comment.