@@ -30,6 +30,7 @@ import (
30
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
31
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
32
32
"k8s.io/apimachinery/pkg/runtime"
33
+ "k8s.io/apimachinery/pkg/types"
33
34
kerrors "k8s.io/apimachinery/pkg/util/errors"
34
35
"k8s.io/client-go/tools/record"
35
36
"k8s.io/klog/v2"
@@ -106,6 +107,14 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
106
107
& clusterv1.Machine {},
107
108
handler .EnqueueRequestsFromMapFunc (r .controlPlaneMachineToCluster ),
108
109
).
110
+ Watches (
111
+ & clusterv1.MachineDeployment {},
112
+ handler .EnqueueRequestsFromMapFunc (r .machineDeploymentToCluster ),
113
+ ).
114
+ Watches (
115
+ & expv1.MachinePool {},
116
+ handler .EnqueueRequestsFromMapFunc (r .machinePoolToCluster ),
117
+ ).
109
118
WithOptions (options ).
110
119
WithEventFilter (predicates .ResourceHasFilterLabel (mgr .GetScheme (), predicateLog , r .WatchFilterValue )).
111
120
Build (r )
@@ -726,3 +735,41 @@ func (r *Reconciler) controlPlaneMachineToCluster(ctx context.Context, o client.
726
735
NamespacedName : util .ObjectKey (cluster ),
727
736
}}
728
737
}
738
+
739
+ // machineDeploymentToCluster is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
740
+ // for Cluster to update when one of its own MachineDeployments gets updated.
741
+ func (r * Reconciler ) machineDeploymentToCluster (_ context.Context , o client.Object ) []ctrl.Request {
742
+ md , ok := o .(* clusterv1.MachineDeployment )
743
+ if ! ok {
744
+ panic (fmt .Sprintf ("Expected a MachineDeployment but got a %T" , o ))
745
+ }
746
+ if md .Spec .ClusterName == "" {
747
+ return nil
748
+ }
749
+
750
+ return []ctrl.Request {{
751
+ NamespacedName : types.NamespacedName {
752
+ Namespace : md .Namespace ,
753
+ Name : md .Spec .ClusterName ,
754
+ },
755
+ }}
756
+ }
757
+
758
+ // machinePoolToCluster is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
759
+ // for Cluster to update when one of its own MachinePools gets updated.
760
+ func (r * Reconciler ) machinePoolToCluster (_ context.Context , o client.Object ) []ctrl.Request {
761
+ mp , ok := o .(* expv1.MachinePool )
762
+ if ! ok {
763
+ panic (fmt .Sprintf ("Expected a MachinePool but got a %T" , o ))
764
+ }
765
+ if mp .Spec .ClusterName == "" {
766
+ return nil
767
+ }
768
+
769
+ return []ctrl.Request {{
770
+ NamespacedName : types.NamespacedName {
771
+ Namespace : mp .Namespace ,
772
+ Name : mp .Spec .ClusterName ,
773
+ },
774
+ }}
775
+ }
0 commit comments