You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
verify: tidy fmt generate manifests crd-ref-docs generate-test-data #HELP Verify all generated code is up-to-date.
157
+
verify: k8s-pin fmt generate manifests crd-ref-docs generate-test-data #HELP Verify all generated code is up-to-date. Runs k8s-pin instead of just tidy.
# Kubernetes Staging Module Version Synchronization Tool
2
+
3
+
## Purpose
4
+
This tool ensures that if `k8s.io/kubernetes` changes version in your `go.mod`, all related staging modules (e.g., `k8s.io/api`, `k8s.io/apimachinery`) are automatically pinned to the corresponding published version. Recent improvements include an environment variable override and refined logic for version resolution.
5
+
6
+
## How It Works
7
+
8
+
1.**Parsing and Filtering:**
9
+
- Reads and parses your `go.mod` file.
10
+
- Removes existing `replace` directives for `k8s.io/` modules to avoid stale mappings.
11
+
12
+
2.**Determine Kubernetes Version:**
13
+
-**Environment Variable Override:**
14
+
If the environment variable `K8S_IO_K8S_VERSION` is set, its value is validated (using semver standards) and used as the target version for `k8s.io/kubernetes`. The tool then runs `go get k8s.io/kubernetes@<version>` to update the dependency.
15
+
-**Default Behavior:**
16
+
If `K8S_IO_K8S_VERSION` is not set, the tool reads the version of `k8s.io/kubernetes` from the `go.mod` file.
17
+
18
+
3.**Compute the Target Staging Version:**
19
+
- Converts a Kubernetes version in the form `v1.xx.yy` into the staging version format `v0.xx.yy`.
20
+
- If the target staging version is unavailable, the tool attempts to fall back to the previous patch version.
21
+
22
+
4.**Updating Module Replace Directives:**
23
+
- Retrieves the full dependency graph using `go list -m -json all`.
24
+
- Identifies relevant `k8s.io/*` modules (skipping the main module and version-suffixed modules).
25
+
- Removes outdated `replace` directives (ignoring local path replacements).
26
+
- Adds new `replace` directives to pin modules—including `k8s.io/kubernetes`—to the computed staging version.
27
+
28
+
5.**Finalizing Changes:**
29
+
- Writes the updated `go.mod` file.
30
+
- Runs `go mod tidy` to clean up dependencies.
31
+
- Executes `go mod download k8s.io/kubernetes` to update `go.sum`.
32
+
- Logs any issues, such as modules remaining at an untagged version (`v0.0.0`), which may indicate upstream tagging problems.
33
+
34
+
## Environment Variables
35
+
36
+
-**K8S_IO_K8S_VERSION (optional):**
37
+
When set, this environment variable overrides the Kubernetes version found in `go.mod`. The tool validates this semver string, updates the dependency using `go get`, and processes modules accordingly.
38
+
39
+
## Additional Notes
40
+
41
+
- The tool ensures consistency across all `k8s.io/*` modules, even if they are not explicitly listed in `go.mod`.
42
+
- If a suitable staging version is not found, a warning is logged and the closest valid version is used.
43
+
- All operations are logged, which helps in troubleshooting and verifying the process.
0 commit comments