Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 add TypedAll, ResourceIsUnchanged and TypedResourceIsUnchanged predicates #11597

Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue))

if feature.Gates.Enabled(feature.MachinePool) {
b = b.Watches(
&expv1.MachinePool{},
handler.EnqueueRequestsFromMapFunc(r.MachinePoolToBootstrapMapFunc),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
)
}

Expand All @@ -136,6 +138,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmConfigs),
builder.WithPredicates(
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ClusterPausedTransitionsOrInfrastructureReady(mgr.GetScheme(), predicateLog),
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
),
Expand Down
3 changes: 2 additions & 1 deletion controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "kubeadmcontrolplane")
c, err := ctrl.NewControllerManagedBy(mgr).
For(&controlplanev1.KubeadmControlPlane{}).
Owns(&clusterv1.Machine{}).
Owns(&clusterv1.Machine{}, builder.WithPredicates(predicates.ResourceIsChanged(predicateLog))).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmControlPlane),
builder.WithPredicates(
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
predicates.ClusterPausedTransitionsOrInfrastructureReady(mgr.GetScheme(), predicateLog),
),
Expand Down
13 changes: 11 additions & 2 deletions exp/addons/internal/controllers/clusterresourceset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,20 @@ func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(r.clusterToClusterResourceSet),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WatchesRawSource(r.ClusterCache.GetClusterSource("clusterresourceset", r.clusterToClusterResourceSet)).
WatchesMetadata(
&corev1.ConfigMap{},
handler.EnqueueRequestsFromMapFunc(
resourceToClusterResourceSetFunc[client.Object](r.Client),
),
builder.WithPredicates(resourcepredicates.TypedResourceCreateOrUpdate[client.Object](predicateLog)),
builder.WithPredicates(
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
resourcepredicates.TypedResourceCreateOrUpdate[client.Object](predicateLog),
),
),
).
WatchesRawSource(source.Kind(
partialSecretCache,
Expand All @@ -101,7 +107,10 @@ func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr
handler.TypedEnqueueRequestsFromMapFunc(
resourceToClusterResourceSetFunc[*metav1.PartialObjectMetadata](r.Client),
),
resourcepredicates.TypedResourceCreateOrUpdate[*metav1.PartialObjectMetadata](predicateLog),
predicates.TypedAll(mgr.GetScheme(), predicateLog,
predicates.TypedResourceIsChanged[*metav1.PartialObjectMetadata](predicateLog),
resourcepredicates.TypedResourceCreateOrUpdate[*metav1.PartialObjectMetadata](predicateLog),
),
)).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"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/handler"
Expand Down Expand Up @@ -58,6 +59,7 @@ func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Conte
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(r.clusterToClusterResourceSetBinding),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Expand Down
3 changes: 3 additions & 0 deletions exp/internal/controllers/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -120,6 +121,7 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
builder.WithPredicates(
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ClusterPausedTransitions(mgr.GetScheme(), predicateLog),
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
),
Expand Down Expand Up @@ -377,6 +379,7 @@ func (r *MachinePoolReconciler) watchClusterNodes(ctx context.Context, cluster *
Watcher: r.controller,
Kind: &corev1.Node{},
EventHandler: handler.EnqueueRequestsFromMapFunc(r.nodeToMachinePool),
Predicates: []predicate.TypedPredicate[client.Object]{predicates.TypedResourceIsChanged[client.Object](log)},
}))
}

Expand Down
5 changes: 3 additions & 2 deletions exp/internal/controllers/machinepool_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"sigs.k8s.io/cluster-api/util/labels"
"sigs.k8s.io/cluster-api/util/labels/format"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
)

func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) {
Expand Down Expand Up @@ -123,7 +124,7 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, m *expv1.
}

// Ensure we add a watch to the external object, if there isn't one already.
if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &expv1.MachinePool{})); err != nil {
if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &expv1.MachinePool{}), predicates.ResourceIsChanged(log)); err != nil {
return external.ReconcileOutput{}, err
}

