From 352d42f1e390177aed8fedf0cfb0212d5e71bc71 Mon Sep 17 00:00:00 2001 From: Varsha Prasad Narsing Date: Wed, 12 Jun 2024 06:55:50 -0700 Subject: [PATCH] externalize handler interface implementation This would help in removing the duplicate handler interface implmentation in operator-controller. Signed-off-by: Varsha Prasad Narsing --- cmd/core/main.go | 5 +++-- cmd/helm/main.go | 3 ++- .../controllers/bundledeployment/bundledeployment.go | 11 ++++++----- .../bundledeployment => pkg/handler}/interfaces.go | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) rename {internal/controllers/bundledeployment => pkg/handler}/interfaces.go (95%) diff --git a/cmd/core/main.go b/cmd/core/main.go index 305d86e1..f3ecccbe 100644 --- a/cmd/core/main.go +++ b/cmd/core/main.go @@ -50,6 +50,7 @@ import ( "github.com/operator-framework/rukpak/internal/version" "github.com/operator-framework/rukpak/pkg/features" "github.com/operator-framework/rukpak/pkg/finalizer" + "github.com/operator-framework/rukpak/pkg/handler" "github.com/operator-framework/rukpak/pkg/preflights/crdupgradesafety" "github.com/operator-framework/rukpak/pkg/provisioner/plain" "github.com/operator-framework/rukpak/pkg/provisioner/registry" @@ -255,7 +256,7 @@ func main() { if err := bundledeployment.SetupWithManager(mgr, systemNamespace, append( commonBDProvisionerOptions, bundledeployment.WithProvisionerID(plain.ProvisionerID), - bundledeployment.WithHandler(bundledeployment.HandlerFunc(plain.HandleBundleDeployment)), + bundledeployment.WithHandler(handler.HandlerFunc(plain.HandleBundleDeployment)), )...); err != nil { setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha2.BundleDeploymentKind, "provisionerID", plain.ProvisionerID) os.Exit(1) @@ -264,7 +265,7 @@ func main() { if err := bundledeployment.SetupWithManager(mgr, systemNamespace, append( commonBDProvisionerOptions, bundledeployment.WithProvisionerID(registry.ProvisionerID), - bundledeployment.WithHandler(bundledeployment.HandlerFunc(registry.HandleBundleDeployment)), + bundledeployment.WithHandler(handler.HandlerFunc(registry.HandleBundleDeployment)), )...); err != nil { setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha2.BundleDeploymentKind, "provisionerID", registry.ProvisionerID) os.Exit(1) diff --git a/cmd/helm/main.go b/cmd/helm/main.go index 0d0a80c8..b7a5e982 100644 --- a/cmd/helm/main.go +++ b/cmd/helm/main.go @@ -44,6 +44,7 @@ import ( "github.com/operator-framework/rukpak/internal/controllers/bundledeployment" "github.com/operator-framework/rukpak/internal/version" "github.com/operator-framework/rukpak/pkg/finalizer" + "github.com/operator-framework/rukpak/pkg/handler" "github.com/operator-framework/rukpak/pkg/provisioner/helm" "github.com/operator-framework/rukpak/pkg/source" "github.com/operator-framework/rukpak/pkg/storage" @@ -232,7 +233,7 @@ func main() { if err := bundledeployment.SetupWithManager(mgr, systemNamespace, append( commonBDProvisionerOptions, bundledeployment.WithProvisionerID(helm.ProvisionerID), - bundledeployment.WithHandler(bundledeployment.HandlerFunc(helm.HandleBundleDeployment)), + bundledeployment.WithHandler(handler.HandlerFunc(helm.HandleBundleDeployment)), )...); err != nil { setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha2.BundleDeploymentKind, "provisionerID", helm.ProvisionerID) os.Exit(1) diff --git a/internal/controllers/bundledeployment/bundledeployment.go b/internal/controllers/bundledeployment/bundledeployment.go index b70d2c2b..ea4c6bfa 100644 --- a/internal/controllers/bundledeployment/bundledeployment.go +++ b/internal/controllers/bundledeployment/bundledeployment.go @@ -31,7 +31,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" crcontroller "sigs.k8s.io/controller-runtime/pkg/controller" crfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer" - "sigs.k8s.io/controller-runtime/pkg/handler" + crhandler "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/source" @@ -41,6 +41,7 @@ import ( rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2" "github.com/operator-framework/rukpak/internal/healthchecks" "github.com/operator-framework/rukpak/pkg/features" + "github.com/operator-framework/rukpak/pkg/handler" helmpredicate "github.com/operator-framework/rukpak/pkg/helm-operator-plugins/predicate" unpackersource "github.com/operator-framework/rukpak/pkg/source" "github.com/operator-framework/rukpak/pkg/storage" @@ -65,7 +66,7 @@ limitations under the License. type Option func(bd *controller) -func WithHandler(h Handler) Option { +func WithHandler(h handler.Handler) Option { return func(c *controller) { c.handler = h } @@ -182,7 +183,7 @@ type controller struct { cl client.Client cache cache.Cache - handler Handler + handler handler.Handler provisionerID string acg helmclient.ActionClientGetter storage storage.Storage @@ -413,11 +414,11 @@ func (c *controller) reconcile(ctx context.Context, bd *rukpakv1alpha2.BundleDep source.Kind( c.cache, unstructuredObj, - handler.TypedEnqueueRequestForOwner[*unstructured.Unstructured]( + crhandler.TypedEnqueueRequestForOwner[*unstructured.Unstructured]( c.cl.Scheme(), c.cl.RESTMapper(), bd, - handler.OnlyControllerOwner(), + crhandler.OnlyControllerOwner(), ), helmpredicate.DependentPredicateFuncs[*unstructured.Unstructured](), ), diff --git a/internal/controllers/bundledeployment/interfaces.go b/pkg/handler/interfaces.go similarity index 95% rename from internal/controllers/bundledeployment/interfaces.go rename to pkg/handler/interfaces.go index 955fd0d6..a69c3682 100644 --- a/internal/controllers/bundledeployment/interfaces.go +++ b/pkg/handler/interfaces.go @@ -1,4 +1,4 @@ -package bundledeployment +package handler import ( "context"