Skip to content

Commit

Permalink
Use Build() function for all controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
shafeeqes committed Dec 20, 2022
1 parent 9aabdb8 commit f9a0400
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 227 deletions.
16 changes: 7 additions & 9 deletions pkg/controllermanager/controller/project/activity/add.go
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
Expand All @@ -51,16 +52,13 @@ func (r *Reconciler) AddToManager(mgr manager.Manager) error {
r.Clock = clock.RealClock{}
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
17 changes: 8 additions & 9 deletions pkg/controllermanager/controller/seed/backupbucketscheck/add.go
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
Expand All @@ -46,18 +47,16 @@ func (r *Reconciler) AddToManager(mgr manager.Manager) error {
r.Clock = clock.RealClock{}
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),

// if going into exponential backoff, wait at most the configured sync period
RateLimiter: workqueue.NewWithMaxWaitRateLimiter(workqueue.DefaultControllerRateLimiter(), r.Config.SyncPeriod.Duration),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
17 changes: 8 additions & 9 deletions pkg/controllermanager/controller/seed/extensionscheck/add.go
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -45,18 +46,16 @@ func (r *Reconciler) AddToManager(mgr manager.Manager) error {
r.Clock = clock.RealClock{}
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),

// if going into exponential backoff, wait at most the configured sync period
RateLimiter: workqueue.NewWithMaxWaitRateLimiter(workqueue.DefaultControllerRateLimiter(), r.Config.SyncPeriod.Duration),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/backupbucket/add.go
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -58,18 +59,15 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
r.GardenNamespace = v1beta1constants.GardenNamespace
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),

RateLimiter: r.RateLimiter,
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/backupentry/backupentry/add.go
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -61,18 +62,15 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
r.GardenNamespace = v1beta1constants.GardenNamespace
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),

RateLimiter: r.RateLimiter,
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/backupentry/migration/add.go
Expand Up @@ -17,6 +17,7 @@ package migration
import (
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand All @@ -41,16 +42,13 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
r.Clock = clock.RealClock{}
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/bastion/add.go
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/clock"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -53,18 +54,15 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
r.Clock = clock.RealClock{}
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),

RateLimiter: r.RateLimiter,
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/controllerinstallation/care/add.go
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -53,19 +54,16 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
r.GardenNamespace = v1beta1constants.GardenNamespace
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),

// if going into exponential backoff, wait at most the configured sync period
RateLimiter: workqueue.NewWithMaxWaitRateLimiter(workqueue.DefaultControllerRateLimiter(), r.Config.SyncPeriod.Duration),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
Expand Up @@ -19,6 +19,7 @@ import (
"reflect"

"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand All @@ -42,16 +43,13 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
r.GardenClient = gardenCluster.GetClient()
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/controllerinstallation/required/add.go
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -55,16 +56,13 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
r.Lock = &sync.RWMutex{}
r.KindToRequiredTypes = make(map[string]sets.String)

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/managedseed/add.go
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -87,16 +88,13 @@ func (r *Reconciler) AddToManager(
)
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.Controllers.ManagedSeed.ConcurrentSyncs, 0),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/gardenlet/controller/networkpolicy/add.go
Expand Up @@ -23,6 +23,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -73,16 +74,13 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, seedCluster cluster.Clust
r.IstioSystemNamespace = v1beta1constants.IstioSystemNamespace
}

// It's not possible to overwrite the event handler when using the controller builder. Hence, we have to build up
// the controller manually.
c, err := controller.New(
ControllerName,
mgr,
controller.Options{
Reconciler: r,
c, err := builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
},
)
}).
Build(r)
if err != nil {
return err
}
Expand Down

0 comments on commit f9a0400

Please sign in to comment.