-
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.
+3,090
−11
Open
Changes from 11 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,33 @@ | ||
| repo: github.com/scality/metalk8s/operator | ||
| domain: metalk8s.scality.com | ||
|
|
||
| operator_sdk_version: v1.42.1 | ||
|
|
||
| # Optional: pin versions. If absent, the script detects the latest | ||
| # patch from the scaffold's go.mod and auto-pins them here. | ||
| go_toolchain: go1.24.13 | ||
| k8s_libs: v0.33.10 | ||
|
|
||
| apis: | ||
| - version: v1alpha1 | ||
| kind: ClusterConfig | ||
| namespaced: false | ||
| - version: v1alpha1 | ||
| kind: VirtualIPPool | ||
| namespaced: true | ||
|
|
||
| # Directories/files copied as-is from backup (purely custom, no scaffold equivalent). | ||
| raw_copy: | ||
| - pkg | ||
| - version | ||
| - config/metalk8s | ||
| - api/v1alpha1/conditions.go | ||
| - api/v1alpha1/conditions_test.go | ||
| - api/v1alpha1/clusterconfig_types_test.go | ||
| - api/v1alpha1/virtualippool_types_test.go | ||
| - api/v1alpha1/v1alpha1_suite_test.go | ||
|
|
||
| image_placeholder: '{{ build_image_name("metalk8s-operator") }}' | ||
|
|
||
| extra_commands: | ||
| - ["make", "metalk8s"] |
65 changes: 65 additions & 0 deletions
65
tools/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" |
15 changes: 15 additions & 0 deletions
15
tools/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,15 @@ | ||
| --- a/Makefile | ||
| +++ b/Makefile | ||
| @@ -3,3 +3,12 @@ | ||
| .PHONY: catalog-push | ||
| catalog-push: ## Push a catalog image. | ||
| $(MAKE) docker-push IMG=$(CATALOG_IMG) | ||
| + | ||
| +# Force Go toolchain version | ||
| +export GOTOOLCHAIN = __GOTOOLCHAIN__ | ||
| + | ||
| +.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 |
73 changes: 73 additions & 0 deletions
73
tools/upgrade-operator-sdk/operator/patches/clusterconfig_controller.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,73 @@ | ||
| --- a/internal/controller/clusterconfig_controller.go | ||
| +++ b/internal/controller/clusterconfig_controller.go | ||
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| -Copyright 2026. | ||
| +Copyright 2022. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| @@ -17,14 +17,10 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| - "context" | ||
| - | ||
| + "github.com/scality/metalk8s/operator/pkg/controller/clusterconfig" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| - logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| - | ||
| - metalk8sscalitycomv1alpha1 "github.com/scality/metalk8s/operator/api/v1alpha1" | ||
| ) | ||
|
|
||
| // ClusterConfigReconciler reconciles a ClusterConfig object | ||
| @@ -33,9 +29,13 @@ | ||
| Scheme *runtime.Scheme | ||
| } | ||
|
|
||
| -// +kubebuilder:rbac:groups=metalk8s.scality.com,resources=clusterconfigs,verbs=get;list;watch;create;update;patch;delete | ||
| -// +kubebuilder:rbac:groups=metalk8s.scality.com,resources=clusterconfigs/status,verbs=get;update;patch | ||
| -// +kubebuilder:rbac:groups=metalk8s.scality.com,resources=clusterconfigs/finalizers,verbs=update | ||
| +//+kubebuilder:rbac:groups=metalk8s.scality.com,resources=clusterconfigs,verbs=get;list;watch;create;update;patch;delete | ||
| +//+kubebuilder:rbac:groups=metalk8s.scality.com,resources=clusterconfigs/status,verbs=get;update;patch | ||
| +//+kubebuilder:rbac:groups=metalk8s.scality.com,resources=clusterconfigs/finalizers,verbs=update | ||
ezekiel-alexrod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + | ||
| +//+kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch;create;update;patch;delete | ||
| +//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch | ||
| +//+kubebuilder:rbac:groups=metalk8s.scality.com,resources=virtualippools,verbs=get;list;watch;create;update;patch;delete | ||
|
|
||
| // Reconcile is part of the main kubernetes reconciliation loop which aims to | ||
| // move the current state of the cluster closer to the desired state. | ||
| @@ -45,19 +45,18 @@ | ||
| // the user. | ||
| // | ||
| // For more details, check Reconcile and its Result here: | ||
| -// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.21.0/pkg/reconcile | ||
| -func (r *ClusterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
| - _ = logf.FromContext(ctx) | ||
| - | ||
| - // TODO(user): your logic here | ||
| - | ||
| - return ctrl.Result{}, nil | ||
| -} | ||
| +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.1/pkg/reconcile | ||
| +//func (r *ClusterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
| +// _ = log.FromContext(ctx) | ||
| +// | ||
| +// return ctrl.Result{}, nil | ||
| +//} | ||
|
|
||
| // SetupWithManager sets up the controller with the Manager. | ||
| func (r *ClusterConfigReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
| - return ctrl.NewControllerManagedBy(mgr). | ||
| - For(&metalk8sscalitycomv1alpha1.ClusterConfig{}). | ||
| - Named("clusterconfig"). | ||
| - Complete(r) | ||
| + return clusterconfig.Add(mgr) | ||
| + | ||
| + //return ctrl.NewControllerManagedBy(mgr). | ||
| + // For(&metalk8sscalitycomv1alpha1.ClusterConfig{}). | ||
| + // Complete(r) | ||
| } | ||
87 changes: 87 additions & 0 deletions
87
tools/upgrade-operator-sdk/operator/patches/clusterconfig_controller_test.patch
ezekiel-alexrod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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,87 @@ | ||
| --- a/internal/controller/clusterconfig_controller_test.go | ||
| +++ b/internal/controller/clusterconfig_controller_test.go | ||
| @@ -1,84 +1 @@ | ||
| -/* | ||
| -Copyright 2026. | ||
| - | ||
| -Licensed under the Apache License, Version 2.0 (the "License"); | ||
| -you may not use this file except in compliance with the License. | ||
| -You may obtain a copy of the License at | ||
| - | ||
| - http://www.apache.org/licenses/LICENSE-2.0 | ||
| - | ||
| -Unless required by applicable law or agreed to in writing, software | ||
| -distributed under the License is distributed on an "AS IS" BASIS, | ||
| -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| -See the License for the specific language governing permissions and | ||
| -limitations under the License. | ||
| -*/ | ||
| - | ||
| package controller | ||
| - | ||
| -import ( | ||
| - "context" | ||
| - | ||
| - . "github.com/onsi/ginkgo/v2" | ||
| - . "github.com/onsi/gomega" | ||
| - "k8s.io/apimachinery/pkg/api/errors" | ||
| - "k8s.io/apimachinery/pkg/types" | ||
| - "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
| - | ||
| - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| - | ||
| - metalk8sscalitycomv1alpha1 "github.com/scality/metalk8s/operator/api/v1alpha1" | ||
| -) | ||
| - | ||
| -var _ = Describe("ClusterConfig Controller", func() { | ||
| - Context("When reconciling a resource", func() { | ||
| - const resourceName = "test-resource" | ||
| - | ||
| - ctx := context.Background() | ||
| - | ||
| - typeNamespacedName := types.NamespacedName{ | ||
| - Name: resourceName, | ||
| - Namespace: "default", // TODO(user):Modify as needed | ||
| - } | ||
| - clusterconfig := &metalk8sscalitycomv1alpha1.ClusterConfig{} | ||
| - | ||
| - BeforeEach(func() { | ||
| - By("creating the custom resource for the Kind ClusterConfig") | ||
| - err := k8sClient.Get(ctx, typeNamespacedName, clusterconfig) | ||
| - if err != nil && errors.IsNotFound(err) { | ||
| - resource := &metalk8sscalitycomv1alpha1.ClusterConfig{ | ||
| - ObjectMeta: metav1.ObjectMeta{ | ||
| - Name: resourceName, | ||
| - Namespace: "default", | ||
| - }, | ||
| - // TODO(user): Specify other spec details if needed. | ||
| - } | ||
| - Expect(k8sClient.Create(ctx, resource)).To(Succeed()) | ||
| - } | ||
| - }) | ||
| - | ||
| - AfterEach(func() { | ||
| - // TODO(user): Cleanup logic after each test, like removing the resource instance. | ||
| - resource := &metalk8sscalitycomv1alpha1.ClusterConfig{} | ||
| - err := k8sClient.Get(ctx, typeNamespacedName, resource) | ||
| - Expect(err).NotTo(HaveOccurred()) | ||
| - | ||
| - By("Cleanup the specific resource instance ClusterConfig") | ||
| - Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) | ||
| - }) | ||
| - It("should successfully reconcile the resource", func() { | ||
| - By("Reconciling the created resource") | ||
| - controllerReconciler := &ClusterConfigReconciler{ | ||
| - Client: k8sClient, | ||
| - Scheme: k8sClient.Scheme(), | ||
| - } | ||
| - | ||
| - _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ | ||
| - NamespacedName: typeNamespacedName, | ||
| - }) | ||
| - Expect(err).NotTo(HaveOccurred()) | ||
| - // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. | ||
| - // Example: If you expect a certain status condition after reconciliation, verify it here. | ||
| - }) | ||
| - }) | ||
| -}) |
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.