-
Notifications
You must be signed in to change notification settings - Fork 47
tools: add script to upgrade operator-sdk #4816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ezekiel-alexrod
wants to merge
12
commits into
development/133.0
Choose a base branch
from
improvement/tool-upgrade-operator-sdk
base: development/133.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1aeb5ab
scripts: add upgrade-operator-sdk.py
ezekiel-alexrod 7121a7d
scripts: fetch last patch for k8s go libraries
ezekiel-alexrod 669c94c
scripts: constants for regexp
ezekiel-alexrod 7e6dd52
scripts: update target python version to 3.10
ezekiel-alexrod 9569a9d
scripts: use scaffold Dockerfile and .golangci.yml instead of backup
ezekiel-alexrod 521bae0
scripts: corrected regex for Dockerfile
ezekiel-alexrod 800dc94
scripts: change strategy for GNU patch files
ezekiel-alexrod 17afab5
scripts: rewrite upgrade-operator-sdk as generic YAML-driven tool
ezekiel-alexrod 3db697e
scripts: detect latest Go/k8s patches and check operator-sdk release
ezekiel-alexrod 05260c0
scripts: address review round 4 -- operator_dir as CLI arg, raw_copy,…
ezekiel-alexrod 432380b
scripts,tools: move upgrade-operator-sdk to tools/ directory
ezekiel-alexrod ecda27e
scripts: address review round 5
ezekiel-alexrod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| repo: github.com/scality/metalk8s/operator | ||
| domain: metalk8s.scality.com | ||
| operator_dir: operator | ||
|
|
||
| operator_sdk_version: v1.42.1 | ||
| go_toolchain: go1.25.8 | ||
| k8s_libs: v0.33.9 | ||
|
|
||
| apis: | ||
| - version: v1alpha1 | ||
| kind: ClusterConfig | ||
| namespaced: false | ||
| - version: v1alpha1 | ||
| kind: VirtualIPPool | ||
| namespaced: true | ||
|
|
||
| backup_paths: | ||
ezekiel-alexrod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - pkg/ | ||
| - version/ | ||
| - config/metalk8s/ | ||
| - api/ | ||
ezekiel-alexrod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - hack/ | ||
ezekiel-alexrod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - internal/controller/ | ||
ezekiel-alexrod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| image_placeholder: '{{ build_image_name("metalk8s-operator") }}' | ||
|
|
||
| extra_commands: | ||
| - ["make", "metalk8s"] | ||
65 changes: 65 additions & 0 deletions
65
scripts/upgrade-operator-sdk/operator/patches/Dockerfile.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- a/Dockerfile | ||
| +++ b/Dockerfile | ||
| @@ -15,13 +15,20 @@ | ||
| COPY cmd/main.go cmd/main.go | ||
| COPY api/ api/ | ||
| COPY internal/ internal/ | ||
| +COPY pkg/ pkg/ | ||
| +COPY version/ version/ | ||
| + | ||
| +# Version of the project, e.g. `git describe --always --long --dirty --broken` | ||
| +ARG METALK8S_VERSION | ||
|
|
||
| # Build | ||
| # the GOARCH has not a default value to allow the binary be built according to the host where the command | ||
| # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO | ||
| # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, | ||
| # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. | ||
| -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go | ||
| +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager \ | ||
| + -ldflags "-X 'github.com/scality/metalk8s/operator/version.Version=${METALK8S_VERSION}'" \ | ||
| + cmd/main.go | ||
|
|
||
| # Use distroless as minimal base image to package the manager binary | ||
| # Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
| @@ -31,3 +38,40 @@ | ||
| USER 65532:65532 | ||
|
|
||
| ENTRYPOINT ["/manager"] | ||
| + | ||
| +# Timestamp of the build, formatted as RFC3339 | ||
| +ARG BUILD_DATE | ||
| +# Git revision o the tree at build time | ||
| +ARG VCS_REF | ||
| +# Version of the image | ||
| +ARG VERSION | ||
| +# Version of the project, e.g. `git describe --always --long --dirty --broken` | ||
| +ARG METALK8S_VERSION | ||
| + | ||
| +# These contain BUILD_DATE so should come 'late' for layer caching | ||
| +LABEL maintainer="squad-metalk8s@scality.com" \ | ||
| + # http://label-schema.org/rc1/ | ||
| + org.label-schema.build-date="$BUILD_DATE" \ | ||
| + org.label-schema.name="metalk8s-operator" \ | ||
| + org.label-schema.description="Kubernetes Operator for managing MetalK8s cluster config" \ | ||
| + org.label-schema.url="https://github.com/scality/metalk8s/" \ | ||
| + org.label-schema.vcs-url="https://github.com/scality/metalk8s.git" \ | ||
| + org.label-schema.vcs-ref="$VCS_REF" \ | ||
| + org.label-schema.vendor="Scality" \ | ||
| + org.label-schema.version="$VERSION" \ | ||
| + org.label-schema.schema-version="1.0" \ | ||
| + # https://github.com/opencontainers/image-spec/blob/master/annotations.md | ||
| + org.opencontainers.image.created="$BUILD_DATE" \ | ||
| + org.opencontainers.image.authors="squad-metalk8s@scality.com" \ | ||
| + org.opencontainers.image.url="https://github.com/scality/metalk8s/" \ | ||
| + org.opencontainers.image.source="https://github.com/scality/metalk8s.git" \ | ||
| + org.opencontainers.image.version="$VERSION" \ | ||
| + org.opencontainers.image.revision="$VCS_REF" \ | ||
| + org.opencontainers.image.vendor="Scality" \ | ||
| + org.opencontainers.image.title="metalk8s-operator" \ | ||
| + org.opencontainers.image.description="Kubernetes Operator for managing MetalK8s cluster config" \ | ||
| + # https://docs.openshift.org/latest/creating_images/metadata.html | ||
| + io.openshift.tags="metalk8s,operator" \ | ||
| + io.k8s.description="Kubernetes Operator for managing MetalK8s cluster config" \ | ||
| + # Various | ||
| + com.scality.metalk8s.version="$METALK8S_VERSION" |
19 changes: 19 additions & 0 deletions
19
scripts/upgrade-operator-sdk/operator/patches/Makefile.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- a/Makefile | ||
| +++ b/Makefile | ||
| @@ -1,2 +1,6 @@ | ||
| #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) | ||
| + | ||
| +# Force Go toolchain version to prevent automatic selection issues | ||
| +# See: https://go.dev/doc/toolchain | ||
| +export GOTOOLCHAIN = __GOTOOLCHAIN__ | ||
| ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') | ||
| @@ -4,3 +8,9 @@ | ||
| .PHONY: catalog-push | ||
| catalog-push: ## Push a catalog image. | ||
| $(MAKE) docker-push IMG=$(CATALOG_IMG) | ||
| + | ||
| +.PHONY: metalk8s | ||
| +metalk8s: manifests kustomize ## Generate MetalK8s resulting manifests | ||
| + mkdir -p deploy | ||
| + $(KUSTOMIZE) build config/metalk8s | \ | ||
| + sed 's/BUILD_IMAGE_CLUSTER_OPERATOR:latest/__IMAGE__/' > deploy/manifests.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Linting and formatting configuration for scripts/upgrade-operator-sdk/upgrade.py | ||
| # Run from the scripts/ directory: | ||
| # python3 -m black upgrade-operator-sdk/upgrade.py | ||
| # python3 -m ruff check upgrade-operator-sdk/upgrade.py | ||
| # python3 -m mypy upgrade-operator-sdk/upgrade.py | ||
|
|
||
| [tool.black] | ||
| line-length = 88 | ||
| target-version = ["py310"] | ||
|
|
||
| [tool.ruff] | ||
| line-length = 88 | ||
| target-version = "py310" | ||
|
|
||
| [tool.ruff.lint] | ||
| select = [ | ||
| "E", # pycodestyle errors | ||
| "W", # pycodestyle warnings | ||
| "F", # pyflakes (undefined names, unused imports, …) | ||
| "I", # isort (import ordering) | ||
| "N", # pep8-naming conventions | ||
| "UP", # pyupgrade (modernise Python syntax) | ||
| "B", # flake8-bugbear (likely bugs and design issues) | ||
| "C4", # flake8-comprehensions (better list/dict/set comprehensions) | ||
| "SIM", # flake8-simplify (simplifiable code patterns) | ||
| "RET", # flake8-return (return statement issues) | ||
| "PTH", # flake8-use-pathlib (prefer pathlib over os.path) | ||
| "TRY", # tryceratops (exception handling anti-patterns) | ||
| ] | ||
| ignore = [ | ||
| "RET504", # allow x = ...; return x (readability) | ||
| "TRY003", # allow long messages in raise/die() calls | ||
| "TRY300", # allow return inside try block | ||
| ] | ||
|
|
||
| [tool.mypy] | ||
| strict = true | ||
| ignore_missing_imports = true | ||
| python_version = "3.10" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| repo: github.com/scality/metalk8s/storage-operator | ||
| domain: metalk8s.scality.com | ||
| operator_dir: storage-operator | ||
|
|
||
| operator_sdk_version: v1.42.1 | ||
| go_toolchain: go1.25.8 | ||
| k8s_libs: v0.33.9 | ||
|
|
||
| apis: | ||
| - group: storage | ||
| version: v1alpha1 | ||
| kind: Volume | ||
| namespaced: false | ||
|
|
||
| backup_paths: | ||
| - api/ | ||
| - hack/ | ||
| - internal/controller/ | ||
| - config/metalk8s/ | ||
| - salt/ | ||
|
|
||
| image_placeholder: '{{ build_image_name("storage-operator") }}' | ||
|
|
||
| extra_commands: | ||
| - ["make", "metalk8s"] |
51 changes: 51 additions & 0 deletions
51
scripts/upgrade-operator-sdk/storage-operator/patches/Dockerfile.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- a/Dockerfile | ||
| +++ b/Dockerfile | ||
| @@ -15,6 +15,7 @@ | ||
| COPY cmd/main.go cmd/main.go | ||
| COPY api/ api/ | ||
| COPY internal/ internal/ | ||
| +COPY salt/ salt/ | ||
|
|
||
| # Build | ||
| # the GOARCH has not a default value to allow the binary be built according to the host where the command | ||
| @@ -31,3 +32,40 @@ | ||
| USER 65532:65532 | ||
|
|
||
| ENTRYPOINT ["/manager"] | ||
| + | ||
| +# Timestamp of the build, formatted as RFC3339 | ||
| +ARG BUILD_DATE | ||
| +# Git revision o the tree at build time | ||
| +ARG VCS_REF | ||
| +# Version of the image | ||
| +ARG VERSION | ||
| +# Version of the project, e.g. `git describe --always --long --dirty --broken` | ||
| +ARG METALK8S_VERSION | ||
| + | ||
| +# These contain BUILD_DATE so should come 'late' for layer caching | ||
| +LABEL maintainer="squad-metalk8s@scality.com" \ | ||
| + # http://label-schema.org/rc1/ | ||
| + org.label-schema.build-date="$BUILD_DATE" \ | ||
| + org.label-schema.name="storage-operator" \ | ||
| + org.label-schema.description="Kubernetes Operator for managing PersistentVolumes in MetalK8s" \ | ||
| + org.label-schema.url="https://github.com/scality/metalk8s/" \ | ||
| + org.label-schema.vcs-url="https://github.com/scality/metalk8s.git" \ | ||
| + org.label-schema.vcs-ref="$VCS_REF" \ | ||
| + org.label-schema.vendor="Scality" \ | ||
| + org.label-schema.version="$VERSION" \ | ||
| + org.label-schema.schema-version="1.0" \ | ||
| + # https://github.com/opencontainers/image-spec/blob/master/annotations.md | ||
| + org.opencontainers.image.created="$BUILD_DATE" \ | ||
| + org.opencontainers.image.authors="squad-metalk8s@scality.com" \ | ||
| + org.opencontainers.image.url="https://github.com/scality/metalk8s/" \ | ||
| + org.opencontainers.image.source="https://github.com/scality/metalk8s.git" \ | ||
| + org.opencontainers.image.version="$VERSION" \ | ||
| + org.opencontainers.image.revision="$VCS_REF" \ | ||
| + org.opencontainers.image.vendor="Scality" \ | ||
| + org.opencontainers.image.title="storage-operator" \ | ||
| + org.opencontainers.image.description="Kubernetes Operator for managing PersistentVolumes in MetalK8s" \ | ||
| + # https://docs.openshift.org/latest/creating_images/metadata.html | ||
| + io.openshift.tags="metalk8s,storage,operator" \ | ||
| + io.k8s.description="Kubernetes Operator for managing PersistentVolumes in MetalK8s" \ | ||
| + # Various | ||
| + com.scality.metalk8s.version="$METALK8S_VERSION" |
19 changes: 19 additions & 0 deletions
19
scripts/upgrade-operator-sdk/storage-operator/patches/Makefile.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- a/Makefile | ||
| +++ b/Makefile | ||
| @@ -1,2 +1,6 @@ | ||
| #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) | ||
| + | ||
| +# Force Go toolchain version to prevent automatic selection issues | ||
| +# See: https://go.dev/doc/toolchain | ||
| +export GOTOOLCHAIN = __GOTOOLCHAIN__ | ||
| ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') | ||
| @@ -4,3 +8,9 @@ | ||
| .PHONY: catalog-push | ||
| catalog-push: ## Push a catalog image. | ||
| $(MAKE) docker-push IMG=$(CATALOG_IMG) | ||
| + | ||
| +.PHONY: metalk8s | ||
| +metalk8s: manifests kustomize ## Generate MetalK8s resulting manifests | ||
| + mkdir -p deploy | ||
| + $(KUSTOMIZE) build config/metalk8s | \ | ||
| + sed 's/BUILD_IMAGE_CLUSTER_OPERATOR:latest/__IMAGE__/' > deploy/manifests.yaml |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.