Skip to content

Commit 3db697e

Browse files
scripts: detect latest Go/k8s patches and check operator-sdk release
After scaffolding, read the generated go.mod to detect the latest stable Go patch (go.dev) and k8s.io patch (module proxy). Also check the latest operator-sdk release on GitHub. Version reconciliation is CI-friendly (zero interactive input): - No pin in YAML: auto-pin detected version and update the file - Pin matches detected: all good - Pin is older: warn with the newer version, keep pinned value - Pin is newer than detected: warn, use detected Re-adds GOTOOLCHAIN export to Makefile patches (single hunk at end).
1 parent 17afab5 commit 3db697e

File tree

6 files changed

+317
-99
lines changed

6 files changed

+317
-99
lines changed

BUMPING.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,30 @@ This guide is applied for both `metalk8s-operator` and `storage-operator`.
132132

133133
- `go`, `curl`, and `patch` in `PATH`.
134134
- `pyyaml` Python package: `pip install pyyaml`
135+
- `GITHUB_TOKEN` (optional): raises the GitHub API rate limit from 60 to 5000
136+
req/hour. Set via `export GITHUB_TOKEN=<token>`.
135137

136138
### Updating the versions
137139

138-
Before running the script, update the target versions in the YAML config files at
139-
`scripts/upgrade-operator-sdk/<name>/config.yaml`:
140+
Target versions are pinned in `scripts/upgrade-operator-sdk/<name>/config.yaml`:
140141

141142
```yaml
142143
operator_sdk_version: v1.42.1 # target operator-sdk release
143-
go_toolchain: go1.25.8 # Go toolchain (for GOTOOLCHAIN + FROM golang:X.Y)
144-
k8s_libs: v0.33.9 # k8s.io/{api,apimachinery,client-go} version
144+
go_toolchain: go1.25.8 # pin Go toolchain (for GOTOOLCHAIN)
145+
k8s_libs: v0.33.9 # pin k8s.io libs version
145146
```
146147
147-
The script makes **no version-detection API calls**; all versions are read from the
148-
YAML config.
148+
After scaffolding, the script detects the latest available versions (operator-sdk
149+
from GitHub, Go and k8s.io patches from go.dev / module proxy) and compares with
150+
the pinned values:
151+
152+
- **No pin** in YAML: the detected version is used and auto-pinned in the file.
153+
- **Pin matches detected**: all good, no action.
154+
- **Pin is older** than detected: warning printed with the newer version available.
155+
The pinned value is still used. Update the YAML manually when ready.
156+
- **Pin is newer** than detected (unusual): warning, the detected value is used.
157+
158+
This is CI-friendly: zero interactive input during reconciliation.
149159
150160
### Running the upgrade
151161
@@ -173,9 +183,9 @@ Options:
173183
Each operator has a config directory at `scripts/upgrade-operator-sdk/<name>/` containing
174184
`config.yaml` and a `patches/` subdirectory. The config fields are:
175185

176-
- **Versions**: `operator_sdk_version`, `go_toolchain`, `k8s_libs`
186+
- **Versions**: `operator_sdk_version`, `go_toolchain` (optional pin), `k8s_libs` (optional pin)
177187
- **Scaffold**: `repo`, `domain`, `apis` (with `group`, `version`, `kind`, `namespaced`). The operator name is derived from the config directory name.
178-
- **Paths**: `operator_dir`, `patches_dir`, `backup_paths`
188+
- **Paths**: `operator_dir`, `backup_paths`
179189
- **Post-processing**: `image_placeholder`, `extra_commands`
180190

181191
### Patch files
@@ -187,12 +197,10 @@ look for `.rej` files and resolve manually.
187197

188198
Patch files use `__PLACEHOLDER__` tokens for values from the YAML config:
189199

190-
| Placeholder | Replaced with | Source |
191-
| ----------------- | -------------------------------------------- | ---------- |
192-
| `__GOTOOLCHAIN__` | `go_toolchain` from config (e.g. `go1.25.8`) | `Makefile` |
193-
| `__IMAGE__` | `image_placeholder` from config | `Makefile` |
194-
195-
The `FROM golang:X.Y` in `Dockerfile` is derived from `go_toolchain` in the config.
200+
| Placeholder | Replaced with | Source |
201+
| ----------------- | ------------------------------- | ---------- |
202+
| `__GOTOOLCHAIN__` | Detected/pinned Go toolchain | `Makefile` |
203+
| `__IMAGE__` | `image_placeholder` from config | `Makefile` |
196204

197205
New `.patch` files in the patches directory are automatically picked up.
198206

scripts/upgrade-operator-sdk/operator/config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ domain: metalk8s.scality.com
33
operator_dir: operator
44

55
operator_sdk_version: v1.42.1
6-
go_toolchain: go1.25.8
7-
k8s_libs: v0.33.9
6+
7+
# Optional: pin versions. If absent or empty, the script detects the
8+
# latest patch from the scaffold's go.mod and offers to update this file.
9+
go_toolchain: go1.24.13
10+
k8s_libs: v0.33.10
811

912
apis:
1013
- version: v1alpha1

scripts/upgrade-operator-sdk/operator/patches/Makefile.patch

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
--- a/Makefile
22
+++ b/Makefile
3-
@@ -1,2 +1,6 @@
4-
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
5-
+
6-
+# Force Go toolchain version to prevent automatic selection issues
7-
+# See: https://go.dev/doc/toolchain
8-
+export GOTOOLCHAIN = __GOTOOLCHAIN__
9-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
10-
@@ -4,3 +8,9 @@
3+
@@ -3,3 +3,12 @@
114
.PHONY: catalog-push
125
catalog-push: ## Push a catalog image.
136
$(MAKE) docker-push IMG=$(CATALOG_IMG)
147
+
8+
+# Force Go toolchain version
9+
+export GOTOOLCHAIN = __GOTOOLCHAIN__
10+
+
1511
+.PHONY: metalk8s
1612
+metalk8s: manifests kustomize ## Generate MetalK8s resulting manifests
1713
+ mkdir -p deploy

scripts/upgrade-operator-sdk/storage-operator/config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ domain: metalk8s.scality.com
33
operator_dir: storage-operator
44

55
operator_sdk_version: v1.42.1
6-
go_toolchain: go1.25.8
7-
k8s_libs: v0.33.9
6+
7+
# Optional: pin versions. If absent or empty, the script detects the
8+
# latest patch from the scaffold's go.mod and offers to update this file.
9+
go_toolchain: go1.24.13
10+
k8s_libs: v0.33.10
811

912
apis:
1013
- group: storage

scripts/upgrade-operator-sdk/storage-operator/patches/Makefile.patch

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
--- a/Makefile
22
+++ b/Makefile
3-
@@ -1,2 +1,6 @@
4-
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
5-
+
6-
+# Force Go toolchain version to prevent automatic selection issues
7-
+# See: https://go.dev/doc/toolchain
8-
+export GOTOOLCHAIN = __GOTOOLCHAIN__
9-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
10-
@@ -4,3 +8,9 @@
3+
@@ -3,3 +3,12 @@
114
.PHONY: catalog-push
125
catalog-push: ## Push a catalog image.
136
$(MAKE) docker-push IMG=$(CATALOG_IMG)
147
+
8+
+# Force Go toolchain version
9+
+export GOTOOLCHAIN = __GOTOOLCHAIN__
10+
+
1511
+.PHONY: metalk8s
1612
+metalk8s: manifests kustomize ## Generate MetalK8s resulting manifests
1713
+ mkdir -p deploy

0 commit comments

Comments
 (0)