@@ -60,8 +60,9 @@ type ControlPlane struct {
60
60
// TalosControlPlaneReconciler reconciles a TalosControlPlane object
61
61
type TalosControlPlaneReconciler struct {
62
62
client.Client
63
- Log logr.Logger
64
- Scheme * runtime.Scheme
63
+ APIReader client.Reader
64
+ Log logr.Logger
65
+ Scheme * runtime.Scheme
65
66
}
66
67
67
68
func (r * TalosControlPlaneReconciler ) SetupWithManager (mgr ctrl.Manager , options controller.Options ) error {
@@ -90,7 +91,7 @@ func (r *TalosControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Re
90
91
91
92
// Fetch the TalosControlPlane instance.
92
93
tcp := & controlplanev1.TalosControlPlane {}
93
- if err := r .Client .Get (ctx , req .NamespacedName , tcp ); err != nil {
94
+ if err := r .APIReader .Get (ctx , req .NamespacedName , tcp ); err != nil {
94
95
if apierrors .IsNotFound (err ) {
95
96
return ctrl.Result {}, nil
96
97
}
@@ -140,13 +141,8 @@ func (r *TalosControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Re
140
141
141
142
// patch and return right away instead of reusing the main defer,
142
143
// because the main defer may take too much time to get cluster status
143
- // Patch ObservedGeneration only if the reconciliation completed successfully
144
- patchOpts := []patch.Option {}
145
- if reterr == nil {
146
- patchOpts = append (patchOpts , patch.WithStatusObservedGeneration {})
147
- }
148
144
149
- if err := patchTalosControlPlane (ctx , patchHelper , tcp , patchOpts ... ); err != nil {
145
+ if err := patchTalosControlPlane (ctx , patchHelper , tcp , patch. WithStatusObservedGeneration {} ); err != nil {
150
146
logger .Error (err , "Failed to add finalizer to TalosControlPlane" )
151
147
return ctrl.Result {}, err
152
148
}
@@ -172,7 +168,7 @@ func (r *TalosControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Re
172
168
}
173
169
174
170
// Always attempt to Patch the TalosControlPlane object and status after each reconciliation.
175
- if err := r . Client . Status (). Update ( ctx , tcp ); err != nil {
171
+ if err := patchTalosControlPlane ( ctx , patchHelper , tcp , patch. WithStatusObservedGeneration {} ); err != nil {
176
172
logger .Error (err , "Failed to patch TalosControlPlane" )
177
173
reterr = kerrors .NewAggregate ([]error {reterr , err })
178
174
}
@@ -627,17 +623,21 @@ func (r *TalosControlPlaneReconciler) bootstrapCluster(ctx context.Context, clus
627
623
628
624
addresses := []string {}
629
625
for _ , machine := range machines {
630
- if len (machine .Status .Addresses ) == 0 {
631
- continue
632
- }
626
+ found := false
633
627
634
628
for _ , addr := range machine .Status .Addresses {
635
629
if addr .Type == clusterv1 .MachineInternalIP {
636
630
addresses = append (addresses , addr .Address )
637
631
632
+ found = true
633
+
638
634
break
639
635
}
640
636
}
637
+
638
+ if ! found {
639
+ return fmt .Errorf ("machine %q doesn't have an InternalIP address yet" , machine .Name )
640
+ }
641
641
}
642
642
643
643
if len (addresses ) == 0 {
0 commit comments