Skip to content

Commit

Permalink
Adopt Kubernetes breaking changes: PR 113542 which require singular n…
Browse files Browse the repository at this point in the history
…ames for core types

Adopt breaking change of contriller-runtime PR 2122
Adopt breaking change of contriller-runtime PR 2296
Adopt breaking change of controller-runtime PR 2139
Adopt breaking change of controller-runtime PR 2135
Adopt breaking change of Kubernetes PR 116218
Adopt breaking change of controller-runtime PR 2149
Adopt breaking change of controller-runtime PR 2150
Adopt breaking change of controller-runtime PR 2134
Adopt breaking change of controller-runtime PR 2293
Adopt breaking change of controller-runtime PR 2144
Adopt k8s feature: watch list. PR 115402
Adopt breaking change of Kubernetes PR 117102
Adopt Kubernetes change: disable staticcheck
Fix unit tests that failure due to fake-client behavior changes.

Signed-off-by: RainbowMango <[email protected]>
  • Loading branch information
RainbowMango committed Jul 29, 2023
1 parent 8efb010 commit 4ee4b22
Show file tree
Hide file tree
Showing 50 changed files with 199 additions and 462 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ linters-settings:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
- name: if-return
disabled: true
staticcheck:
checks:
- all
- '-SA1019' # disable deprecation check. Tracked by https://github.com/karmada-io/karmada/issues/3835.

issues:
# The list of ids of default excludes to include or disable. By default it's empty.
Expand Down
12 changes: 7 additions & 5 deletions cmd/agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/term"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"