Expand Down Expand Up @@ -364,7 +365,7 @@ func (r *MachinePoolReconciler) reconcileMachines(ctx context.Context, s *scope,
sampleInfraMachine.SetKind(infraMachineKind)

// Add watcher for infraMachine, if there isn't one already.
if err := r.externalTracker.Watch(log, sampleInfraMachine, handler.EnqueueRequestsFromMapFunc(r.infraMachineToMachinePoolMapper)); err != nil {
if err := r.externalTracker.Watch(log, sampleInfraMachine, handler.EnqueueRequestsFromMapFunc(r.infraMachineToMachinePoolMapper), predicates.ResourceIsChanged(log)); err != nil {
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
handler.TypedEnqueueRequestsFromMapFunc(
r.secretToExtensionConfig,
),
predicates.TypedResourceIsChanged[*metav1.PartialObjectMetadata](predicateLog),
)).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Expand Down
4 changes: 4 additions & 0 deletions internal/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -103,14 +104,17 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(r.controlPlaneMachineToCluster),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
Watches(
&clusterv1.MachineDeployment{},
handler.EnqueueRequestsFromMapFunc(r.machineDeploymentToCluster),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
Watches(
&expv1.MachinePool{},
handler.EnqueueRequestsFromMapFunc(r.machinePoolToCluster),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/cluster/cluster_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/cluster-api/util/kubeconfig"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
"sigs.k8s.io/cluster-api/util/secret"
)

Expand Down Expand Up @@ -96,7 +97,7 @@ func (r *Reconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.C
}

// Ensure we add a watcher to the external object.
if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Cluster{})); err != nil {
if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Cluster{}), predicates.ResourceIsChanged(log)); err != nil {
return nil, err
}

Expand Down
2 changes: 2 additions & 0 deletions internal/controllers/clusterclass/clusterclass_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"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/controller/controllerutil"
Expand Down Expand Up @@ -84,6 +85,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Watches(
&runtimev1.ExtensionConfig{},
handler.EnqueueRequestsFromMapFunc(r.extensionConfigToClusterClass),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Complete(r)
Expand Down
5 changes: 5 additions & 0 deletions internal/controllers/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -150,6 +151,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
builder.WithPredicates(
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ClusterControlPlaneInitialized(mgr.GetScheme(), predicateLog),
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
),
Expand All @@ -158,10 +160,12 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Watches(
&clusterv1.MachineSet{},
handler.EnqueueRequestsFromMapFunc(msToMachines),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
Watches(
&clusterv1.MachineDeployment{},
handler.EnqueueRequestsFromMapFunc(mdToMachines),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
Build(r)
if err != nil {
Expand Down Expand Up @@ -1081,6 +1085,7 @@ func (r *Reconciler) watchClusterNodes(ctx context.Context, cluster *clusterv1.C
Watcher: r.controller,
Kind: &corev1.Node{},
EventHandler: handler.EnqueueRequestsFromMapFunc(r.nodeToMachine),
Predicates: []predicate.TypedPredicate[client.Object]{predicates.TypedResourceIsChanged[client.Object](log)},
}))
}

Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/machine/machine_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"sigs.k8s.io/cluster-api/util/conditions"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
)

var externalReadyWait = 30 * time.Second
Expand Down Expand Up @@ -89,7 +90,7 @@ func (r *Reconciler) ensureExternalOwnershipAndWatch(ctx context.Context, cluste
}

// Ensure we add a watch to the external object, if there isn't one already.
if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Machine{})); err != nil {
if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Machine{}), predicates.ResourceIsChanged(log)); err != nil {
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,22 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt

err = ctrl.NewControllerManagedBy(mgr).
For(&clusterv1.MachineDeployment{}).
Owns(&clusterv1.MachineSet{}).
Owns(&clusterv1.MachineSet{}, builder.WithPredicates(predicates.ResourceIsChanged(predicateLog))).
// Watches enqueues MachineDeployment for corresponding MachineSet resources, if no managed controller reference (owner) exists.
Watches(
&clusterv1.MachineSet{},
handler.EnqueueRequestsFromMapFunc(r.MachineSetToDeployments),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(clusterToMachineDeployments),
builder.WithPredicates(
builder.WithPredicates(predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ClusterPausedTransitions(mgr.GetScheme(), predicateLog),
),
)),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
).Complete(r)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -97,6 +98,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(r.machineToMachineHealthCheck),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Expand All @@ -106,6 +108,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
builder.WithPredicates(
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ClusterPausedTransitions(mgr.GetScheme(), predicateLog),
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
),
Expand Down Expand Up @@ -617,6 +620,7 @@ func (r *Reconciler) watchClusterNodes(ctx context.Context, cluster *clusterv1.C
Watcher: r.controller,
Kind: &corev1.Node{},
EventHandler: handler.EnqueueRequestsFromMapFunc(r.nodeToMachineHealthCheck),
Predicates: []predicate.TypedPredicate[client.Object]{predicates.TypedResourceIsChanged[client.Object](ctrl.LoggerFrom(ctx))},
}))
}

