Skip to content

Commit

Permalink
Add just Recipies, Playbooks, & Zuul Jobs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
o-otte committed Nov 29, 2024
1 parent 3c0d845 commit 078f6d0
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 19 deletions.
35 changes: 35 additions & 0 deletions .zuul.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@
scs_compliance:
enabled: true

## Cluster Stack Asset and Chore Jobs.
## TODO: Adjust parent to a job that sets up credentials for registry and GH token, i.e. playbook definiton
# - job:
# name: publish-cluster-stack-assets
# parent: base
# description: |
# Creates Cluster Stack Assets and uploads them to the configured OCI Registry.
# If used in a PR, Assets with a hashed version will be used. Otherwise, a

Check failure on line 63 in .zuul.yaml

View workflow job for this annotation

GitHub Actions / check-yaml-syntax

63:81 [trailing-spaces] trailing spaces
# new release is build.
# timeout: 900 # 15m
# pre-run: playbooks/dependencies.yaml
# run: playbooks/upload_assets.yaml

# - job:
# name: publish-cluster-stack-release-assets
# parent: publish-cluster-stack-assets
# description: |
# Creates Cluster Stack Assets and uploads them to the configured OCI Registry.
# If used in a PR, Assets with a hashed version will be used. Otherwise, a

Check failure on line 74 in .zuul.yaml

View workflow job for this annotation

GitHub Actions / check-yaml-syntax

74:81 [trailing-spaces] trailing spaces
# new release is build.
# timeout: 900 # 15m
# pre-run: playbooks/dependencies.yaml
# run: playbooks/upload_assets.yaml
# vars:
# is_pr: False

# - job:
# name: cluster-stacks-chore
# parent: base
# description: |
# Creates Cluster Stack manifests with updated versions and opens chore branches
# and PRs against the correspondend release branches.

Check failure on line 87 in .zuul.yaml

View workflow job for this annotation

GitHub Actions / check-yaml-syntax

87:60 [trailing-spaces] trailing spaces
# timeout: 900 # 15m
# pre-run: playbooks/dependencies.yaml
# run: playbooks/create_chore_branches.yaml

- project:
name: SovereignCloudStack/cluster-stacks
Expand Down
44 changes: 25 additions & 19 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workingBranchPrefix := "chore/update-"
targetBranchPrefix := "release-"

# For Cluster Stack creation

mgmtcluster := "contextName"
mgmcluster_namespace := "NamespaceName"

Expand All @@ -30,7 +31,7 @@ help: default
dependencies:
#!/usr/bin/env bash
set -euo pipefail
if ! which csctl >/dev/null 2>&1; then
echo -e "\e[33m\e[1mcsctl not found, building it from source.\e[0m"
mkdir -p bin
Expand Down Expand Up @@ -138,7 +139,6 @@ build-version VERSION:
./hack/generate_version.py --target-version {{ replace(VERSION, "-", ".") }}
fi

