Skip to content

Commit e58ec94

Browse files
committed
ci: improve fetch Core manifest workflow
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
1 parent c8d07ae commit e58ec94

File tree

8 files changed

+98
-83
lines changed

8 files changed

+98
-83
lines changed

.github/scripts/fetch-core-capi.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,75 @@
1-
name: Fetch core CAPI components manifest and embed in Turtles chart for air-gapped installations.
1+
name: Update Core CAPI components manifest
22
on:
3-
schedule:
4-
- cron: "0 0 * * *" # Run every day at midnight (UTC)
5-
# allow running manually on demand
63
workflow_dispatch:
4+
inputs:
5+
capi_version:
6+
type: string
7+
description: CAPI Core version (ex. 'v1.2.3' or empty for latest)
8+
required: false
9+
710

811
env:
912
TURTLES_REF: "${{ github.ref_name }}"
10-
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
13+
GH_TOKEN: "${{ github.token }}"
1114

1215
jobs:
1316
create-core-capi-turtles-pr:
1417
runs-on: ubuntu-latest
1518
permissions:
16-
contents: read
19+
pull-requests: write
20+
contents: write
1721
steps:
1822
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5
1923
with:
20-
ref: "${{ env.TURTLES_REF }}"
21-
token: ${{ env.GH_TOKEN }}
22-
# Allow making git push request later on
23-
persist-credentials: true
24+
fetch-depth: 0
2425

2526
- name: Configure the committer
2627
run: |
2728
user_id=$(gh api "/users/$APP_USER" --jq .id)
2829
git config --global user.name "$APP_USER"
2930
git config --global user.email "${user_id}+${APP_USER}@users.noreply.github.com"
3031
env:
31-
GH_TOKEN: "${{ env.GH_TOKEN }}"
3232
APP_USER: "${{ github.actor }}"
3333

3434
- name: Run script to fetch components manifest
3535
run: |
36-
CAPI_VERSION=$(curl -s "https://api.github.com/repos/rancher-sandbox/cluster-api/releases/latest" | jq -r ".tag_name")
37-
echo "CAPI_VERSION=${CAPI_VERSION}" >> $GITHUB_ENV
36+
CAPI_MANIFEST_UPDATE_VERSION=${{ inputs.capi_version }}
37+
if [ -z "${CAPI_MANIFEST_UPDATE_VERSION}" ]; then
38+
echo "Fetching latest CAPI Core version"
39+
CAPI_MANIFEST_UPDATE_VERSION=$(curl -s "https://api.github.com/repos/rancher-sandbox/cluster-api/releases/latest" | jq -r ".tag_name")
40+
echo "Found version ${CAPI_MANIFEST_UPDATE_VERSION}"
41+
fi
42+
echo "CAPI_MANIFEST_UPDATE_VERSION=${CAPI_MANIFEST_UPDATE_VERSION}" >> $GITHUB_ENV
3843
BRANCH="fetch-core-capi-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
3944
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
4045
git checkout -b "$BRANCH" "$TURTLES_REF"
41-
CAPI_VERSION=$CAPI_VERSION ./.github/scripts/fetch-core-capi.sh
46+
CAPI_MANIFEST_UPDATE_VERSION=${CAPI_MANIFEST_UPDATE_VERSION} make update-core-capi-manifest
4247
git add charts/rancher-turtles
4348
if git diff --cached --quiet; then
4449
echo "No changes detected"
4550
echo "SKIP_PUSH=true" >> $GITHUB_ENV
4651
else
47-
git commit -m "chore: embed core CAPI ${CAPI_VERSION} in Turtles chart"
52+
git commit -m "chore: embed core CAPI ${CAPI_MANIFEST_UPDATE_VERSION} in Turtles chart"
4853
echo "SKIP_PUSH=false" >> $GITHUB_ENV
4954
fi
5055
5156
- name: Push and create pull request
5257
if: env.SKIP_PUSH == 'false'
53-
env:
54-
GH_TOKEN: "${{ env.GH_TOKEN }}"
5558
run: |
5659
git push origin "$BRANCH"
57-
body="This PR fetches core CAPI $CAPI_VERSION components manifest from release and embeds the template in the Turtles chart for a simplified air-gapped installation."
60+
body="This PR fetches core CAPI ${CAPI_MANIFEST_UPDATE_VERSION} components manifest from release and embeds the template in the Turtles chart for a simplified air-gapped installation."
5861
5962
gh pr create \
60-
--title "chore: embed core CAPI provider $CAPI_VERSION manifest in chart" \
63+
--title "chore: embed core CAPI provider ${CAPI_MANIFEST_UPDATE_VERSION} manifest in chart" \
6164
--body "$body" \
6265
--head "${{ github.repository_owner }}:$BRANCH" \
6366
--base "$TURTLES_REF" \
6467
--label "area/installation" \
6568
--label "kind/ci"
69+
70+
- name: Collect run artifacts
71+
if: env.SKIP_PUSH == 'false'
72+
uses: actions/upload-artifact@v7
73+
with:
74+
name: update-core-capi-artifacts
75+
path: _artifacts

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ hack/crd/bases/*
3939
# helm
4040
**/Chart.lock
4141

