Skip to content

Commit

Permalink
Adapt "Refactor source/handler/predicate packages to remove dep injec…
Browse files Browse the repository at this point in the history
  • Loading branch information
ary1992 committed Jun 19, 2023
1 parent 444ccdd commit 0d2ea18
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/networkpolicy/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, runtimeCluster cluster.Cl
MaxConcurrentReconciles: pointer.IntDeref(r.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(&corev1.Namespace{}, runtimeCluster.GetCache()),
source.Kind(runtimeCluster.GetCache(), &corev1.Namespace{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicateutils.ForEventTypes(predicateutils.Create, predicateutils.Update)),
).
Expand All @@ -92,15 +92,15 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, runtimeCluster cluster.Cl
}

if err := c.Watch(
source.NewKindWithCache(&corev1.Endpoints{}, runtimeCluster.GetCache()),
source.Kind(runtimeCluster.GetCache(), &corev1.Endpoints{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapToNamespaces), mapper.UpdateWithNew, c.GetLogger()),
r.IsKubernetesEndpoint(),
); err != nil {
return err
}

if err := c.Watch(
source.NewKindWithCache(&networkingv1.NetworkPolicy{}, runtimeCluster.GetCache()),
source.Kind(runtimeCluster.GetCache(), &networkingv1.NetworkPolicy{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapObjectToNamespace), mapper.UpdateWithNew, c.GetLogger()),
r.NetworkPolicyPredicate(),
); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gardenlet/controller/backupbucket/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
RateLimiter: r.RateLimiter,
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.BackupBucket{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.BackupBucket{}),
controllerutils.EnqueueCreateEventsOncePer24hDuration(r.Clock),
builder.WithPredicates(
&predicate.GenerationChangedPredicate{},
Expand All @@ -80,7 +80,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
}

return c.Watch(
source.NewKindWithCache(&extensionsv1alpha1.BackupBucket{}, seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), &extensionsv1alpha1.BackupBucket{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapExtensionBackupBucketToCoreBackupBucket), mapper.UpdateWithNew, c.GetLogger()),
predicateutils.ExtensionStatusChanged(),
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gardenlet/controller/backupentry/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
RateLimiter: r.RateLimiter,
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.BackupEntry{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.BackupEntry{}),
controllerutils.EnqueueCreateEventsOncePer24hDuration(r.Clock),
builder.WithPredicates(
&predicate.GenerationChangedPredicate{},
Expand All @@ -83,7 +83,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
}

return c.Watch(
source.NewKindWithCache(&extensionsv1alpha1.BackupEntry{}, seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), &extensionsv1alpha1.BackupEntry{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapExtensionBackupEntryToCoreBackupEntry), mapper.UpdateWithNew, c.GetLogger()),
predicateutils.ExtensionStatusChanged(),
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gardenlet/controller/bastion/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
RateLimiter: r.RateLimiter,
}).
Watches(
source.NewKindWithCache(&operationsv1alpha1.Bastion{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &operationsv1alpha1.Bastion{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.GenerationChangedPredicate{}),
).
Expand All @@ -72,7 +72,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
}

return c.Watch(
source.NewKindWithCache(&extensionsv1alpha1.Bastion{}, seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), &extensionsv1alpha1.Bastion{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapExtensionsBastionToOperationsBastion), mapper.UpdateWithNew, c.GetLogger()),
predicateutils.ExtensionStatusChanged(),
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gardenlet/controller/controllerinstallation/care/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
RateLimiter: workqueue.NewWithMaxWaitRateLimiter(workqueue.DefaultControllerRateLimiter(), r.Config.SyncPeriod.Duration),
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.ControllerInstallation{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.ControllerInstallation{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicateutils.ForEventTypes(predicateutils.Create)),
).
Expand All @@ -77,7 +77,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
}

