Skip to content

Commit 1ffbe57

Browse files
committed
update
Signed-off-by: Jan Schoone <[email protected]>
1 parent 860b6f2 commit 1ffbe57

File tree

8 files changed

+342
-40
lines changed

8 files changed

+342
-40
lines changed

.zuul.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,41 @@
5353
scs_compliance:
5454
enabled: true
5555

56+
## Cluster Stack Asset and Chore Jobs.
57+
## TODO: Adjust parent to a job that sets up credentials for registry and GH token, i.e. playbook definiton
58+
# - job:
59+
# name: publish-cluster-stack-assets
60+
# parent: base
61+
# description: |
62+
# Creates Cluster Stack Assets and uploads them to the configured OCI Registry.
63+
# If used in a PR, Assets with a hashed version will be used. Otherwise, a
64+
# new release is build.
65+
# timeout: 900 # 15m
66+
# pre-run: playbooks/dependencies.yaml
67+
# run: playbooks/upload_assets.yaml
68+
69+
# - job:
70+
# name: publish-cluster-stack-release-assets
71+
# parent: publish-cluster-stack-assets
72+
# description: |
73+
# Creates Cluster Stack Assets and uploads them to the configured OCI Registry.
74+
# If used in a PR, Assets with a hashed version will be used. Otherwise, a
75+
# new release is build.
76+
# timeout: 900 # 15m
77+
# pre-run: playbooks/dependencies.yaml
78+
# run: playbooks/upload_assets.yaml
79+
# vars:
80+
# is_pr: False
81+
82+
# - job:
83+
# name: cluster-stacks-chore
84+
# parent: base
85+
# description: |
86+
# Creates Cluster Stack manifests with updated versions and opens chore branches
87+
# and PRs against the correspondend release branches.
88+
# timeout: 900 # 15m
89+
# pre-run: playbooks/dependencies.yaml
90+
# run: playbooks/create_chore_branches.yaml
5691

5792
- project:
5893
name: SovereignCloudStack/cluster-stacks

just.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
OCI_REGISTRY=
2-
OCI_REPOSITORY=
1+
OCI_REGISTRY=registry.scs.community
2+
OCI_REPOSITORY=registry.scs.community/cluster-stacks/scs
33
OCI_USERNAME=
44
OCI_PASSWORD=
5+
# or
56
OCI_ACCESS_TOKEN=
7+
GH_TOKEN= # Accesstoken for GitHub Account for authentication for git and PR management

justfile

Lines changed: 212 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ set export := true
77
set dotenv-filename := "just.env"
88
set dotenv-load := true
99

10-
path := env_var('PATH') + ":" + justfile_directory() + "/bin"
10+
PATH := env_var('PATH') + ":" + justfile_directory() + "/bin"
1111
repo := "https://github.com/SovereignCloudStack/cluster-stacks"
1212
mainBranch := "main"
1313
workingBranchPrefix := "chore/update-"
1414
targetBranchPrefix := "release-"
1515

16+
# For Cluster Stack creation
17+
18+
mgmtcluster := "contextName"
19+
mgmcluster_namespace := "NamespaceName"
20+
1621
[private]
1722
default:
1823
@just --list --justfile {{ justfile() }}
@@ -26,7 +31,6 @@ help: default
2631
dependencies:
2732
#!/usr/bin/env bash
2833
set -euo pipefail
29-
export PATH=${path}
3034
if ! which csctl >/dev/null 2>&1; then
3135
echo -e "\e[33m\e[1mcsctl not found, building it from source.\e[0m"
3236
mkdir -p bin
@@ -75,7 +79,7 @@ clean:
7579
[group('General')]
7680
diff:
7781
#!/usr/bin/env bash
78-
set -euxo pipefail
82+
set -euo pipefail
7983
versionsPath="providers/openstack/scs/versions.yaml"
8084
currentVersions=$(cat ${versionsPath})
8185
mainVersions=$(git show ${mainBranch}:${versionsPath})
@@ -90,22 +94,26 @@ diff:
9094
done
9195
echo "${toTest[@]}"
9296