# Build assets for a certain Kubernetes Version. Out directory needs to be present.
[group('Build Assets')]
build-assets-local-for VERSION: dependencies
Expand Down Expand Up @@ -176,7 +176,7 @@ build-assets-all-local: build-versions-all
# Publish assets to OCI registry
[group('Release')]
publish-assets VERSION:
publish-assets VERSION:
#!/usr/bin/env bash
if [[ -e providers/openstack/out/{{ replace(VERSION, ".", "-") }} ]]; then
if [[ -n ${OCI_REGISTRY} && \
Expand All @@ -202,11 +202,16 @@ publish-assets-all:
# Publish new release of providers/openstack/scs
[group('Release')]
publish-test-release: dependencies
csctl create -m hash --publish --remote oci providers/openstack/scs/
# Publish new release of providers/openstack/scs
[confirm('Are you sure to publish a new stable release? (y|n)')]
[group('Release')]
publish-release: dependencies
csctl create --publish --remote oci providers/openstack/scs/
# Remove old branches that had been merged to main
# Remove old branches that had been merged to main
[group('git')]
git-clean:
git branch --merged | grep -Ev "(^\*|^\+|^release/\+|main)" | xargs --no-run-if-empty git branch -d
Expand All @@ -217,17 +222,17 @@ git-chore-branch VERSION: && (gh-create-chore-pr VERSION)
#!/usr/bin/env bash
set -euo pipefail
currentBranch=$(git branch --show-current)
if git show-ref -q --branches {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}; then
if git show-ref -q --branches {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}; then
# Switch to branch if it exists
git switch {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}
git switch {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
else
# Create branch and switch to it
git switch -c {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}
git switch -c {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
fi
cp -r providers/openstack/out/{{replace(VERSION, ".", "-") }}/* providers/openstack/scs/
cp -r providers/openstack/out/{{ replace(VERSION, ".", "-") }}/* providers/openstack/scs/
git add providers/openstack/scs/
git commit -s -m "chore(versions): Update Release for {{replace(VERSION, "-", ".") }}"
git push --set-upstream origin {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }}
git commit -s -m "chore(versions): Update Release for {{ replace(VERSION, "-", ".") }}"
git push --set-upstream origin {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }}
git switch ${currentBranch}
# Create chore branches for all available out versions
Expand Down Expand Up @@ -273,9 +278,9 @@ gh-create-chore-pr VERSION: gh-login
if ! which gh >/dev/null 2>&1; then
echo "GitHub CLI not installed."
else
gh pr --title "chore(versions): Update Release for {{replace(VERSION, "-", ".") }}" \
--head {{ workingBranchPrefix }}{{replace(VERSION, "-", ".") }} \
--base {{ targetBranchPrefix }}{{replace(VERSION, "-", ".") }} \
gh pr --title "chore(versions): Update Release for {{ replace(VERSION, "-", ".") }}" \
--head {{ workingBranchPrefix }}{{ replace(VERSION, "-", ".") }} \
--base {{ targetBranchPrefix }}{{ replace(VERSION, "-", ".") }} \
--dry-run
fi
Expand All @@ -286,23 +291,23 @@ create-clusterstack PATH:
set -euo pipefail
# Given directory name
directory_name=".release/$PATH"
# Extract parts from the directory name
IFS='/' read -ra PARTS <<<"$directory_name"
IFS='-' read -ra PARTS <<<"${PARTS[1]}"
provider="${PARTS[0]}"
name="${PARTS[1]}"
kubernetes_major_version="${PARTS[2]}"
kubernetes_minor_version="${PARTS[3]}"
version="${PARTS[4]}-${PARTS[5]}.${PARTS[6]}"
channel="custom"
if [[ -z ${PARTS[6]} ]]; then
version="${PARTS[4]}"
channel="stable"
fi
Create the YAML structure
clusterstack_yaml=$(cat <<-EOF
---
Expand All @@ -324,7 +329,7 @@ create-clusterstack PATH:
- ${version}
EOF
)
echo "$clusterstack" | kubectl apply -f -
# UNTESTED RECIPE: Check on Cluster Stack creation
Expand Down Expand Up @@ -357,7 +362,7 @@ check-clusterstack NAME:
create-cluster VERSION CLASS:
#!/usr/bin/env bash
set -euo pipefail
cluster_manifest=<<-EOF
cluster_manifest=$(cat <<-EOF
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
Expand All @@ -377,4 +382,5 @@ create-cluster VERSION CLASS:
name: md-0
replicas: 1
EOF
)
echo "${cluster_manifest}" | kubectl apply -f -
27 changes: 27 additions & 0 deletions playbooks/create_chore_branches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---

Check failure on line 1 in playbooks/create_chore_branches.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

internal-error

A malformed block was encountered while loading a block.
# This Play should be used on PRs against release branches to upload Release Assets to SCS Registry
- name: "Create Chore Branches and PRs"
hosts: "all"
vars:
install_dir: "{{ ansible_user_dir }}/.local/bin"
github_token: ""
environment:
PATH: "{{ install_dir }}:{{ ansible_env.PATH }}"
tasks:
- name: "Install Just"
ansible.builtin.command:
cmd: "curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to {{ ansible_user_dir }}/.local/bin/"
creates: "{{ ansible_user_dir }}/.local/bin/just"
- name: "Ensure just env file"
ansible.builtin.copy:
src: "{{ zuul.project.src_dir}}/just.env.example"
dest: "{{ zuul.project.src_dir}}/just.env"
- name: "Set Enviroments variables for just"
ansible.builtin.lineinfile:
path: "{{ zuul.project.src_dir}}/just.env"
regexp: '^GH_TOKEN='
line: "GH_TOKEN={{ github_token }}"
- name: "Build Versions"
ansible.builtin.command: "just --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile build-versions"
- name: "Create Chore PRs"
ansible.builtin.command: "just --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile git-chore-branches-all"
37 changes: 37 additions & 0 deletions playbooks/upload_assets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---

Check failure on line 1 in playbooks/upload_assets.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

internal-error

A malformed block was encountered while loading a block.
# This Play should be used on PRs against release branches to upload Release Assets to SCS Registry
- name: "Upload Assets"
hosts: "all"
vars:
install_dir: "{{ ansible_user_dir }}/.local/bin"
is_pr: True # Set to False for Runs after merge.

Check warning on line 7 in playbooks/upload_assets.yaml

View workflow job for this annotation

GitHub Actions / check-yaml-syntax

7:12 [truthy] truthy value should be one of [false, true]

Check warning on line 7 in playbooks/upload_assets.yaml

View workflow job for this annotation

GitHub Actions / check-yaml-syntax

7:17 [comments] too few spaces before comment
registry_credentials:
OCI_REGISTRY: "registry.scs.community"
OCI_REPOSITORY: "registry.scs.community/cluster-stacks/scs"
OCI_USERNAME: ""
OCI_PASSWORD: ""
environment:
PATH: "{{ install_dir }}:{{ ansible_env.PATH }}"
tasks:
- name: "Install Just"
ansible.builtin.command:
cmd: "curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to {{ ansible_user_dir }}/.local/bin/"
creates: "{{ ansible_user_dir }}/.local/bin/just"
- name: "Ensure just env file"
ansible.builtin.copy:
src: "{{ zuul.project.src_dir}}/just.env.example"
dest: "{{ zuul.project.src_dir}}/just.env"
- name: "Set Enviroments variables for just"
ansible.builtin.lineinfile:
path: "{{ zuul.project.src_dir}}/just.env"
regexp: '^{{ item.key }}='
line: "{{ item.key }}={{ item.value }}"
loop: "{{registry_credentials | dict2items }}"
- name: "Upload Preliminary Assets"

Check failure on line 30 in playbooks/upload_assets.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

syntax-check[unknown-module]

couldn't resolve module/action 'ansible.builtin.cmd'. This often indicates a misspelling, missing collection, or incorrect module path.
ansible.builtin.cmd:
cmd: "just --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile publish-test-release"
when: is_pr
- name: "Upload Release Assets"
ansible.builtin.cmd:
cmd: "just --yes --working-directory {{ zuul.project.src_dir}} --just-file {{ zuul.project.src_dir}}/justfile publish-release"
when: not is_pr

0 comments on commit 078f6d0

Please sign in to comment.