tools: add script to upgrade operator-sdk#4816
tools: add script to upgrade operator-sdk#4816ezekiel-alexrod wants to merge 12 commits intodevelopment/133.0from
Conversation
Add a script to upgrade the operator-sdk It detects the latest compatible versions of operator-sdk, Go toolchain and golangci-lint from their respective public APIs, scaffolds fresh projects, and merges the existing custom code back. It applies to both `operator/` and `storage-operator/`. Closes: MK8S-190
Hello ezekiel-alexrod,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
Keep scaffold-generated versions for Dockerfile and .golangci.yml, applying MetalK8s customizations programmatically on top (extra COPY layers, ldflags, LABEL block) via a new DockerfilePatch dataclass. This ensures upstream scaffold improvements are picked up automatically on future upgrades. Also cleans up redundant entries (.devcontainer, cover.out) from the merge policy and removes the golangci-lint install/migrate logic.
2657ffa to
9569a9d
Compare
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
3c7cbaf to
800dc94
Compare
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
Replace the monolithic script with a generic, config-driven tool that takes an operator directory as argument. Each operator has its own config.yaml and patches/ directory under scripts/upgrade-operator-sdk/. All versions (operator-sdk, Go toolchain, k8s.io libs) are now pinned in the YAML config — the script makes no API calls for version detection. Key changes per review feedback: - YAML config per operator instead of hardcoded OPERATORS dict - GNU patch files for scaffold customizations (Dockerfile, Makefile) - Inclusion-list merge (backup_paths) instead of exclusion-list - No global mutable state (VersionInfo removed) - No SourceFix mechanism (manual fixes by the developer) - API scope (--namespaced) configurable per CRD - Empty group hack removed (operator-sdk v1.42.1 supports it) - Backup/scaffold file conflicts shown as errors with diff - Extra commands (make metalk8s) configurable in YAML
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
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).
TeddyAndrieux
left a comment
There was a problem hiding this comment.
I would suggest also to move this to tools it has nothing to do with scripts (this directory is for scripts that will be used by the end user not by the developers)
… new patches
- Move operator_dir from YAML config to --operator-dir CLI argument
- Remove REPO_ROOT and __file__-based path deduction (KISS)
- Rename backup_paths to raw_copy, reduce to purely custom dirs
(pkg/, version/, config/metalk8s/, salt/)
- Generate patch files for CRD types and controllers (previously
raw-copied from backup, now scaffold + patch)
- Remove Dockerfile modification (scaffold FROM golang is kept as-is)
- Fail on missing raw_copy paths instead of warning
- Use Path.is_dir() instead of endswith("/") convention
- Remove zz_generated filtering (no longer needed)
- Neutralize scaffold-generated controller tests via patches
(incompatible with our delegation pattern, never used)
- Add --forward flag to patch command to avoid false "reversed patch"
e8f96e9 to
05260c0
Compare
tools/upgrade-operator-sdk/operator/patches/clusterconfig_controller.patch
Outdated
Show resolved
Hide resolved
tools/upgrade-operator-sdk/operator/patches/clusterconfig_controller.patch
Outdated
Show resolved
Hide resolved
tools/upgrade-operator-sdk/operator/patches/clusterconfig_controller_test.patch
Outdated
Show resolved
Hide resolved
9638577 to
a85a05f
Compare
- Hardcode Jinja build_image_name() directly in Makefile patches, remove __IMAGE__ placeholder and image_placeholder config field - Add 'delete' config field to remove scaffold files (replaces hardcoded .devcontainer removal and controller_test patches) - Simplify controller patches: keep scaffold kubebuilder marker format, remove Copyright changes and commented-out code - Improve raw_copy directory handling: diff and skip if identical, error with diff if different (idempotent re-runs) - Remove auto-pin of YAML config (never modify the config file) - Remove _update_yaml() function (no longer needed) - Fix f-string formatting per review suggestions - Sync BUMPING.md: remove stale image_placeholder references
a85a05f to
ecda27e
Compare
|
/approve |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: The following options are set: approve |
Add tool to upgrade operator-sdk projects
Summary
A generic, config-driven tool that automates operator-sdk upgrades by scaffolding
fresh projects and applying customizations via GNU patch files. Designed to be
reusable across repositories.
Closes: MK8S-190
Execution flow
flowchart TD A["Load config.yaml"] --> B["Confirm upgrade (--yes to skip)"] B --> C["Install operator-sdk (cached)"] C --> D["Phase 1: Backup operator/ → operator.bak/"] D --> E["Phase 2: Scaffold fresh project"] E --> E1["operator-sdk init + create api"] E1 --> E2["Delete unwanted files (delete config)"] E2 --> F["Phase 2b: Detect latest versions"] F --> F1["operator-sdk: GitHub releases/latest"] F --> F2["Go toolchain: go.dev latest patch"] F --> F3["k8s.io libs: module proxy latest patch"] F1 & F2 & F3 --> G["Reconcile: compare detected vs pinned"] G --> H["Phase 3: Restore custom code (raw_copy)"] H --> I["Phase 4: Apply patch files"] I --> J["Substitute __GOTOOLCHAIN__ placeholder"] J --> K["Phase 5: go get k8s.io + go mod tidy"] K --> L["make manifests generate"] L --> M["make fmt vet"] M --> N["Extra commands (make metalk8s)"] N --> O["Upgrade complete"]Usage
python3 tools/upgrade-operator-sdk/upgrade.py \ --operator-dir operator \ tools/upgrade-operator-sdk/operator python3 tools/upgrade-operator-sdk/upgrade.py \ --operator-dir storage-operator \ tools/upgrade-operator-sdk/storage-operator--operator-dir--skip-backup.bakdirectory--clean-tools--yes, -yGITHUB_TOKENPrerequisites:
go,curl,patch,pyyamlConfiguration
Each operator has a config directory with
config.yamlandpatches/:config.yaml fields
operator_sdk_versionv1.42.1)repooperator-sdk init --repodomainoperator-sdk init --domainapisgroup,version,kind,namespacedgo_toolchaingo1.24.13). If absent, detected from go.devk8s_libsv0.33.10). If absent, detected from module proxyraw_copydeleteextra_commandsmake fmt vet(e.g.["make", "metalk8s"])Version reconciliation (CI-friendly)
After scaffolding, the tool queries go.dev, the Go module proxy, and GitHub to detect the latest available versions. It compares them with the YAML pins:
Zero interactive input during reconciliation -- safe for CI.
Design decisions
diff -ufiles, readable and editable without understanding the Python coderaw_copyfor purely custom code: only dirs/files with no scaffold equivalent are copied from backup; everything else uses patchesdeleteconfig field: configurable removal of scaffold files (.devcontainer,.github, incompatible test stubs)--operator-diras CLI arg: not in the YAML, so the tool works from any directory__GOTOOLCHAIN__placeholder: only runtime placeholder, detected dynamically (latest Go patch from go.dev) and substituted in the MakefileMakefile.patchcontains its ownbuild_image_name()call directly, no placeholder needed--forwardflag onpatch: prevents false "reversed patch" detection on patches that remove most of a file's content