Expand Down Expand Up @@ -191,15 +192,16 @@ func run(ctx context.Context, opts *options.Options) error {
BaseContext: func() context.Context {
return ctx
},
Controller: v1alpha1.ControllerConfigurationSpec{
Controller: config.Controller{
GroupKindConcurrency: map[string]int{
workv1alpha1.SchemeGroupVersion.WithKind("Work").GroupKind().String(): opts.ConcurrentWorkSyncs,
clusterv1alpha1.SchemeGroupVersion.WithKind("Cluster").GroupKind().String(): opts.ConcurrentClusterSyncs,
},
},
NewCache: cache.BuilderWithOptions(cache.Options{
DefaultTransform: fedinformer.StripUnusedFields,
}),
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.DefaultTransform = fedinformer.StripUnusedFields
return cache.New(config, opts)
},
})
if err != nil {
return fmt.Errorf("failed to build controller manager: %w", err)
Expand Down
18 changes: 10 additions & 8 deletions cmd/controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/term"
"k8s.io/klog/v2"
Expand All @@ -22,7 +23,7 @@ import (
"k8s.io/metrics/pkg/client/external_metrics"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/healthz"
crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
Expand Down Expand Up @@ -118,12 +119,12 @@ func Run(ctx context.Context, opts *options.Options) error {

profileflag.ListenAndServe(opts.ProfileOpts)

config, err := controllerruntime.GetConfig()
controlPlaneRestConfig, err := controllerruntime.GetConfig()
if err != nil {
panic(err)
}
config.QPS, config.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst
controllerManager, err := controllerruntime.NewManager(config, controllerruntime.Options{
controlPlaneRestConfig.QPS, controlPlaneRestConfig.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst
controllerManager, err := controllerruntime.NewManager(controlPlaneRestConfig, controllerruntime.Options{
Logger: klog.Background(),
Scheme: gclient.NewSchema(),
SyncPeriod: &opts.ResyncPeriod.Duration,
Expand All @@ -141,7 +142,7 @@ func Run(ctx context.Context, opts *options.Options) error {
BaseContext: func() context.Context {
return ctx
},
Controller: v1alpha1.ControllerConfigurationSpec{
Controller: config.Controller{
GroupKindConcurrency: map[string]int{
workv1alpha1.SchemeGroupVersion.WithKind("Work").GroupKind().String(): opts.ConcurrentWorkSyncs,
workv1alpha2.SchemeGroupVersion.WithKind("ResourceBinding").GroupKind().String(): opts.ConcurrentResourceBindingSyncs,
Expand All @@ -150,9 +151,10 @@ func Run(ctx context.Context, opts *options.Options) error {
schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"}.GroupKind().String(): opts.ConcurrentNamespaceSyncs,
},
},
NewCache: cache.BuilderWithOptions(cache.Options{
DefaultTransform: fedinformer.StripUnusedFields,
}),
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.DefaultTransform = fedinformer.StripUnusedFields
return cache.New(config, opts)
},
})
if err != nil {
klog.Errorf("Failed to build controller manager: %v", err)
Expand Down
8 changes: 7 additions & 1 deletion cmd/karmada-search/app/karmada-search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
genericapiserver "k8s.io/apiserver/pkg/server"
genericfilters "k8s.io/apiserver/pkg/server/filters"
genericoptions "k8s.io/apiserver/pkg/server/options"
"k8s.io/client-go/rest"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/term"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -160,7 +161,12 @@ func config(o *options.Options, outOfTreeRegistryOptions ...Option) (*search.Con
serverConfig.ClientConfig.QPS = o.KubeAPIQPS
serverConfig.ClientConfig.Burst = o.KubeAPIBurst

restMapper, err := apiutil.NewDynamicRESTMapper(serverConfig.ClientConfig)
httpClient, err := rest.HTTPClientFor(serverConfig.ClientConfig)
if err != nil {
klog.Errorf("Failed to create HTTP client: %v", err)
return nil, err
}
restMapper, err := apiutil.NewDynamicRESTMapper(serverConfig.ClientConfig, httpClient)
if err != nil {
klog.Errorf("Failed to create REST mapper: %v", err)
return nil, err
Expand Down
8 changes: 8 additions & 0 deletions cmd/metrics-adapter/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

"github.com/spf13/pflag"
openapinamer "k8s.io/apiserver/pkg/endpoints/openapi"
"k8s.io/apiserver/pkg/features"
genericapiserver "k8s.io/apiserver/pkg/server"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -66,6 +68,12 @@ func (o *Options) Config() (*metricsadapter.MetricsServer, error) {
metricsAdapter.OpenAPIConfig.Info.Title = "karmada-metrics-adapter"
metricsAdapter.OpenAPIConfig.Info.Version = "1.0.0"

if utilfeature.DefaultFeatureGate.Enabled(features.OpenAPIV3) {
metricsAdapter.OpenAPIV3Config = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(api.Scheme))
metricsAdapter.OpenAPIV3Config.Info.Title = "karmada-metrics-adapter"
metricsAdapter.OpenAPIV3Config.Info.Version = "1.0.0"
}

server, err := metricsAdapter.Server()
if err != nil {
klog.Errorf("Unable to construct metrics adapter: %v", err)
Expand Down
43 changes: 23 additions & 20 deletions cmd/webhook/app/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"sigs.k8s.io/controller-runtime/pkg/webhook/conversion"

"github.com/karmada-io/karmada/cmd/webhook/app/options"
Expand Down Expand Up @@ -98,14 +99,14 @@ func Run(ctx context.Context, opts *options.Options) error {
hookManager, err := controllerruntime.NewManager(config, controllerruntime.Options{
Logger: klog.Background(),
Scheme: gclient.NewSchema(),
WebhookServer: &webhook.Server{
WebhookServer: webhook.NewServer(webhook.Options{
Host: opts.BindAddress,
Port: opts.SecurePort,
CertDir: opts.CertDir,
CertName: opts.CertName,
KeyName: opts.KeyName,
TLSMinVersion: opts.TLSMinVersion,
},
}),
LeaderElection: false,
MetricsBindAddress: opts.MetricsBindAddress,
HealthProbeBindAddress: opts.HealthProbeBindAddress,
Expand All @@ -115,28 +116,30 @@ func Run(ctx context.Context, opts *options.Options) error {
return err
}

decoder := admission.NewDecoder(hookManager.GetScheme())

klog.Info("Registering webhooks to the webhook server")
hookServer := hookManager.GetWebhookServer()
hookServer.Register("/mutate-propagationpolicy", &webhook.Admission{Handler: propagationpolicy.NewMutatingHandler(
opts.DefaultNotReadyTolerationSeconds, opts.DefaultUnreachableTolerationSeconds)})
hookServer.Register("/validate-propagationpolicy", &webhook.Admission{Handler: &propagationpolicy.ValidatingAdmission{}})
opts.DefaultNotReadyTolerationSeconds, opts.DefaultUnreachableTolerationSeconds, decoder)})
hookServer.Register("/validate-propagationpolicy", &webhook.Admission{Handler: &propagationpolicy.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/mutate-clusterpropagationpolicy", &webhook.Admission{Handler: clusterpropagationpolicy.NewMutatingHandler(
opts.DefaultNotReadyTolerationSeconds, opts.DefaultUnreachableTolerationSeconds)})
hookServer.Register("/validate-clusterpropagationpolicy", &webhook.Admission{Handler: &clusterpropagationpolicy.ValidatingAdmission{}})
hookServer.Register("/mutate-overridepolicy", &webhook.Admission{Handler: &overridepolicy.MutatingAdmission{}})
hookServer.Register("/validate-overridepolicy", &webhook.Admission{Handler: &overridepolicy.ValidatingAdmission{}})
hookServer.Register("/validate-clusteroverridepolicy", &webhook.Admission{Handler: &clusteroverridepolicy.ValidatingAdmission{}})
hookServer.Register("/mutate-work", &webhook.Admission{Handler: &work.MutatingAdmission{}})
hookServer.Register("/convert", &conversion.Webhook{})
hookServer.Register("/validate-resourceinterpreterwebhookconfiguration", &webhook.Admission{Handler: &configuration.ValidatingAdmission{}})
hookServer.Register("/validate-federatedresourcequota", &webhook.Admission{Handler: &federatedresourcequota.ValidatingAdmission{}})
hookServer.Register("/validate-federatedhpa", &webhook.Admission{Handler: &federatedhpa.ValidatingAdmission{}})
hookServer.Register("/validate-cronfederatedhpa", &webhook.Admission{Handler: &cronfederatedhpa.ValidatingAdmission{}})
hookServer.Register("/validate-resourceinterpretercustomization", &webhook.Admission{Handler: &resourceinterpretercustomization.ValidatingAdmission{Client: hookManager.GetClient()}})
hookServer.Register("/validate-multiclusteringress", &webhook.Admission{Handler: &multiclusteringress.ValidatingAdmission{}})
hookServer.Register("/validate-multiclusterservice", &webhook.Admission{Handler: &multiclusterservice.ValidatingAdmission{}})
hookServer.Register("/mutate-federatedhpa", &webhook.Admission{Handler: &federatedhpa.MutatingAdmission{}})
hookServer.WebhookMux.Handle("/readyz/", http.StripPrefix("/readyz/", &healthz.Handler{}))
opts.DefaultNotReadyTolerationSeconds, opts.DefaultUnreachableTolerationSeconds, decoder)})
hookServer.Register("/validate-clusterpropagationpolicy", &webhook.Admission{Handler: &clusterpropagationpolicy.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/mutate-overridepolicy", &webhook.Admission{Handler: &overridepolicy.MutatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-overridepolicy", &webhook.Admission{Handler: &overridepolicy.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-clusteroverridepolicy", &webhook.Admission{Handler: &clusteroverridepolicy.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/mutate-work", &webhook.Admission{Handler: &work.MutatingAdmission{Decoder: decoder}})
hookServer.Register("/convert", conversion.NewWebhookHandler(hookManager.GetScheme()))
hookServer.Register("/validate-resourceinterpreterwebhookconfiguration", &webhook.Admission{Handler: &configuration.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-federatedresourcequota", &webhook.Admission{Handler: &federatedresourcequota.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-federatedhpa", &webhook.Admission{Handler: &federatedhpa.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-cronfederatedhpa", &webhook.Admission{Handler: &cronfederatedhpa.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-resourceinterpretercustomization", &webhook.Admission{Handler: &resourceinterpretercustomization.ValidatingAdmission{Client: hookManager.GetClient(), Decoder: decoder}})
hookServer.Register("/validate-multiclusteringress", &webhook.Admission{Handler: &multiclusteringress.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/validate-multiclusterservice", &webhook.Admission{Handler: &multiclusterservice.ValidatingAdmission{Decoder: decoder}})
hookServer.Register("/mutate-federatedhpa", &webhook.Admission{Handler: &federatedhpa.MutatingAdmission{Decoder: decoder}})
hookServer.WebhookMux().Handle("/readyz/", http.StripPrefix("/readyz/", &healthz.Handler{}))

// blocks until the context is done.
if err := hookManager.Start(ctx); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/customresourceinterpreter/webhook/app/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Run(ctx context.Context, opts *options.Options) error {
klog.Info("Registering webhooks to the webhook server")
hookServer := hookManager.GetWebhookServer()
hookServer.Register("/interpreter-workload", interpreter.NewWebhook(&workloadInterpreter{}, interpreter.NewDecoder(gclient.NewSchema())))
hookServer.WebhookMux.Handle("/readyz/", http.StripPrefix("/readyz/", &healthz.Handler{}))
hookServer.WebhookMux().Handle("/readyz/", http.StripPrefix("/readyz/", &healthz.Handler{}))

// blocks until the context is done.
if err := hookManager.Start(ctx); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions hack/tools/swagger/lib/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ProxyREST struct{}
var _ rest.GroupVersionKindProvider = &StandardREST{}
var _ rest.Scoper = &StandardREST{}
var _ rest.StandardStorage = &StandardREST{}
var _ rest.SingularNameProvider = &StandardREST{}

// Implement below interfaces for StatusREST.
var _ rest.Patcher = &StatusREST{}
Expand Down Expand Up @@ -104,6 +105,11 @@ func (r *StandardREST) Destroy() {
// need to destroy anything.
}

// GetSingularName implements the SingularNameProvider interfaces.
func (r *StandardREST) GetSingularName() string {
return ""
}

// GroupVersionKind implement GroupVersionKind interface.
func (r *StatusREST) GroupVersionKind(_ schema.GroupVersion) schema.GroupVersionKind {
return r.cfg.gvk
Expand Down
8 changes: 4 additions & 4 deletions operator/cmd/operator/app/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"k8s.io/component-base/term"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
ctrlruntimecfg "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"

"github.com/karmada-io/karmada/operator/cmd/operator/app/options"
Expand Down Expand Up @@ -133,7 +133,7 @@ func startKarmadaController(ctx ctrlctx.Context) (bool, error) {

// createControllerManager creates controllerruntime.Manager from the given configuration
func createControllerManager(ctx context.Context, o *options.Options) (controllerruntime.Manager, error) {
config, err := controllerruntime.GetConfig()
restConfig, err := controllerruntime.GetConfig()
if err != nil {
return nil, err
}
Expand All @@ -155,11 +155,11 @@ func createControllerManager(ctx context.Context, o *options.Options) (controlle
HealthProbeBindAddress: net.JoinHostPort(o.BindAddress, strconv.Itoa(o.SecurePort)),
LivenessEndpointName: "/healthz",
MetricsBindAddress: o.MetricsBindAddress,
Controller: ctrlruntimecfg.ControllerConfigurationSpec{
Controller: config.Controller{
GroupKindConcurrency: map[string]int{
operatorv1alpha1.SchemeGroupVersion.WithKind("Karmada").GroupKind().String(): o.ConcurrentKarmadaSyncs,
},
},
}
return controllerruntime.NewManager(config, opts)
return controllerruntime.NewManager(restConfig, opts)
}
7 changes: 3 additions & 4 deletions pkg/controllers/binding/binding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
Expand Down Expand Up @@ -151,14 +150,14 @@ func (c *ResourceBindingController) removeOrphanWorks(binding *workv1alpha2.Reso
func (c *ResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha2.ResourceBinding{}).
WithEventFilter(predicate.GenerationChangedPredicate{}).
Watches(&source.Kind{Type: &policyv1alpha1.OverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Watches(&source.Kind{Type: &policyv1alpha1.ClusterOverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Watches(&policyv1alpha1.OverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c)
}

func (c *ResourceBindingController) newOverridePolicyFunc() handler.MapFunc {
return func(a client.Object) []reconcile.Request {
return func(ctx context.Context, a client.Object) []reconcile.Request {
var overrideRS []policyv1alpha1.ResourceSelector
var namespace string
switch t := a.(type) {
Expand Down
17 changes: 1 addition & 16 deletions pkg/controllers/binding/binding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"reflect"
"testing"
"time"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -75,7 +74,6 @@ func makeFakeRBCByResource(rs *workv1alpha2.ObjectReference) (*ResourceBindingCo
}

func TestResourceBindingController_Reconcile(t *testing.T) {
preTime := metav1.Date(2023, 0, 0, 0, 0, 0, 0, time.UTC)
tmpReq := controllerruntime.Request{
NamespacedName: types.NamespacedName{
Name: "test-rb",
Expand All @@ -95,19 +93,6 @@ func TestResourceBindingController_Reconcile(t *testing.T) {
wantErr: false,
req: tmpReq,
},
{
name: "RB found with deleting",
want: controllerruntime.Result{},
wantErr: false,
rb: &workv1alpha2.ResourceBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "test-rb",
Namespace: "default",
DeletionTimestamp: &preTime,
},
},
req: tmpReq,
},
{
name: "RB found without deleting",
want: controllerruntime.Result{Requeue: true},
Expand Down Expand Up @@ -288,7 +273,7 @@ func TestResourceBindingController_newOverridePolicyFunc(t *testing.T) {
if (got == nil) != tt.want {
t.Errorf("newOverridePolicyFunc() is not same as want:%v", tt.want)
}
if (got(client.Object(tempOP)) == nil) == tt.obIsNil {
if (got(context.TODO(), client.Object(tempOP)) == nil) == tt.obIsNil {
t.Errorf("newOverridePolicyFunc() got() result is not same as want: %v", tt.obIsNil)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
Expand Down Expand Up @@ -147,14 +146,14 @@ func (c *ClusterResourceBindingController) removeOrphanWorks(binding *workv1alph
// SetupWithManager creates a controller and register to controller manager.
func (c *ClusterResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha2.ClusterResourceBinding{}).
Watches(&source.Kind{Type: &policyv1alpha1.ClusterOverridePolicy{}}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
WithEventFilter(predicate.GenerationChangedPredicate{}).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c)
}

func (c *ClusterResourceBindingController) newOverridePolicyFunc() handler.MapFunc {
return func(a client.Object) []reconcile.Request {
return func(ctx context.Context, a client.Object) []reconcile.Request {
var overrideRS []policyv1alpha1.ResourceSelector
switch t := a.(type) {
case *policyv1alpha1.ClusterOverridePolicy:
Expand Down
Loading

0 comments on commit 4ee4b22

Please sign in to comment.