93-
9497
# Build Clusterstacks version directories according to changes in versions.yaml. Builds out directoy
9598
[group('Building Manifests')]
9699
build-versions: dependencies
97100
#!/usr/bin/env bash
98101
set -euxo pipefail
102+
# Build Clusterstacks version directories according to changes in versions.yaml. Builds out directoy
103+
[group('Build Manifests')]
104+
build-versions: dependencies
105+
#!/usr/bin/env bash
106+
set -euo pipefail
99107
changedVersions=$(just diff)
100108
for version in ${changedVersions[@]}; do
101109
just build-version ${version}
102110
done
103111

104112
# Generate manifest for all Kubernetes Version regardless of changes to versions.
105-
[group('Building Manifests')]
113+
[group('Build Manifests')]
106114
build-versions-all: dependencies
107115
#!/usr/bin/env bash
108-
set -euxo pipefail
116+
set -euo pipefail
109117
versionsPath="providers/openstack/scs/versions.yaml"
110118
currentVersions=$(cat ${versionsPath})
111119
kubernetesVersions=$(yq -r '.[].kubernetes' ${versionsPath} | grep -Po "1\.\d+")
@@ -114,12 +122,12 @@ build-versions-all: dependencies
114122
done
115123

116124
# Generate Manifest for a specific Kubernetes version. Builds out directory
117-
[group('Building Manifests')]
125+
[group('Build Manifests')]
118126
build-version VERSION:
119127
#!/usr/bin/env bash
120-
set -euxo pipefail
128+
set -euo pipefail
121129
echo -e "\e[33m\e[1mBuild Manifests for {{ VERSION }}\e[0m"
122-
## CHECK IF THERE IS A CHANGE IN THE COMPONENT VERSIONS
130+
# check if there is a change in the component versions
123131
if [[ -e providers/openstack/out/{{ replace(VERSION, ".", "-") }} ]]; then
124132
versionsFile="providers/openstack/scs/versions.yaml"
125133
k8sVersion=$(yq -r ".[] | select(.kubernetes | test(\"{{ replace(VERSION, "-", ".") }}\")).kubernetes" ${versionsFile})
@@ -135,13 +143,17 @@ build-version VERSION:
135143
./hack/generate_version.py --target-version {{ replace(VERSION, "-", ".") }}
136144
fi
137145

138-
139146
# Build assets for a certain Kubernetes Version. Out directory needs to be present.
140147
[group('Building Assets')]
141148
build-assets-local-for VERSION: dependencies
142149
#!/usr/bin/env bash
143150
export PATH=${path}
144151
set -euxo pipefail
152+
# Build assets for a certain Kubernetes Version. Out directory needs to be present.
153+
[group('Build Assets')]
154+
build-assets-local-for VERSION: dependencies
155+
#!/usr/bin/env bash
156+
set -euo pipefail
145157
just build-version {{ VERSION }}
146158
echo -e "\e[33m\e[1mBuild Assets for {{ VERSION }}\e[0m"
147159
if ! [[ -e providers/openstack/out/{{ replace(VERSION, ".", "-") }}/cluster-addon/Chart.lock ]]; then
@@ -153,47 +165,91 @@ build-assets-local-for VERSION: dependencies
153165
csctl create -m hash providers/openstack/out/{{ replace(VERSION, ".", "-") }}/
154166

155167
# Build assets for a certain Kubernetes Version. Out directory needs to be present.
156-
[group('Building Assets')]
168+
[group('Build Assets')]
157169
build-assets-local: build-versions
158170
#!/usr/bin/env bash
159-
export PATH=${path}
171+
set -euo pipefail
160172
changedVersions=$(just diff)
161173
for version in ${changedVersions[@]}; do
162174
just build-assets-local-for ${version}
163175
done
164176

165177
# Build assets for a certain Kubernetes Version.
166-
[group('Building Assets')]
178+
[group('Build Assets')]
167179
build-assets-all-local: build-versions-all
168180
#!/usr/bin/env bash
169-
export PATH=${path}
170-
set -euxo pipefail
181+
set -euo pipefail
171182
versions="$(cd providers/openstack/out/ && echo *)"
172183
for version in ${versions[@]}; do
173184
just build-assets-local-for ${version}
174185
done
175186