42-
.buildx-cache/
42+
.buildx-cache/
43+
44+
# krew
45+
hack/tools/krew/*

Makefile

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ REPO ?= rancher/turtles
3939
CAPI_VERSION ?= $(shell grep "sigs.k8s.io/cluster-api" go.mod | head -1 |awk '{print $$NF}')
4040
CAPI_UPSTREAM_REPO ?= https://github.com/kubernetes-sigs/cluster-api
4141
CAPI_UPSTREAM_RELEASES ?= $(CAPI_UPSTREAM_REPO)/releases
42+
CAPI_MANIFEST_UPDATE_VERSION ?= $(shell curl -s "https://api.github.com/repos/rancher-sandbox/cluster-api/releases/latest" | jq -r ".tag_name")
43+
CAPI_MANIFEST_OUTPUT_FILE ?= $(CHART_DIR)/templates/core-provider-configmap.yaml
4244

4345
# Use GOPROXY environment variable if set
4446
GOPROXY := $(shell go env GOPROXY)
@@ -66,7 +68,9 @@ $(TOOLS_BIN_DIR):
6668
mkdir -p $@
6769

6870
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
69-
export KREW_ROOT := $(abspath $(TOOLS_BIN_DIR))
71+
72+
# Configure krew root directory to tools dir
73+
export KREW_ROOT := $(abspath $(TOOLS_DIR))/krew
7074
export PATH := $(KREW_ROOT)/bin:$(PATH)
7175

7276
# Set --output-base for conversion-gen if we are not within GOPATH
@@ -76,7 +80,6 @@ else
7680
export GOPATH := $(shell go env GOPATH)
7781
endif
7882

79-
8083
#
8184
# Ginkgo configuration.
8285
#
@@ -168,9 +171,6 @@ GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
168171
NOTES_BIN := notes
169172
NOTES := $(abspath $(TOOLS_BIN_DIR)/$(NOTES_BIN))
170173

171-
CRUST_GATHER_BIN := crust-gather
172-
CRUST_GATHER := $(abspath $(TOOLS_BIN_DIR)/$(CRUST_GATHER_BIN))
173-
174174
CHART_TESTING_VER := v3.14.0
175175

176176
# Registry / images
@@ -495,9 +495,6 @@ $(CONVERSION_GEN): # Build conversion-gen from tools folder.
495495
.PHONY: $(GINKGO_BIN)
496496
$(GINKGO_BIN): $(GINKGO) ## Build a local copy of ginkgo.
497497

498-
.PHONY: $(CRUST_GATHER_BIN)
499-
$(CRUST_GATHER_BIN): $(CRUST_GATHER) ## Download crust-gather.
500-
501498
$(GO_APIDIFF): # Build go-apidiff from tools folder.
502499
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GO_APIDIFF_PKG) $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)
503500

@@ -530,9 +527,6 @@ $(GH): # Download GitHub cli into the tools bin folder
530527
-b $(TOOLS_BIN_DIR) \
531528
$(GH_VERSION)
532529

533-
$(CRUST_GATHER): # Downloads and install crust-gather
534-
curl -sSfL https://github.com/crust-gather/crust-gather/raw/main/install.sh | sh -s - -f -b $(TOOLS_BIN_DIR)
535-
536530
kubectl: # Download kubectl cli into tools bin folder
537531
hack/ensure-kubectl.sh \
538532
-b $(TOOLS_BIN_DIR) \
@@ -727,5 +721,16 @@ clean-rancher-charts: ## Remove the local rancher charts folder
727721
## --------------------------------------
728722

729723
.PHONY: collect-artifacts
730-
collect-artifacts: $(CRUST_GATHER_BIN)
731-
$(CRUST_GATHER) collect -f $(ARTIFACTS_FOLDER)/gather
724+
collect-artifacts: kubectl
725+
mkdir -p $(ARTIFACTS_FOLDER)
726+
kubectl crust-gather collect -f $(ARTIFACTS_FOLDER)/gather
727+
728+
## --------------------------------------
729+
## Update the CAPI Core Provider manifest
730+
## --------------------------------------
731+
732+
.PHONY: update-core-capi-manifest
733+
update-core-capi-manifest: kubectl
734+
mkdir -p $(ARTIFACTS_FOLDER)
735+
ARTIFACTS_FOLDER=$(ARTIFACTS_FOLDER) CAPI_VERSION=$(CAPI_MANIFEST_UPDATE_VERSION) OUTPUT_FILE=$(CAPI_MANIFEST_OUTPUT_FILE) hack/fetch-core-capi.sh
736+

charts/rancher-turtles/templates/core-provider-configmap.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ kind: ConfigMap
5555
metadata:
5656
annotations:
5757
provider.cluster.x-k8s.io/compressed: "true"
58-
creationTimestamp: null
5958
labels:
60-
managed-by.operator.cluster.x-k8s.io: "true"
6159
provider.cluster.x-k8s.io/name: cluster-api
6260
provider.cluster.x-k8s.io/type: core
6361
provider.cluster.x-k8s.io/version: v1.12.2

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ module github.com/rancher/turtles
22

33
go 1.25.8
44

5+
ignore (
6+
./hack/tools/krew
7+
./out
8+
)
9+
510
require (
611
github.com/blang/semver/v4 v4.0.0
712
github.com/go-logr/logr v1.4.3

hack/ensure-kubectl.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ install_plugins() {
6666
tar zxvf "${KREW}.tar.gz" &&
6767
./"${KREW}" install krew
6868
)
69+
kubectl krew version
70+
6971
kubectl krew install crust-gather
72+
kubectl crust-gather --version
73+
74+
rm -rf ${KREW_ROOT}/index/operator # Clear the index to prevent errors and ensure update on next add
75+
kubectl krew index add operator https://github.com/kubernetes-sigs/cluster-api-operator.git
76+
kubectl krew install operator/clusterctl-operator
77+
kubectl operator version
7078
}
7179

7280
verify_kubectl_version

hack/fetch-core-capi.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# script-specific variables
4+
CAPI_VERSION="${CAPI_VERSION:-latest}"
5+
CAPI_RELEASE_URL="${CAPI_RELEASE_URL:-https://github.com/rancher-sandbox/cluster-api/releases/${CAPI_VERSION}/core-components.yaml}"
6+
CORE_CAPI_NAMESPACE="${CORE_CAPI_NAMESPACE:-cattle-capi-system}"
7+
OUTPUT_FILE="${OUTPUT_FILE:-/tmp/core-provider-configmap.yaml}"
8+
ARTIFACTS_FOLDER="${ARTIFACTS_FOLDER:-_artifacts}"
9+
10+
# parameters that must be substituted in CAPI manifest
11+
export CAPI_DIAGNOSTICS_ADDRESS=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}
12+
export CAPI_INSECURE_DIAGNOSTICS=${CAPI_INSECURE_DIAGNOSTICS:=false}
13+
export EXP_MACHINE_POOL=${EXP_MACHINE_POOL:=true}
14+
export EXP_CLUSTER_RESOURCE_SET=${EXP_CLUSTER_RESOURCE_SET:=true}
15+
export CLUSTER_TOPOLOGY=${CLUSTER_TOPOLOGY:=true}
16+
export EXP_RUNTIME_SDK=${EXP_RUNTIME_SDK:=false}
17+
export EXP_MACHINE_SET_PREFLIGHT_CHECKS=${EXP_MACHINE_SET_PREFLIGHT_CHECKS:=true}
18+
export EXP_MACHINE_WAITFORVOLUMEDETACH_CONSIDER_VOLUMEATTACHMENTS=${EXP_MACHINE_WAITFORVOLUMEDETACH_CONSIDER_VOLUMEATTACHMENTS:=true}
19+
export EXP_PRIORITY_QUEUE=${EXP_PRIORITY_QUEUE:=false}
20+
21+
# use CAPI Operator plugin to generate ConfigMap with core CAPI components
22+
kubectl operator preload --core cluster-api --target-namespace ${CORE_CAPI_NAMESPACE} -u ${CAPI_RELEASE_URL} > ${OUTPUT_FILE}
23+
# replace cluster-api-operator managed label with turtles
24+
yq -i 'del(.metadata.labels["managed-by.operator.cluster.x-k8s.io"])' ${OUTPUT_FILE}
25+
yq -i '.metadata.labels["managed-by.turtles.cattle.io"]="true"' ${OUTPUT_FILE}
26+
27+
# Dump the manifest in the artifacts directory
28+
if [ $(yq '.metadata.annotations["provider.cluster.x-k8s.io/compressed"]' ${OUTPUT_FILE}) = "true" ]; then
29+
echo "Dumping uncompressed manifest in ${ARTIFACTS_FOLDER}/core-manifest-update-dump.yaml"
30+
yq '.binaryData.components' ${OUTPUT_FILE} | base64 -d | gzip -d > ${ARTIFACTS_FOLDER}/core-manifest-update-dump.yaml
31+
else
32+
echo "Dumping manifest in ${ARTIFACTS_FOLDER}/core-manifest-update-dump.yaml"
33+
yq '.data.components' ${OUTPUT_FILE} > ${ARTIFACTS_FOLDER}/core-manifest-update-dump.yaml
34+
fi

0 commit comments

Comments
 (0)