Skip to content

Commit

Permalink
Minor cosmetics and streamlining (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
shafeeqes authored Mar 28, 2023
1 parent bf8694f commit 0299799
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
30 changes: 15 additions & 15 deletions controllers/compaction/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
druidpredicates "github.com/gardener/etcd-druid/pkg/predicate"
coordinationv1 "k8s.io/api/coordination/v1"
ctrl "sigs.k8s.io/controller-runtime"
ctrlbuilder "sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand All @@ -28,19 +29,18 @@ const controllerName = "compaction-controller"

// RegisterWithManager registers the Compaction Controller with the given controller manager.
func (r *Reconciler) RegisterWithManager(mgr ctrl.Manager) error {
c, err := controller.New(controllerName, mgr, controller.Options{
Reconciler: r,
MaxConcurrentReconciles: r.config.Workers,
})

if err != nil {
return err
}

return c.Watch(
&source.Kind{Type: &coordinationv1.Lease{}},
&handler.EnqueueRequestForOwner{OwnerType: &druidv1alpha1.Etcd{}, IsController: true},
druidpredicates.LeaseHolderIdentityChange(),
druidpredicates.IsSnapshotLease(),
)
return ctrl.
NewControllerManagedBy(mgr).
Named(controllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.config.Workers,
}).
Watches(
&source.Kind{Type: &coordinationv1.Lease{}},
&handler.EnqueueRequestForOwner{OwnerType: &druidv1alpha1.Etcd{}, IsController: true},
ctrlbuilder.WithPredicates(
druidpredicates.LeaseHolderIdentityChange(),
druidpredicates.IsSnapshotLease(),
)).
Complete(r)
}
13 changes: 7 additions & 6 deletions controllers/custodian/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ const controllerName = "custodian-controller"

// RegisterWithManager registers the Custodian Controller with the given controller manager.
func (r *Reconciler) RegisterWithManager(ctx context.Context, mgr ctrl.Manager, ignoreOperationAnnotation bool) error {
builder := ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
MaxConcurrentReconciles: r.config.Workers,
})

c, err := builder.
c, err := ctrl.
NewControllerManagedBy(mgr).
Named(controllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.config.Workers,
}).
For(
&druidv1alpha1.Etcd{},
ctrlbuilder.WithPredicates(druidpredicates.EtcdReconciliationFinished(ignoreOperationAnnotation))).
ctrlbuilder.WithPredicates(druidpredicates.EtcdReconciliationFinished(ignoreOperationAnnotation)),
).
Owns(&coordinationv1.Lease{}).
Build(r)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions controllers/etcd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ const controllerName = "etcd-controller"

// RegisterWithManager registers the Etcd Controller with the given controller manager.
func (r *Reconciler) RegisterWithManager(mgr ctrl.Manager, ignoreOperationAnnotation bool) error {
builder := ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
MaxConcurrentReconciles: r.config.Workers,
})
builder = builder.
builder := ctrl.
NewControllerManagedBy(mgr).
Named(controllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.config.Workers,
}).
WithEventFilter(BuildPredicate(ignoreOperationAnnotation)).
For(&druidv1alpha1.Etcd{})

if ignoreOperationAnnotation {
builder = builder.Owns(&corev1.Service{}).
Owns(&corev1.ConfigMap{}).
Owns(&appsv1.StatefulSet{})
}

return builder.Complete(r)
}

Expand Down
9 changes: 6 additions & 3 deletions controllers/etcdcopybackupstask/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

batchv1 "k8s.io/api/batch/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
ctrlbuilder "sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
Expand All @@ -30,10 +30,13 @@ const controllerName = "etcdcopybackupstask-controller"
func (r *Reconciler) RegisterWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Named(controllerName).
For(&druidv1alpha1.EtcdCopyBackupsTask{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&batchv1.Job{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.Config.Workers,
}).
For(
&druidv1alpha1.EtcdCopyBackupsTask{},
ctrlbuilder.WithPredicates(predicate.GenerationChangedPredicate{}),
).
Owns(&batchv1.Job{}).
Complete(r)
}
10 changes: 5 additions & 5 deletions controllers/secret/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const controllerName = "secret-controller"

// RegisterWithManager registers the Secret Controller with the given controller manager.
func (r *Reconciler) RegisterWithManager(mgr ctrl.Manager) error {
builder := ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
MaxConcurrentReconciles: r.Config.Workers,
})

c, err := builder.
c, err := ctrl.
NewControllerManagedBy(mgr).
Named(controllerName).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.Config.Workers,
}).
For(&corev1.Secret{}).
Build(r)
if err != nil {
Expand Down

0 comments on commit 0299799

Please sign in to comment.