Expand Down
5 changes: 4 additions & 1 deletion internal/controllers/machineset/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt

err = ctrl.NewControllerManagedBy(mgr).
For(&clusterv1.MachineSet{}).
Owns(&clusterv1.Machine{}).
Owns(&clusterv1.Machine{}, builder.WithPredicates(predicates.ResourceIsChanged(predicateLog))).
// Watches enqueues MachineSet for corresponding Machine resources, if no managed controller reference (owner) exists.
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(r.MachineToMachineSets),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
Watches(
&clusterv1.MachineDeployment{},
handler.EnqueueRequestsFromMapFunc(mdToMachineSets),
builder.WithPredicates(predicates.ResourceIsChanged(predicateLog)),
).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
Expand All @@ -139,6 +141,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
builder.WithPredicates(
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.All(mgr.GetScheme(), predicateLog,
predicates.ResourceIsChanged(predicateLog),
predicates.ClusterPausedTransitions(mgr.GetScheme(), predicateLog),
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
),
Expand Down
21 changes: 17 additions & 4 deletions internal/controllers/topology/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,25 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Watches(
&clusterv1.ClusterClass{},
handler.EnqueueRequestsFromMapFunc(r.clusterClassToCluster),
builder.WithPredicates(predicates.ResourceIsChanged(r.predicateLog)),
).
Watches(
&clusterv1.MachineDeployment{},
handler.EnqueueRequestsFromMapFunc(r.machineDeploymentToCluster),
// Only trigger Cluster reconciliation if the MachineDeployment is topology owned.
builder.WithPredicates(predicates.ResourceIsTopologyOwned(mgr.GetScheme(), r.predicateLog)),
builder.WithPredicates(predicates.All(mgr.GetScheme(), r.predicateLog,
predicates.ResourceIsChanged(r.predicateLog),
predicates.ResourceIsTopologyOwned(mgr.GetScheme(), r.predicateLog),
)),
).
Watches(
&expv1.MachinePool{},
handler.EnqueueRequestsFromMapFunc(r.machinePoolToCluster),
// Only trigger Cluster reconciliation if the MachinePool is topology owned.
builder.WithPredicates(predicates.ResourceIsTopologyOwned(mgr.GetScheme(), r.predicateLog)),
builder.WithPredicates(predicates.All(mgr.GetScheme(), r.predicateLog,
predicates.ResourceIsChanged(r.predicateLog),
predicates.ResourceIsTopologyOwned(mgr.GetScheme(), r.predicateLog),
)),
).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), r.predicateLog, r.WatchFilterValue)).
Expand Down Expand Up @@ -324,15 +331,21 @@ func (r *Reconciler) setupDynamicWatches(ctx context.Context, s *scope.Scope) er
if err := r.externalTracker.Watch(ctrl.LoggerFrom(ctx), s.Current.InfrastructureCluster,
handler.EnqueueRequestForOwner(scheme, r.Client.RESTMapper(), &clusterv1.Cluster{}),
// Only trigger Cluster reconciliation if the InfrastructureCluster is topology owned.
predicates.ResourceIsTopologyOwned(scheme, r.predicateLog)); err != nil {
predicates.All(scheme, r.predicateLog,
predicates.ResourceIsChanged(r.predicateLog),
predicates.ResourceIsTopologyOwned(scheme, r.predicateLog),
)); err != nil {
return errors.Wrap(err, "error watching Infrastructure CR")
}
}
if s.Current.ControlPlane.Object != nil {
if err := r.externalTracker.Watch(ctrl.LoggerFrom(ctx), s.Current.ControlPlane.Object,
handler.EnqueueRequestForOwner(scheme, r.Client.RESTMapper(), &clusterv1.Cluster{}),
// Only trigger Cluster reconciliation if the ControlPlane is topology owned.
predicates.ResourceIsTopologyOwned(scheme, r.predicateLog)); err != nil {
predicates.All(scheme, r.predicateLog,
predicates.ResourceIsChanged(r.predicateLog),
predicates.ResourceIsTopologyOwned(scheme, r.predicateLog),
)); err != nil {
return errors.Wrap(err, "error watching ControlPlane CR")
}
}
Expand Down
Loading
Loading