176-
# Remove old branches that had been merged to main
187+
# Publish assets to OCI registry
188+
[group('Release')]
189+
publish-assets VERSION:
190+
#!/usr/bin/env bash
191+
if [[ -e providers/openstack/out/{{ replace(VERSION, ".", "-") }} ]]; then
192+
if [[ -n ${OCI_REGISTRY} && \
193+
-n ${OCI_REPOSITORY} && \
194+
(( -n ${OCI_USERNAME} && -n ${OCI_PASSWORD} ) || -n ${OCI_ACCESS_TOKEN} ) ]]; then
195+
csctl create -m hash --publish --remote oci providers/openstack/out/{{ replace(VERSION, ".", "-") }}/
196+
else
197+
echo "Please define OCI_* Variables in just.env"
198+
fi
199+
else
200+
echo "Manifest directory for {{ replace(VERSION, ".", "-") }}" does not exist.
201+
fi
202+
203+
# Publish all available assets to OCI registry
204+
[group('Release')]
205+
publish-assets-all:
206+
#!/usr/bin/env bash
207+
set -euo pipefail
208+
versions="$(cd providers/openstack/out/ && echo *)"
209+
for version in ${versions[@]}; do
210+
just publish-assets ${version}
211+
done
212+
213+
# Publish new release of providers/openstack/scs
214+
[group('Release')]
215+
publish-test-release: dependencies
216+
csctl create -m hash --publish --remote oci providers/openstack/scs/
217+
218+
# Publish new release of providers/openstack/scs
219+
[confirm('Are you sure to publish a new stable release? (y|n)')]
220+
[group('Release')]
221+
publish-release: dependencies
222+
csctl create --publish --remote oci providers/openstack/scs/
223+
224+
# Remove old branches that had been merged to main
177225
[group('git')]
178226
git-clean:
179-
git branch --merged | grep -Ev "(^\*|^\+|master|main|dev)" | xargs --no-run-if-empty git branch -d
227+
git branch --merged | grep -Ev "(^\*|^\+|^release/\+|main)" | xargs --no-run-if-empty git branch -d
180228

