Skip to content

Commit b19add3

Browse files
committed
Update README.md to account for changes
Signed-off-by: Brett Tofel <[email protected]>
1 parent 0195c72 commit b19add3

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

hack/tools/k8smaintainer/README.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
# Kubernetes Staging Module Version Synchronization Tool
22

33
## 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.
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.
55

66
## How It Works
77

8-
1. **Parse and Filter:**
9-
- Reads and parses your `go.mod`.
10-
- Removes any existing `replace` directives referencing `k8s.io/`, ensuring no stale mappings persist.
11-
12-
2. **Find Kubernetes Version & Compute Staging Version:**
13-
- Identifies the pinned `k8s.io/kubernetes` version in the `require` block.
14-
- Converts `"v1.xx.yy"` to `"v0.xx.yy"` to determine the correct version for staging modules.
15-
16-
3. **List All Modules in the Graph:**
17-
- Runs `go list -m -json all` to get the full dependency tree.
18-
- Extracts all `k8s.io/*` modules, ensuring completeness.
19-
20-
4. **Pin Staging Modules:**
21-
- For each `k8s.io/*` module (except `k8s.io/kubernetes`):
22-
- If it has a `v0.0.0` version (indicating it’s untagged) or its version doesn’t match the computed published version, the tool updates the `replace` directive accordingly.
23-
- Ensures `k8s.io/kubernetes` itself has a `replace` entry for consistency.
24-
25-
5. **Write & Finalize:**
26-
- Writes the updated `go.mod`.
27-
- Runs `go mod tidy` to clean up any dangling dependencies.
28-
- Runs `go mod download k8s.io/kubernetes` to guarantee required entries in `go.sum`.
29-
- Performs a final check that no modules remain at `v0.0.0`.
30-
31-
## Behavior When Kubernetes Version Changes
32-
- If you manually update `k8s.io/kubernetes` (e.g., from `v1.32.2` to `v1.32.1`) and rerun this tool:
33-
- The tool detects the new version and calculates the corresponding staging version (`v0.32.1`).
34-
- It updates all staging modules (`k8s.io/*`) to match the new version, ensuring consistency.
35-
- Any outdated `replace` directives are removed and replaced with the correct version.
36-
37-
## Additional Checks & Safeguards
38-
- **Missing `go.sum` Entries:** If `go list -m -json all` fails due to missing entries, the tool runs `go mod download` to ensure completeness.
39-
- **Conflicting Pinned Versions:** The tool enforces replace directives, but transitive dependencies may still cause conflicts that require manual resolution.
40-
- **Modules Introduced/Removed in Certain Versions:** If a required module no longer exists in a given Kubernetes version, manual intervention may be needed.
41-
42-
## Notes
43-
- Ensures all `k8s.io/*` modules are treated consistently, even if they were not explicitly listed in `go.mod`.
44-
- Warns if any module remains pinned at `v0.0.0`, which could indicate an issue with upstream tagging.
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

Comments
 (0)