Skip to content

Commit

Permalink
remove deprecated funcs from controller-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichwilken committed Oct 20, 2023
1 parent 8140f79 commit 519edf6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 35 deletions.
20 changes: 13 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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")
Expand Down
23 changes: 14 additions & 9 deletions internal/controller/subscription/eventmesh/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ 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"
Expand Down Expand Up @@ -119,12 +122,14 @@ func setupSuite() error {
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
HealthProbeBindAddress: "0", // disable
Cache: cache.Options{SyncPeriod: &syncPeriod},
Metrics: server.Options{BindAddress: "0"}, // disable
HealthProbeBindAddress: "0", // disable
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
})
if err != nil {
return err
Expand Down
15 changes: 10 additions & 5 deletions internal/controller/subscription/eventmesh/testwithory/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ 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"
Expand Down Expand Up @@ -118,12 +121,14 @@ func setupSuite() error {
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
HealthProbeBindAddress: "0", // disable
Cache: cache.Options{SyncPeriod: &syncPeriod},
Metrics: server.Options{BindAddress: "0"}, //disable
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
})
if err != nil {
return err
Expand Down
15 changes: 10 additions & 5 deletions internal/controller/subscription/jetstream/test_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

cleanerv1alpha2 "github.com/kyma-project/eventing-manager/pkg/backend/cleaner"
"github.com/kyma-project/eventing-manager/pkg/backend/jetstream"
Expand Down Expand Up @@ -150,12 +153,14 @@ func startReconciler() error {
webhookInstallOptions := &jsTestEnsemble.TestEnv.WebhookInstallOptions
k8sManager, err := ctrl.NewManager(jsTestEnsemble.Cfg, ctrl.Options{
Scheme: scheme.Scheme,
SyncPeriod: &syncPeriod,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
MetricsBindAddress: "0", // disable
HealthProbeBindAddress: "0", // disable
Cache: cache.Options{SyncPeriod: &syncPeriod},
Metrics: server.Options{BindAddress: "0"}, // disable
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
})
if err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions test/utils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/kyma-project/eventing-manager/api/v1alpha1"
eventingctrl "github.com/kyma-project/eventing-manager/internal/controller/eventing"
Expand Down Expand Up @@ -145,9 +147,9 @@ func NewTestEnvironment(projectRootDir string, celValidationEnabled bool,

ctrlMgr, err := ctrl.NewManager(envTestKubeCfg, ctrl.Options{
Scheme: scheme.Scheme,
Port: metricsPort,
MetricsBindAddress: "0", // disable
HealthProbeBindAddress: "0", // disable
HealthProbeBindAddress: "0", // disable
Metrics: server.Options{BindAddress: "0"}, // disable
WebhookServer: webhook.NewServer(webhook.Options{Port: metricsPort}),
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 519edf6

Please sign in to comment.