181-
# Create Chore branch for specific Kubernetes Version
229+
# Create chore branch and PR for specific Kubernetes Version
182230
[group('git')]
183-
git-chore-branch VERSION:
231+
git-chore-branch VERSION: && (gh-create-chore-pr VERSION)
184232
#!/usr/bin/env bash
233+
set -euo pipefail
185234
currentBranch=$(git branch --show-current)
186-
git switch -c chore/update-{{replace(VERSION, "-", ".") }}
187-
cp -r providers/openstack/out/{{replace(VERSION, ".", "-") }}/* providers/openstack/scs/
235+
if git show-ref -q --branches {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}; then
236+
# Switch to branch if it exists
237+
git switch {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
238+
else
239+
# Create branch and switch to it
240+
git switch -c {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
241+
fi
242+
cp -r providers/openstack/out/{{ replace(VERSION, ".", "-") }}/* providers/openstack/scs/
188243
git add providers/openstack/scs/
189-
git commit -s -S -m "chore(versions): Update Release for {{replace(VERSION, "-", ".") }}"
190-
#git push
244+
git commit -s -m "chore(versions): Update Release for {{ replace(VERSION, "-", ".") }}"
245+
git push --set-upstream origin {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
191246
git switch ${currentBranch}
192247

193248
# Create chore branches for all available out versions
194249
[group('git')]
195250
git-chore-branches-all:
196251
#!/usr/bin/env bash
252+
set -euo pipefail
197253
if ! [[ -e providers/openstack/out ]]; then
198254
echo "Error: out directory does not exists."
199255
else
@@ -204,3 +260,136 @@ git-chore-branches-all:
204260
just git-chore-branch $version
205261
done
206262
fi
263+
# Login to Github with GitHub CLI
264+
[group('GitHub')]
265+
gh-login GH_TOKEN="${GH_TOKEN}":
266+
#!/usr/bin/env bash
267+
set -euo pipefail
268+
if ! which gh >/dev/null 2>&1; then
269+
echo "GitHub CLI not installed."
270+
else
271+
if ! gh auth status >/dev/null 2>&1; then
272+
gh config set -h github.com git_protocol https
273+
# If TOKEN is empty use WebUI Authentication
274+
if [[ -z $GH_TOKEN ]]; then
275+
gh auth login --hostname github.com
276+
else
277+
echo $GH_TOKEN | gh auth login --hostname github.com --with-token
278+
fi
279+
fi
280+
fi
281+
282+
# Create chore PR for given VERSION against correspondend release branch
283+
[group('GitHub')]
284+
gh-create-chore-pr VERSION: gh-login
285+
#!/usr/bin/env bash
286+
set -euo pipefail
287+
if ! which gh >/dev/null 2>&1; then
288+
echo "GitHub CLI not installed."
289+
else
290+
gh pr --title "chore(versions): Update Release for {{ replace(VERSION, "-", ".") }}" \
291+
--head {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }} \
292+
--base {{ targetBranchPrefix }}{{ replace(VERSION, "-", ".") }} \
293+
--dry-run
294+
fi
295+
296+
# UNTESTED RECIPE: Create Cluster Stack on Cluster for given Version at $PATH in ./release
297+
[group('Test')]
298+
create-clusterstack PATH:
299+
#!/usr/bin/env bash
300+
set -euo pipefail
301+
# Given directory name
302+
directory_name=".release/$PATH"
303+
304+
# Extract parts from the directory name
305+
IFS='/' read -ra PARTS <<<"$directory_name"
306+
IFS='-' read -ra PARTS <<<"${PARTS[1]}"
307+
308+
provider="${PARTS[0]}"
309+
name="${PARTS[1]}"
310+
kubernetes_major_version="${PARTS[2]}"
311+
kubernetes_minor_version="${PARTS[3]}"
312+
version="${PARTS[4]}-${PARTS[5]}.${PARTS[6]}"
313+
channel="custom"
314+
315+
if [[ -z ${PARTS[6]} ]]; then
316+
version="${PARTS[4]}"
317+
channel="stable"
318+
fi
319+
320+
Create the YAML structure
321+
clusterstack_yaml=$(cat <<-EOF
322+
---
323+
apiVersion: clusterstack.x-k8s.io/v1alpha1
324+
kind: ClusterStack
325+
metadata:
326+
name: ${provider}-${name}-${kubernetes_major_version}-${kubernetes_minor_version}
327+
spec:
328+
provider: ${provider}
329+
name: ${name}
330+
kubernetesVersion: "${kubernetes_major_version}.${kubernetes_minor_version}"
331+
channel: ${channel}
332+
autoSubscribe: false
333+
providerRef:
334+
apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
335+
kind: OpenStackClusterStackReleaseTemplate
336+
name: cspotemplate
337+
versions:
338+
- ${version}
339+
EOF
340+
)
341+
342+
echo "$clusterstack" | kubectl apply -f -
343+
344+
# UNTESTED RECIPE: Check on Cluster Stack creation
345+
[group('Test')]
346+
check-clusterstack NAME:
347+
#!/usr/bin/env bash
348+
set -euo pipefail
349+
declare -i RETRIES
350+
RETRIES=20
351+
declare -i INTERVAL
352+
INTERVAL=5
353+
# TODO: Refine Status Command
354+
STATUS_CMD="kubectl get clusterstack -n $ ${NAME} -ojson | jq .status"
355+
while (( $RETRIES > 0 )); do
356+
RETRIES-=1
357+
if ${STATUS_CMD}; then
358+
STATUS=$(${STATUS_CMD})
359+
if true; then
360+
echo "Clusterstack creation successful."
361+
break
362+
else
363+
echo "waiting for Cluster Stack creation"
364+
fi
365+
fi
366+
sleep $INTERVAL
367+
done
368+
369+
# UNTESTED RECIPE: Create Test Cluster for Kubernetes VERSION and Cluster CLASS
370+
[group('Test')]
371+
create-cluster VERSION CLASS:
372+
#!/usr/bin/env bash
373+
set -euo pipefail
374+
cluster_manifest=$(cat <<-EOF
375+
---
376+
apiVersion: cluster.x-k8s.io/v1beta1
377+
kind: Cluster
378+
metadata:
379+
name: cs-cluster
380+
labels:
381+
managed-secret: cloud-config
382+
spec:
383+
topology:
384+
class: {{ CLASS }}
385+
controlPlane:
386+
replicas: 1
387+
version: v{{ VERSION }}
388+
workers:
389+
machineDeployments:
390+
- class: default-worker
391+
name: md-0
392+
replicas: 1
393+
EOF
394+
)
395+
echo "${cluster_manifest}" | kubectl apply -f -

0 commit comments

Comments
 (0)