@@ -101,7 +101,7 @@ func (r *AgentMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request
101
101
}
102
102
if machine == nil {
103
103
log .Info ("Waiting for Machine Controller to set OwnerRef on AgentMachine" )
104
- return r .updateStatus (ctx , log , agentMachine , ctrl. Result {} , nil )
104
+ return ctrl. Result {}, r .updateStatus (ctx , log , agentMachine , nil )
105
105
}
106
106
107
107
res , err := r .handleDeletionHook (ctx , log , agentMachine , machine )
@@ -120,7 +120,9 @@ func (r *AgentMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request
120
120
}
121
121
122
122
if agentCluster .Status .ClusterDeploymentRef .Name == "" {
123
- return r .updateStatus (ctx , log , agentMachine , ctrl.Result {}, fmt .Errorf ("No cluster deployment reference on agentCluster %s" , agentCluster .GetName ()))
123
+ err = fmt .Errorf ("No cluster deployment reference on agentCluster %s" , agentCluster .GetName ())
124
+ log .Warning (err .Error ())
125
+ return ctrl.Result {}, r .updateStatus (ctx , log , agentMachine , err )
124
126
}
125
127
126
128
machineConfigPool , ignitionTokenSecretRef , err := r .processBootstrapDataSecret (ctx , log , machine )
@@ -130,20 +132,21 @@ func (r *AgentMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request
130
132
131
133
// If the AgentMachine doesn't have an agent, find one and set the agentRef
132
134
if agentMachine .Status .AgentRef == nil {
133
- foundAgent , err := r .findAgent (ctx , log , agentMachine , agentCluster .Status .ClusterDeploymentRef , machineConfigPool , ignitionTokenSecretRef )
135
+ var foundAgent * aiv1beta1.Agent
136
+ foundAgent , err = r .findAgent (ctx , log , agentMachine , agentCluster .Status .ClusterDeploymentRef , machineConfigPool , ignitionTokenSecretRef )
134
137
if foundAgent == nil || err != nil {
135
- return r .updateStatus (ctx , log , agentMachine , ctrl. Result {} , err )
138
+ return ctrl. Result {}, r .updateStatus (ctx , log , agentMachine , err )
136
139
}
137
140
138
141
err = r .updateAgentMachineWithFoundAgent (ctx , log , agentMachine , foundAgent )
139
142
if err != nil {
140
143
log .WithError (err ).Error ("failed to update AgentMachine with found agent" )
141
- return r .updateStatus (ctx , log , agentMachine , ctrl. Result {} , err )
144
+ return ctrl. Result {}, r .updateStatus (ctx , log , agentMachine , err )
142
145
}
143
146
}
144
147
145
148
// If the AgentMachine has an agent, check its conditions and update ready/error
146
- return r .updateStatus (ctx , log , agentMachine , ctrl. Result {} , nil )
149
+ return ctrl. Result {}, r .updateStatus (ctx , log , agentMachine , nil )
147
150
}
148
151
149
152
func (r * AgentMachineReconciler ) removeMachineDeletionHookAnnotation (ctx context.Context , machine * clusterv1.Machine ) (err error ) {
@@ -479,27 +482,27 @@ func isValidAgent(agent *aiv1beta1.Agent, agentMachine *capiproviderv1alpha1.Age
479
482
return true
480
483
}
481
484
482
- func (r * AgentMachineReconciler ) updateStatus (ctx context.Context , log logrus.FieldLogger , agentMachine * capiproviderv1alpha1.AgentMachine , origRes ctrl.Result , origErr error ) (ctrl.Result , error ) {
483
- installationInProgress := false
484
- conditionPassed := setAgentReservedCondition (agentMachine , origErr )
485
+ func (r * AgentMachineReconciler ) updateStatus (ctx context.Context , log logrus.FieldLogger , agentMachine * capiproviderv1alpha1.AgentMachine , err error ) error {
486
+ conditionPassed := setAgentReservedCondition (agentMachine , err )
485
487
if ! conditionPassed {
486
488
conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .AgentSpecSyncedCondition , capiproviderv1alpha1 .AgentNotYetFoundReason , clusterv1 .ConditionSeverityInfo , "Agent not yet reserved" )
487
489
conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .AgentValidatedCondition , capiproviderv1alpha1 .AgentNotYetFoundReason , clusterv1 .ConditionSeverityInfo , "Agent not yet reserved" )
488
490
conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .AgentRequirementsMetCondition , capiproviderv1alpha1 .AgentNotYetFoundReason , clusterv1 .ConditionSeverityInfo , "Agent not yet reserved" )
489
491
conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .InstalledCondition , capiproviderv1alpha1 .AgentNotYetFoundReason , clusterv1 .ConditionSeverityInfo , "Agent not yet reserved" )
490
- return r .setStatus (ctx , log , agentMachine , origRes , origErr , installationInProgress )
492
+ err = r .setStatus (ctx , log , agentMachine )
493
+ return err
491
494
}
492
495
493
- agent , err := r .getAgent (ctx , log , agentMachine )
494
- if err != nil {
495
- return ctrl. Result {}, err
496
+ agent , getErr := r .getAgent (ctx , log , agentMachine )
497
+ if getErr != nil {
498
+ return getErr
496
499
}
497
-
498
500
setConditionByAgentCondition (agentMachine , agent , capiproviderv1alpha1 .AgentSpecSyncedCondition , aiv1beta1 .SpecSyncedCondition , clusterv1 .ConditionSeverityError )
499
501
setConditionByAgentCondition (agentMachine , agent , capiproviderv1alpha1 .AgentValidatedCondition , aiv1beta1 .ValidatedCondition , clusterv1 .ConditionSeverityError )
500
502
setConditionByAgentCondition (agentMachine , agent , capiproviderv1alpha1 .AgentRequirementsMetCondition , aiv1beta1 .RequirementsMetCondition , clusterv1 .ConditionSeverityError )
501
- installationInProgress = ! setConditionByAgentCondition (agentMachine , agent , capiproviderv1alpha1 .InstalledCondition , aiv1beta1 .InstalledCondition , clusterv1 .ConditionSeverityInfo )
502
- return r .setStatus (ctx , log , agentMachine , origRes , origErr , installationInProgress )
503
+ setConditionByAgentCondition (agentMachine , agent , capiproviderv1alpha1 .InstalledCondition , aiv1beta1 .InstalledCondition , clusterv1 .ConditionSeverityInfo )
504
+ err = r .setStatus (ctx , log , agentMachine )
505
+ return err
503
506
}
504
507
505
508
func (r * AgentMachineReconciler ) getAgent (ctx context.Context , log logrus.FieldLogger , agentMachine * capiproviderv1alpha1.AgentMachine ) (* aiv1beta1.Agent , error ) {
@@ -532,12 +535,12 @@ func setConditionByAgentCondition(agentMachine *capiproviderv1alpha1.AgentMachin
532
535
return false
533
536
}
534
537
535
- func setAgentReservedCondition (agentMachine * capiproviderv1alpha1.AgentMachine , origErr error ) bool {
538
+ func setAgentReservedCondition (agentMachine * capiproviderv1alpha1.AgentMachine , err error ) bool {
536
539
if agentMachine .Status .AgentRef == nil {
537
- if origErr == nil {
540
+ if err == nil {
538
541
conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .AgentReservedCondition , capiproviderv1alpha1 .NoSuitableAgentsReason , clusterv1 .ConditionSeverityWarning , "" )
539
542
} else {
540
- conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .AgentReservedCondition , capiproviderv1alpha1 .AgentNotYetFoundReason , clusterv1 .ConditionSeverityInfo , origErr .Error ())
543
+ conditions .MarkFalse (agentMachine , capiproviderv1alpha1 .AgentReservedCondition , capiproviderv1alpha1 .AgentNotYetFoundReason , clusterv1 .ConditionSeverityInfo , err .Error ())
541
544
}
542
545
return false
543
546
}
@@ -546,7 +549,7 @@ func setAgentReservedCondition(agentMachine *capiproviderv1alpha1.AgentMachine,
546
549
return true
547
550
}
548
551
549
- func (r * AgentMachineReconciler ) setStatus (ctx context.Context , log logrus.FieldLogger , agentMachine * capiproviderv1alpha1.AgentMachine , origRes ctrl. Result , origErr error , installationInProgress bool ) (ctrl. Result , error ) {
552
+ func (r * AgentMachineReconciler ) setStatus (ctx context.Context , log logrus.FieldLogger , agentMachine * capiproviderv1alpha1.AgentMachine ) error {
550
553
conditions .SetSummary (agentMachine ,
551
554
conditions .WithConditions (capiproviderv1alpha1 .AgentReservedCondition ,
552
555
capiproviderv1alpha1 .AgentSpecSyncedCondition ,
@@ -559,12 +562,11 @@ func (r *AgentMachineReconciler) setStatus(ctx context.Context, log logrus.Field
559
562
560
563
agentMachine .Status .Ready , _ = strconv .ParseBool (string (conditions .Get (agentMachine , clusterv1 .ReadyCondition ).Status ))
561
564
562
- if updateErr := r .Status ().Update (ctx , agentMachine ); updateErr != nil {
563
- log . WithError ( updateErr ). Error ( "failed to update AgentMachine Status" )
564
- return ctrl. Result {}, updateErr
565
+ err := r .Status ().Update (ctx , agentMachine )
566
+ if err != nil {
567
+ log . WithError ( err ). Error ( "failed to update AgentMachine Status" )
565
568
}
566
-
567
- return origRes , origErr
569
+ return err
568
570
}
569
571
570
572
func getAddresses (foundAgent * aiv1beta1.Agent ) []clusterv1.MachineAddress {
0 commit comments