From 8dfec453ad2b7bafd3eec0b39b6185ff40d0108a Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Fri, 20 Oct 2023 12:59:08 +0200 Subject: [PATCH] remove deprecated funcs from controller-runtime s --- cmd/main.go | 20 ++++++++++------ .../subscription/eventmesh/test/utils.go | 23 +++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index c58a8ca5d..2d3acd819 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -28,35 +28,40 @@ import ( "github.com/go-logr/zapr" - "github.com/kyma-project/eventing-manager/pkg/env" subscriptionv1alpha1 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha1" subscriptionv1alpha2 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha2" + "github.com/kyma-project/eventing-manager/pkg/env" + "github.com/kyma-project/eventing-manager/pkg/subscriptionmanager/jetstream" "github.com/kyma-project/eventing-manager/pkg/eventing" "github.com/kyma-project/eventing-manager/pkg/k8s" + apiclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + eventingcontroller "github.com/kyma-project/eventing-manager/internal/controller/eventing" "github.com/kyma-project/eventing-manager/options" backendmetrics "github.com/kyma-project/eventing-manager/pkg/backend/metrics" "github.com/kyma-project/eventing-manager/pkg/logger" - apiclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. "k8s.io/client-go/dynamic" _ "k8s.io/client-go/plugin/pkg/client/auth" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" - - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" apigatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1" + eventingv1alpha1 "github.com/kyma-project/eventing-manager/api/v1alpha1" //+kubebuilder:scaffold:imports ) @@ -113,14 +118,15 @@ func main() { //nolint:funlen // main function needs to initialize many object // setup ctrl manager k8sRestCfg := ctrl.GetConfigOrDie() + mgr, err := ctrl.NewManager(k8sRestCfg, ctrl.Options{ Scheme: scheme, - MetricsBindAddress: opts.MetricsAddr, - Port: 9443, HealthProbeBindAddress: opts.ProbeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: leaderElectionID, - SyncPeriod: &opts.ReconcilePeriod, + WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}), + Cache: cache.Options{SyncPeriod: &opts.ReconcilePeriod}, + Metrics: server.Options{BindAddress: opts.MetricsAddr}, }) if err != nil { setupLog.Error(err, "unable to start manager") diff --git a/internal/controller/subscription/eventmesh/test/utils.go b/internal/controller/subscription/eventmesh/test/utils.go index 2fd3c9f7f..3921f6fc8 100644 --- a/internal/controller/subscription/eventmesh/test/utils.go +++ b/internal/controller/subscription/eventmesh/test/utils.go @@ -15,6 +15,8 @@ import ( "github.com/avast/retry-go/v3" "github.com/go-logr/zapr" + apigatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1" + kymalogger "github.com/kyma-project/kyma/common/logging/logger" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -25,13 +27,15 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" - apigatewayv1beta1 "github.com/kyma-incubator/api-gateway/api/v1beta1" - kymalogger "github.com/kyma-project/kyma/common/logging/logger" + eventingv1alpha2 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha2" eventmeshreconciler "github.com/kyma-project/eventing-manager/internal/controller/subscription/eventmesh" "github.com/kyma-project/eventing-manager/pkg/backend/cleaner" @@ -47,7 +51,6 @@ import ( "github.com/kyma-project/eventing-manager/pkg/utils" testutils "github.com/kyma-project/eventing-manager/test/utils" reconcilertesting "github.com/kyma-project/eventing-manager/testing" - eventingv1alpha2 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha2" ) type eventMeshTestEnsemble struct { @@ -117,13 +120,15 @@ func setupSuite() error { syncPeriod := syncPeriodSeconds * time.Second webhookInstallOptions := &emTestEnsemble.testEnv.WebhookInstallOptions k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{ - Scheme: scheme.Scheme, - SyncPeriod: &syncPeriod, - Host: webhookInstallOptions.LocalServingHost, - Port: webhookInstallOptions.LocalServingPort, - CertDir: webhookInstallOptions.LocalServingCertDir, - MetricsBindAddress: "0", // disable + Cache: cache.Options{SyncPeriod: &syncPeriod}, HealthProbeBindAddress: "0", // disable + Scheme: scheme.Scheme, + Metrics: server.Options{BindAddress: "0"}, // disable + WebhookServer: webhook.NewServer(webhook.Options{ + Port: webhookInstallOptions.LocalServingPort, + Host: webhookInstallOptions.LocalServingHost, + CertDir: webhookInstallOptions.LocalServingCertDir, + }), }) if err != nil { return err