Skip to content

Commit 078f6d0

Browse files
committed
Add just Recipies, Playbooks, & Zuul Jobs
just recepies (prelimiary): - Apply Cluster Stack to K8s-Cluster - Check for ClusterStack being created (Draft) - Apply Test Cluster Ressource to K8s Cluster Playbooks and Zuul Jobs for: - Uploading Assets for PR and Post-Merge Runs - Creating Chore Branches based on changes to versions.yaml at al. Signed-off-by: Oliver Kautz <oliver.kautz@gonicus.de>
1 parent 3c0d845 commit 078f6d0

4 files changed

Lines changed: 124 additions & 19 deletions

File tree

.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

justfile

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ workingBranchPrefix := "chore/update-"
1414
targetBranchPrefix := "release-"
1515

1616
# For Cluster Stack creation
17+
1718
mgmtcluster := "contextName"
1819
mgmcluster_namespace := "NamespaceName"
1920

@@ -30,7 +31,7 @@ help: default
3031
dependencies:
3132
#!/usr/bin/env bash
3233
set -euo pipefail
33-
34+
3435
if ! which csctl >/dev/null 2>&1; then
3536
echo -e "\e[33m\e[1mcsctl not found, building it from source.\e[0m"
3637
mkdir -p bin
@@ -138,7 +139,6 @@ build-version VERSION:
138139
./hack/generate_version.py --target-version {{ replace(VERSION, "-", ".") }}
139140
fi
140141
141-
142142
# Build assets for a certain Kubernetes Version. Out directory needs to be present.
143143
[group('Build Assets')]
144144
build-assets-local-for VERSION: dependencies
@@ -176,7 +176,7 @@ build-assets-all-local: build-versions-all
176176
177177
# Publish assets to OCI registry
178178
[group('Release')]
179-
publish-assets VERSION:
179+
publish-assets VERSION:
180180
#!/usr/bin/env bash
181181
if [[ -e providers/openstack/out/{{ replace(VERSION, ".", "-") }} ]]; then
182182
if [[ -n ${OCI_REGISTRY} && \
@@ -202,11 +202,16 @@ publish-assets-all:
202202
203203
# Publish new release of providers/openstack/scs
204204
[group('Release')]
205+
publish-test-release: dependencies
206+
csctl create -m hash --publish --remote oci providers/openstack/scs/
207+
208+
# Publish new release of providers/openstack/scs
205209
[confirm('Are you sure to publish a new stable release? (y|n)')]
210+
[group('Release')]
206211
publish-release: dependencies
207212
csctl create --publish --remote oci providers/openstack/scs/
208213
209-
# Remove old branches that had been merged to main
214+
# Remove old branches that had been merged to main
210215
[group('git')]
211216
git-clean:
212217
git branch --merged | grep -Ev "(^\*|^\+|^release/\+|main)" | xargs --no-run-if-empty git branch -d
@@ -217,17 +222,17 @@ git-chore-branch VERSION: && (gh-create-chore-pr VERSION)
217222
#!/usr/bin/env bash
218223
set -euo pipefail
219224
currentBranch=$(git branch --show-current)
220-
if git show-ref -q --branches {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}; then
225+
if git show-ref -q --branches {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}; then
221226
# Switch to branch if it exists
222-
git switch {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}
227+
git switch {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
223228
else
224229
# Create branch and switch to it
225-
git switch -c {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}
230+
git switch -c {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
226231
fi
227-
cp -r providers/openstack/out/{{replace(VERSION, ".", "-") }}/* providers/openstack/scs/
232+
cp -r providers/openstack/out/{{ replace(VERSION, ".", "-") }}/* providers/openstack/scs/
228233
git add providers/openstack/scs/
229-
git commit -s -m "chore(versions): Update Release for {{replace(VERSION, "-", ".") }}"
230-
git push --set-upstream origin {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}
234+
git commit -s -m "chore(versions): Update Release for {{ replace(VERSION, "-", ".") }}"
235+
git push --set-upstream origin {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
231236
git switch ${currentBranch}
232237
233238
# Create chore branches for all available out versions
@@ -273,9 +278,9 @@ gh-create-chore-pr VERSION: gh-login
273278
if ! which gh >/dev/null 2>&1; then
274279
echo "GitHub CLI not installed."
275280
else
276-
gh pr --title "chore(versions): Update Release for {{replace(VERSION, "-", ".") }}" \
277-
--head {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }} \
278-
--base {{ targetBranchPrefix }}{{replace(VERSION, "-", ".") }} \
281+
gh pr --title "chore(versions): Update Release for {{ replace(VERSION, "-", ".") }}" \
282+
--head {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }} \
283+
--base {{ targetBranchPrefix }}{{ replace(VERSION, "-", ".") }} \
279284
--dry-run
280285
fi
281286
@@ -286,23 +291,23 @@ create-clusterstack PATH:
286291
set -euo pipefail
287292
# Given directory name
288293
directory_name=".release/$PATH"
289-
294+
290295
# Extract parts from the directory name
291296
IFS='/' read -ra PARTS <<<"$directory_name"
292297
IFS='-' read -ra PARTS <<<"${PARTS[1]}"
293-
298+
294299
provider="${PARTS[0]}"
295300
name="${PARTS[1]}"
296301
kubernetes_major_version="${PARTS[2]}"
297302
kubernetes_minor_version="${PARTS[3]}"
298303
version="${PARTS[4]}-${PARTS[5]}.${PARTS[6]}"
299304
channel="custom"
300-
305+
301306
if [[ -z ${PARTS[6]} ]]; then
302307
version="${PARTS[4]}"
303308
channel="stable"
304309
fi
305-
310+
306311
Create the YAML structure
307312
clusterstack_yaml=$(cat <<-EOF
308313
---
@@ -324,7 +329,7 @@ create-clusterstack PATH:
324329
- ${version}
325330
EOF
326331
)
327-
332+
328333
echo "$clusterstack" | kubectl apply -f -
329334
330335
# UNTESTED RECIPE: Check on Cluster Stack creation
@@ -357,7 +362,7 @@ check-clusterstack NAME:
357362
create-cluster VERSION CLASS:
358363
#!/usr/bin/env bash
359364
set -euo pipefail
360-
cluster_manifest=<<-EOF
365+
cluster_manifest=$(cat <<-EOF
361366
---
362367
apiVersion: cluster.x-k8s.io/v1beta1
363368
kind: Cluster
@@ -377,4 +382,5 @@ create-cluster VERSION CLASS:
377382
name: md-0
378383
replicas: 1
379384
EOF
385+
)
380386
echo "${cluster_manifest}" | kubectl apply -f -
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# This Play should be used on PRs against release branches to upload Release Assets to SCS Registry
3+
- name: "Create Chore Branches and PRs"
4+
hosts: "all"
5+
vars:
6+
install_dir: "{{ ansible_user_dir }}/.local/bin"
7+
github_token: ""
8+
environment:
9+
PATH: "{{ install_dir }}:{{ ansible_env.PATH }}"
10+
tasks:
11+
- name: "Install Just"
12+
ansible.builtin.command:
13+
cmd: "curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to {{ ansible_user_dir }}/.local/bin/"
14+
creates: "{{ ansible_user_dir }}/.local/bin/just"
15+
- name: "Ensure just env file"
16+
ansible.builtin.copy:
17+
src: "{{ zuul.project.src_dir}}/just.env.example"
18+
dest: "{{ zuul.project.src_dir}}/just.env"
19+
- name: "Set Enviroments variables for just"
20+
ansible.builtin.lineinfile:
21+
path: "{{ zuul.project.src_dir}}/just.env"
22+
regexp: '^GH_TOKEN='
23+
line: "GH_TOKEN={{ github_token }}"
24+
- name: "Build Versions"
25+
ansible.builtin.command: "just --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile build-versions"
26+
- name: "Create Chore PRs"
27+
ansible.builtin.command: "just --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile git-chore-branches-all"

playbooks/upload_assets.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# This Play should be used on PRs against release branches to upload Release Assets to SCS Registry
3+
- name: "Upload Assets"
4+
hosts: "all"
5+
vars:
6+
install_dir: "{{ ansible_user_dir }}/.local/bin"
7+
is_pr: True # Set to False for Runs after merge.
8+
registry_credentials:
9+
OCI_REGISTRY: "registry.scs.community"
10+
OCI_REPOSITORY: "registry.scs.community/cluster-stacks/scs"
11+
OCI_USERNAME: ""
12+
OCI_PASSWORD: ""
13+
environment:
14+
PATH: "{{ install_dir }}:{{ ansible_env.PATH }}"
15+
tasks:
16+
- name: "Install Just"
17+
ansible.builtin.command:
18+
cmd: "curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to {{ ansible_user_dir }}/.local/bin/"
19+
creates: "{{ ansible_user_dir }}/.local/bin/just"
20+
- name: "Ensure just env file"
21+
ansible.builtin.copy:
22+
src: "{{ zuul.project.src_dir}}/just.env.example"
23+
dest: "{{ zuul.project.src_dir}}/just.env"
24+
- name: "Set Enviroments variables for just"
25+
ansible.builtin.lineinfile:
26+
path: "{{ zuul.project.src_dir}}/just.env"
27+
regexp: '^{{ item.key }}='
28+
line: "{{ item.key }}={{ item.value }}"
29+
loop: "{{registry_credentials | dict2items }}"
30+
- name: "Upload Preliminary Assets"
31+
ansible.builtin.cmd:
32+
cmd: "just --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile publish-test-release"
33+
when: is_pr
34+
- name: "Upload Release Assets"
35+
ansible.builtin.cmd:
36+
cmd: "just --yes --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile publish-release"
37+
when: not is_pr

0 commit comments

Comments
 (0)