return c.Watch(
source.NewKindWithCache(&resourcesv1alpha1.ManagedResource{}, seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), &resourcesv1alpha1.ManagedResource{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapManagedResourceToControllerInstallation), mapper.UpdateWithNew, c.GetLogger()),
r.IsExtensionDeployment(),
predicateutils.ManagedResourceConditionsChanged(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.ControllerInstallation{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.ControllerInstallation{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(
r.ControllerInstallationPredicate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
return err
}

if err := c.Watch(source.NewKindWithCache(extension.object, seedCluster.GetCache()), eventHandler, r.ObjectPredicate()); err != nil {
if err := c.Watch(source.Kind(seedCluster.GetCache(), extension.object), eventHandler, r.ObjectPredicate()); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/gardenlet/controller/managedseed/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (r *Reconciler) AddToManager(
MaxConcurrentReconciles: pointer.IntDeref(r.Config.Controllers.ManagedSeed.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(&seedmanagementv1alpha1.ManagedSeed{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &seedmanagementv1alpha1.ManagedSeed{}),
r.EnqueueWithJitterDelay(),
builder.WithPredicates(
r.ManagedSeedPredicate(r.Config.SeedConfig.SeedTemplate.Name),
Expand All @@ -113,7 +113,7 @@ func (r *Reconciler) AddToManager(
}

return c.Watch(
source.NewKindWithCache(&gardencorev1beta1.Seed{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.Seed{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapSeedToManagedSeed), mapper.UpdateWithNew, c.GetLogger()),
r.SeedOfManagedSeedPredicate(r.Config.SeedConfig.SeedTemplate.Name),
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/gardenlet/controller/networkpolicy/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func AddToManager(

reconciler.WatchRegisterers = append(reconciler.WatchRegisterers, func(c controller.Controller) error {
return c.Watch(
source.NewKindWithCache(&extensionsv1alpha1.Cluster{}, seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), &extensionsv1alpha1.Cluster{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(reconciler.MapObjectToName), mapper.UpdateWithNew, mgr.GetLogger()),
ClusterPredicate(),
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gardenlet/controller/seed/care/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
RateLimiter: workqueue.NewWithMaxWaitRateLimiter(workqueue.DefaultControllerRateLimiter(), r.Config.SyncPeriod.Duration),
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.Seed{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.Seed{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(
predicateutils.HasName(r.SeedName),
Expand All @@ -75,7 +75,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
}

return c.Watch(
source.NewKindWithCache(&resourcesv1alpha1.ManagedResource{}, seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), &resourcesv1alpha1.ManagedResource{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapManagedResourceToSeed), mapper.UpdateWithNew, c.GetLogger()),
r.IsSystemComponent(),
predicateutils.ManagedResourceConditionsChanged(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/gardenlet/controller/seed/lease/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(time.Millisecond, 2*time.Second),
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.Seed{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.Seed{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(
predicateutils.HasName(r.SeedName),
Expand Down
2 changes: 1 addition & 1 deletion pkg/gardenlet/controller/seed/seed/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
MaxConcurrentReconciles: 1,
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.Seed{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.Seed{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(
predicateutils.HasName(r.Config.SeedConfig.Name),
Expand Down
2 changes: 1 addition & 1 deletion pkg/gardenlet/controller/shoot/care/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
RateLimiter: workqueue.NewWithMaxWaitRateLimiter(workqueue.DefaultControllerRateLimiter(), r.Config.Controllers.ShootCare.SyncPeriod.Duration),
}).
Watches(
source.NewKindWithCache(&gardencorev1beta1.Shoot{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.Shoot{}),
r.EventHandler(),
builder.WithPredicates(
predicateutils.SeedNamePredicate(r.SeedName, gardenerutils.GetShootSeedNames),
Expand Down
2 changes: 1 addition & 1 deletion pkg/gardenlet/controller/shoot/shoot/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster cluster.Clu
}

return c.Watch(
source.NewKindWithCache(&gardencorev1beta1.Shoot{}, gardenCluster.GetCache()),
source.Kind(gardenCluster.GetCache(), &gardencorev1beta1.Shoot{}),
r.EventHandler(c.GetLogger()),
predicateutils.SeedNamePredicate(r.Config.SeedConfig.Name, gardenerutils.GetShootSeedNames),
&predicate.GenerationChangedPredicate{},
Expand Down
2 changes: 1 addition & 1 deletion pkg/gardenlet/controller/shootstate/extensions/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, gardenCluster, seedCluste
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(r.NewObjectFunc(), seedCluster.GetCache()),
source.Kind(seedCluster.GetCache(), r.NewObjectFunc()),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(
r.ObjectPredicate(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemanager/controller/csrapprover/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, sourceCluster, targetClus
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(&certificatesv1.CertificateSigningRequest{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &certificatesv1.CertificateSigningRequest{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(
predicateutils.ForEventTypes(predicateutils.Create, predicateutils.Update),
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemanager/controller/health/health/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, sourceCluster, targetClus
c.GetLogger().Info("Adding new watch for GroupVersionKind", "groupVersionKind", gvk, "metadataOnly", metadataOnly)

if err := c.Watch(
source.NewKindWithCache(obj, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), obj),
mapper.EnqueueRequestsFrom(utils.MapToOriginManagedResource(clusterID), mapper.UpdateWithNew, c.GetLogger()),
utils.HealthStatusChanged(c.GetLogger()),
); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/resourcemanager/controller/health/progressing/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, sourceCluster, targetClus
// If we want to have immediate updates for managed resources in Shoots in the future as well, we could consider
// adding labels to managed resources and watch them explicitly.
b = b.Watches(
source.NewKindWithCache(&appsv1.Deployment{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &appsv1.Deployment{}),
mapper.EnqueueRequestsFrom(utils.MapToOriginManagedResource(clusterID), mapper.UpdateWithNew, c.GetLogger()),
builder.WithPredicates(r.ProgressingStatusChanged()),
).Watches(
source.NewKindWithCache(&appsv1.StatefulSet{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &appsv1.StatefulSet{}),
mapper.EnqueueRequestsFrom(utils.MapToOriginManagedResource(clusterID), mapper.UpdateWithNew, c.GetLogger()),
builder.WithPredicates(r.ProgressingStatusChanged()),
).Watches(
source.NewKindWithCache(&appsv1.DaemonSet{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &appsv1.DaemonSet{}),
mapper.EnqueueRequestsFrom(utils.MapToOriginManagedResource(clusterID), mapper.UpdateWithNew, c.GetLogger()),
builder.WithPredicates(r.ProgressingStatusChanged()),
)
Expand Down
8 changes: 4 additions & 4 deletions pkg/resourcemanager/controller/networkpolicy/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(&corev1.Service{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &corev1.Service{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(r.ServicePredicate()),
).
Expand All @@ -88,7 +88,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu
}

if err := c.Watch(
source.NewKindWithCache(networkPolicy, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), networkPolicy),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapNetworkPolicyToService), mapper.UpdateWithNew, c.GetLogger()),
networkPolicyPredicate,
); err != nil {
Expand All @@ -97,7 +97,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu

if r.Config.IngressControllerSelector != nil {
if err := c.Watch(
source.NewKindWithCache(&networkingv1.Ingress{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &networkingv1.Ingress{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapIngressToServices), mapper.UpdateWithNew, c.GetLogger()),
r.IngressPredicate(),
); err != nil {
Expand All @@ -109,7 +109,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu
namespace.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Namespace"))

return c.Watch(
source.NewKindWithCache(namespace, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), namespace),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapToAllServices), mapper.UpdateWithNew, c.GetLogger()),
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemanager/controller/node/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
}).
Watches(
source.NewKindWithCache(&corev1.Node{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &corev1.Node{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(r.NodePredicate()),
).
Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcemanager/controller/tokeninvalidator/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu
RateLimiter: r.RateLimiter,
}).
Watches(
source.NewKindWithCache(secret, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), secret),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(r.SecretPredicate()),
).
Expand All @@ -70,7 +70,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager, targetCluster cluster.Clu
}

return c.Watch(
source.NewKindWithCache(&corev1.ServiceAccount{}, targetCluster.GetCache()),
source.Kind(targetCluster.GetCache(), &corev1.ServiceAccount{}),
mapper.EnqueueRequestsFrom(mapper.MapFunc(r.MapServiceAccountToSecrets), mapper.UpdateWithOldAndNew, c.GetLogger()),
r.ServiceAccountPredicate(),
)
Expand Down

0 comments on commit 0d2ea18

Please sign in to comment.