Skip to content

Commit 3c0d845

Browse files
committed
Add Recipes for Cluster Class testing
- Creation of Cluster Class - Check if ressources are ready (prelimiary, needs extension) - Creation of Test Cluster Signed-off-by: Oliver Kautz <[email protected]>
1 parent fdd730a commit 3c0d845

File tree

1 file changed

+110
-7
lines changed

1 file changed

+110
-7
lines changed

justfile

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ mainBranch := "main"
1313
workingBranchPrefix := "chore/update-"
1414
targetBranchPrefix := "release-"
1515

16+
# For Cluster Stack creation
17+
mgmtcluster := "contextName"
18+
mgmcluster_namespace := "NamespaceName"
19+
1620
[private]
1721
default:
1822
@just --list --justfile {{ justfile() }}
@@ -90,7 +94,6 @@ diff:
9094
done
9195
echo "${toTest[@]}"
9296

93-
9497
# Build Clusterstacks version directories according to changes in versions.yaml. Builds out directoy
9598
[group('Build Manifests')]
9699
build-versions: dependencies
@@ -197,6 +200,12 @@ publish-assets-all:
197200
just publish-assets ${version}
198201
done
199202

203+
# Publish new release of providers/openstack/scs
204+
[group('Release')]
205+
[confirm('Are you sure to publish a new stable release? (y|n)')]
206+
publish-release: dependencies
207+
csctl create --publish --remote oci providers/openstack/scs/
208+
200209
# Remove old branches that had been merged to main
201210
[group('git')]
202211
git-clean:
@@ -237,12 +246,6 @@ git-chore-branches-all:
237246
done
238247
fi
239248

240-
# Publish new release of providers/openstack/scs
241-
[group('Release')]
242-
[confirm('Are you sure to publish a new stable release? (y|n)')]
243-
publish-release: dependencies
244-
csctl create --publish --remote oci providers/openstack/scs/
245-
246249
# Login to Github with GitHub CLI
247250
[group('GitHub')]
248251
gh-login GH_TOKEN="${GH_TOKEN}":
@@ -275,3 +278,103 @@ gh-create-chore-pr VERSION: gh-login
275278
--base {{ targetBranchPrefix }}{{replace(VERSION, "-", ".") }} \
276279
--dry-run
277280
fi
281+
282+
# UNTESTED RECIPE: Create Cluster Stack on Cluster for given Version at $PATH in ./release
283+
[group('Test')]
284+
create-clusterstack PATH:
285+
#!/usr/bin/env bash
286+
set -euo pipefail
287+
# Given directory name
288+
directory_name=".release/$PATH"
289+
290+
# Extract parts from the directory name
291+
IFS='/' read -ra PARTS <<<"$directory_name"
292+
IFS='-' read -ra PARTS <<<"${PARTS[1]}"
293+
294+
provider="${PARTS[0]}"
295+
name="${PARTS[1]}"
296+
kubernetes_major_version="${PARTS[2]}"
297+
kubernetes_minor_version="${PARTS[3]}"
298+
version="${PARTS[4]}-${PARTS[5]}.${PARTS[6]}"
299+
channel="custom"
300+
301+
if [[ -z ${PARTS[6]} ]]; then
302+
version="${PARTS[4]}"
303+
channel="stable"
304+
fi
305+
306+
Create the YAML structure
307+
clusterstack_yaml=$(cat <<-EOF
308+
---
309+
apiVersion: clusterstack.x-k8s.io/v1alpha1
310+
kind: ClusterStack
311+
metadata:
312+
name: ${provider}-${name}-${kubernetes_major_version}-${kubernetes_minor_version}
313+
spec:
314+
provider: ${provider}
315+
name: ${name}
316+
kubernetesVersion: "${kubernetes_major_version}.${kubernetes_minor_version}"
317+
channel: ${channel}
318+
autoSubscribe: false
319+
providerRef:
320+
apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
321+
kind: OpenStackClusterStackReleaseTemplate
322+
name: cspotemplate
323+
versions:
324+
- ${version}
325+
EOF
326+
)
327+
328+
echo "$clusterstack" | kubectl apply -f -
329+
330+
# UNTESTED RECIPE: Check on Cluster Stack creation
331+
[group('Test')]
332+
check-clusterstack NAME:
333+
#!/usr/bin/env bash
334+
set -euo pipefail
335+
declare -i RETRIES
336+
RETRIES=20
337+
declare -i INTERVAL
338+
INTERVAL=5
339+
# TODO: Refine Status Command
340+
STATUS_CMD="kubectl get clusterstack -n $ ${NAME} -ojson | jq .status"
341+
while (( $RETRIES > 0 )); do
342+
RETRIES-=1
343+
if ${STATUS_CMD}; then
344+
STATUS=$(${STATUS_CMD})
345+
if true; then
346+
echo "Clusterstack creation successful."
347+
break
348+
else
349+
echo "waiting for Cluster Stack creation"
350+
fi
351+
fi
352+
sleep $INTERVAL
353+
done
354+
355+
# UNTESTED RECIPE: Create Test Cluster for Kubernetes VERSION and Cluster CLASS
356+
[group('Test')]
357+
create-cluster VERSION CLASS:
358+
#!/usr/bin/env bash
359+
set -euo pipefail
360+
cluster_manifest=<<-EOF
361+
---
362+
apiVersion: cluster.x-k8s.io/v1beta1
363+
kind: Cluster
364+
metadata:
365+
name: cs-cluster
366+
labels:
367+
managed-secret: cloud-config
368+
spec:
369+
topology:
370+
class: {{ CLASS }}
371+
controlPlane:
372+
replicas: 1
373+
version: v{{ VERSION }}
374+
workers:
375+
machineDeployments:
376+
- class: default-worker
377+
name: md-0
378+
replicas: 1
379+
EOF
380+
echo "${cluster_manifest}" | kubectl apply -f -

0 commit comments

Comments
 (0)