@@ -29,17 +29,17 @@ import (
29
29
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30
30
"k8s.io/apimachinery/pkg/runtime/schema"
31
31
"k8s.io/utils/pointer"
32
- "sigs.k8s.io/cluster-api/util/annotations"
33
- "sigs.k8s.io/cluster-api/util/conditions"
34
- utilconversion "sigs.k8s.io/cluster-api/util/conversion"
35
- "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
36
- "sigs.k8s.io/controller-runtime/pkg/handler"
37
-
38
32
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
39
33
"sigs.k8s.io/cluster-api/controllers/external"
40
34
capierrors "sigs.k8s.io/cluster-api/errors"
41
35
"sigs.k8s.io/cluster-api/util"
36
+ "sigs.k8s.io/cluster-api/util/annotations"
37
+ "sigs.k8s.io/cluster-api/util/conditions"
38
+ utilconversion "sigs.k8s.io/cluster-api/util/conversion"
42
39
"sigs.k8s.io/cluster-api/util/patch"
40
+ ctrl "sigs.k8s.io/controller-runtime"
41
+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
42
+ "sigs.k8s.io/controller-runtime/pkg/handler"
43
43
)
44
44
45
45
var (
@@ -172,38 +172,40 @@ func (r *MachineReconciler) reconcileExternal(ctx context.Context, cluster *clus
172
172
}
173
173
174
174
// reconcileBootstrap reconciles the Spec.Bootstrap.ConfigRef object on a Machine.
175
- func (r * MachineReconciler ) reconcileBootstrap (ctx context.Context , cluster * clusterv1.Cluster , m * clusterv1.Machine ) error {
175
+ func (r * MachineReconciler ) reconcileBootstrap (ctx context.Context , cluster * clusterv1.Cluster , m * clusterv1.Machine ) (ctrl.Result , error ) {
176
+ logger := r .Log .WithValues ("machine" , m .Name , "namespace" , m .Namespace )
177
+
176
178
// If the bootstrap data is populated, set ready and return.
177
179
if m .Spec .Bootstrap .DataSecretName != nil {
178
180
m .Status .BootstrapReady = true
179
181
conditions .MarkTrue (m , clusterv1 .BootstrapReadyCondition )
180
- return nil
182
+ return ctrl. Result {}, nil
181
183
}
182
184
183
185
// If the Boostrap ref is nil (and so the machine should use user generated data secret), return.
184
186
if m .Spec .Bootstrap .ConfigRef == nil {
185
- return nil
187
+ return ctrl. Result {}, nil
186
188
}
187
189
188
190
// Call generic external reconciler if we have an external reference.
189
191
externalResult , err := r .reconcileExternal (ctx , cluster , m , m .Spec .Bootstrap .ConfigRef )
190
192
if err != nil {
191
- return err
193
+ return ctrl. Result {}, err
192
194
}
193
195
if externalResult .Paused {
194
- return nil
196
+ return ctrl. Result {}, nil
195
197
}
196
198
bootstrapConfig := externalResult .Result
197
199
198
200
// If the bootstrap config is being deleted, return early.
199
201
if ! bootstrapConfig .GetDeletionTimestamp ().IsZero () {
200
- return nil
202
+ return ctrl. Result {}, nil
201
203
}
202
204
203
205
// Determine if the bootstrap provider is ready.
204
206
ready , err := external .IsReady (bootstrapConfig )
205
207
if err != nil {
206
- return err
208
+ return ctrl. Result {}, err
207
209
}
208
210
209
211
// Report a summary of current status of the bootstrap object defined for this machine.
@@ -214,26 +216,28 @@ func (r *MachineReconciler) reconcileBootstrap(ctx context.Context, cluster *clu
214
216
215
217
// If the bootstrap provider is not ready, requeue.
216
218
if ! ready {
217
- return errors . Wrapf ( & capierrors. RequeueAfterError { RequeueAfter : externalReadyWait },
218
- "Bootstrap provider for Machine %q in namespace %q is not ready, requeuing" , m . Name , m . Namespace )
219
+ logger . Info ( "Bootstrap provider is not ready, requeuing" )
220
+ return ctrl. Result { RequeueAfter : externalReadyWait }, nil
219
221
}
220
222
221
223
// Get and set the name of the secret containing the bootstrap data.
222
224
secretName , _ , err := unstructured .NestedString (bootstrapConfig .Object , "status" , "dataSecretName" )
223
225
if err != nil {
224
- return errors .Wrapf (err , "failed to retrieve dataSecretName from bootstrap provider for Machine %q in namespace %q" , m .Name , m .Namespace )
226
+ return ctrl. Result {}, errors .Wrapf (err , "failed to retrieve dataSecretName from bootstrap provider for Machine %q in namespace %q" , m .Name , m .Namespace )
225
227
} else if secretName == "" {
226
- return errors .Errorf ("retrieved empty dataSecretName from bootstrap provider for Machine %q in namespace %q" , m .Name , m .Namespace )
228
+ return ctrl. Result {}, errors .Errorf ("retrieved empty dataSecretName from bootstrap provider for Machine %q in namespace %q" , m .Name , m .Namespace )
227
229
}
228
230
229
231
m .Spec .Bootstrap .Data = nil
230
232
m .Spec .Bootstrap .DataSecretName = pointer .StringPtr (secretName )
231
233
m .Status .BootstrapReady = true
232
- return nil
234
+ return ctrl. Result {}, nil
233
235
}
234
236
235
237
// reconcileInfrastructure reconciles the Spec.InfrastructureRef object on a Machine.
236
- func (r * MachineReconciler ) reconcileInfrastructure (ctx context.Context , cluster * clusterv1.Cluster , m * clusterv1.Machine ) error {
238
+ func (r * MachineReconciler ) reconcileInfrastructure (ctx context.Context , cluster * clusterv1.Cluster , m * clusterv1.Machine ) (ctrl.Result , error ) {
239
+ logger := r .Log .WithValues ("machine" , m .Name , "namespace" , m .Namespace )
240
+
237
241
// Call generic external reconciler.
238
242
infraReconcileResult , err := r .reconcileExternal (ctx , cluster , m , & m .Spec .InfrastructureRef )
239
243
if err != nil {
@@ -244,22 +248,22 @@ func (r *MachineReconciler) reconcileInfrastructure(ctx context.Context, cluster
244
248
m .Status .FailureMessage = pointer .StringPtr (fmt .Sprintf ("Machine infrastructure resource %v with name %q has been deleted after being ready" ,
245
249
m .Spec .InfrastructureRef .GroupVersionKind (), m .Spec .InfrastructureRef .Name ))
246
250
}
247
- return err
251
+ return ctrl. Result {}, err
248
252
}
249
253
// if the external object is paused, return without any further processing
250
254
if infraReconcileResult .Paused {
251
- return nil
255
+ return ctrl. Result {}, nil
252
256
}
253
257
infraConfig := infraReconcileResult .Result
254
258
255
259
if ! infraConfig .GetDeletionTimestamp ().IsZero () {
256
- return nil
260
+ return ctrl. Result {}, nil
257
261
}
258
262
259
263
// Determine if the infrastructure provider is ready.
260
264
ready , err := external .IsReady (infraConfig )
261
265
if err != nil {
262
- return err
266
+ return ctrl. Result {}, err
263
267
}
264
268
m .Status .InfrastructureReady = ready
265
269
@@ -271,23 +275,22 @@ func (r *MachineReconciler) reconcileInfrastructure(ctx context.Context, cluster
271
275
272
276
// If the infrastructure provider is not ready, return early.
273
277
if ! ready {
274
- return errors .Wrapf (& capierrors.RequeueAfterError {RequeueAfter : externalReadyWait },
275
- "Infrastructure provider for Machine %q in namespace %q is not ready, requeuing" , m .Name , m .Namespace ,
276
- )
278
+ logger .Info ("Infrastructure provider is not ready, requeuing" )
279
+ return ctrl.Result {RequeueAfter : externalReadyWait }, nil
277
280
}
278
281
279
282
// Get Spec.ProviderID from the infrastructure provider.
280
283
var providerID string
281
284
if err := util .UnstructuredUnmarshalField (infraConfig , & providerID , "spec" , "providerID" ); err != nil {
282
- return errors .Wrapf (err , "failed to retrieve Spec.ProviderID from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
285
+ return ctrl. Result {}, errors .Wrapf (err , "failed to retrieve Spec.ProviderID from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
283
286
} else if providerID == "" {
284
- return errors .Errorf ("retrieved empty Spec.ProviderID from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
287
+ return ctrl. Result {}, errors .Errorf ("retrieved empty Spec.ProviderID from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
285
288
}
286
289
287
290
// Get and set Status.Addresses from the infrastructure provider.
288
291
err = util .UnstructuredUnmarshalField (infraConfig , & m .Status .Addresses , "status" , "addresses" )
289
292
if err != nil && err != util .ErrUnstructuredFieldNotFound {
290
- return errors .Wrapf (err , "failed to retrieve addresses from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
293
+ return ctrl. Result {}, errors .Wrapf (err , "failed to retrieve addresses from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
291
294
}
292
295
293
296
// Get and set the failure domain from the infrastructure provider.
@@ -296,11 +299,11 @@ func (r *MachineReconciler) reconcileInfrastructure(ctx context.Context, cluster
296
299
switch {
297
300
case err == util .ErrUnstructuredFieldNotFound : // no-op
298
301
case err != nil :
299
- return errors .Wrapf (err , "failed to failure domain from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
302
+ return ctrl. Result {}, errors .Wrapf (err , "failed to failure domain from infrastructure provider for Machine %q in namespace %q" , m .Name , m .Namespace )
300
303
default :
301
304
m .Spec .FailureDomain = pointer .StringPtr (failureDomain )
302
305
}
303
306
304
307
m .Spec .ProviderID = pointer .StringPtr (providerID )
305
- return nil
308
+ return ctrl. Result {}, nil
306
309
}
0 commit comments