@@ -172,9 +172,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
172
172
return result , err
173
173
}
174
174
175
- func patchMachineDeployment (ctx context.Context , patchHelper * patch.Helper , d * clusterv1.MachineDeployment , options ... patch.Option ) error {
175
+ func patchMachineDeployment (ctx context.Context , patchHelper * patch.Helper , md * clusterv1.MachineDeployment , options ... patch.Option ) error {
176
176
// Always update the readyCondition by summarizing the state of other conditions.
177
- conditions .SetSummary (d ,
177
+ conditions .SetSummary (md ,
178
178
conditions .WithConditions (
179
179
clusterv1 .MachineDeploymentAvailableCondition ,
180
180
),
@@ -187,29 +187,29 @@ func patchMachineDeployment(ctx context.Context, patchHelper *patch.Helper, d *c
187
187
clusterv1 .MachineDeploymentAvailableCondition ,
188
188
}},
189
189
)
190
- return patchHelper .Patch (ctx , d , options ... )
190
+ return patchHelper .Patch (ctx , md , options ... )
191
191
}
192
192
193
- func (r * Reconciler ) reconcile (ctx context.Context , cluster * clusterv1.Cluster , d * clusterv1.MachineDeployment ) (ctrl.Result , error ) {
193
+ func (r * Reconciler ) reconcile (ctx context.Context , cluster * clusterv1.Cluster , md * clusterv1.MachineDeployment ) (ctrl.Result , error ) {
194
194
log := ctrl .LoggerFrom (ctx )
195
195
log .V (4 ).Info ("Reconcile MachineDeployment" )
196
196
197
197
// Reconcile and retrieve the Cluster object.
198
- if d .Labels == nil {
199
- d .Labels = make (map [string ]string )
198
+ if md .Labels == nil {
199
+ md .Labels = make (map [string ]string )
200
200
}
201
- if d .Spec .Selector .MatchLabels == nil {
202
- d .Spec .Selector .MatchLabels = make (map [string ]string )
201
+ if md .Spec .Selector .MatchLabels == nil {
202
+ md .Spec .Selector .MatchLabels = make (map [string ]string )
203
203
}
204
- if d .Spec .Template .Labels == nil {
205
- d .Spec .Template .Labels = make (map [string ]string )
204
+ if md .Spec .Template .Labels == nil {
205
+ md .Spec .Template .Labels = make (map [string ]string )
206
206
}
207
207
208
- d .Labels [clusterv1 .ClusterNameLabel ] = d .Spec .ClusterName
208
+ md .Labels [clusterv1 .ClusterNameLabel ] = md .Spec .ClusterName
209
209
210
210
// Set the MachineDeployment as directly owned by the Cluster (if not already present).
211
- if r .shouldAdopt (d ) {
212
- d .OwnerReferences = util .EnsureOwnerRef (d .OwnerReferences , metav1.OwnerReference {
211
+ if r .shouldAdopt (md ) {
212
+ md .OwnerReferences = util .EnsureOwnerRef (md .OwnerReferences , metav1.OwnerReference {
213
213
APIVersion : clusterv1 .GroupVersion .String (),
214
214
Kind : "Cluster" ,
215
215
Name : cluster .Name ,
@@ -219,17 +219,17 @@ func (r *Reconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster,
219
219
}
220
220
221
221
// Make sure to reconcile the external infrastructure reference.
222
- if err := reconcileExternalTemplateReference (ctx , r .Client , cluster , & d .Spec .Template .Spec .InfrastructureRef ); err != nil {
222
+ if err := reconcileExternalTemplateReference (ctx , r .Client , cluster , & md .Spec .Template .Spec .InfrastructureRef ); err != nil {
223
223
return ctrl.Result {}, err
224
224
}
225
225
// Make sure to reconcile the external bootstrap reference, if any.
226
- if d .Spec .Template .Spec .Bootstrap .ConfigRef != nil {
227
- if err := reconcileExternalTemplateReference (ctx , r .Client , cluster , d .Spec .Template .Spec .Bootstrap .ConfigRef ); err != nil {
226
+ if md .Spec .Template .Spec .Bootstrap .ConfigRef != nil {
227
+ if err := reconcileExternalTemplateReference (ctx , r .Client , cluster , md .Spec .Template .Spec .Bootstrap .ConfigRef ); err != nil {
228
228
return ctrl.Result {}, err
229
229
}
230
230
}
231
231
232
- msList , err := r .getMachineSetsForDeployment (ctx , d )
232
+ msList , err := r .getMachineSetsForDeployment (ctx , md )
233
233
if err != nil {
234
234
return ctrl.Result {}, err
235
235
}
@@ -241,15 +241,15 @@ func (r *Reconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster,
241
241
// to all MachineSets created by a MachineDeployment or if a user manually removed the label.
242
242
for idx := range msList {
243
243
machineSet := msList [idx ]
244
- if name , ok := machineSet .Labels [clusterv1 .MachineDeploymentNameLabel ]; ok && name == d .Name {
244
+ if name , ok := machineSet .Labels [clusterv1 .MachineDeploymentNameLabel ]; ok && name == md .Name {
245
245
continue
246
246
}
247
247
248
248
helper , err := patch .NewHelper (machineSet , r .Client )
249
249
if err != nil {
250
250
return ctrl.Result {}, errors .Wrapf (err , "failed to apply %s label to MachineSet %q" , clusterv1 .MachineDeploymentNameLabel , machineSet .Name )
251
251
}
252
- machineSet .Labels [clusterv1 .MachineDeploymentNameLabel ] = d .Name
252
+ machineSet .Labels [clusterv1 .MachineDeploymentNameLabel ] = md .Name
253
253
if err := helper .Patch (ctx , machineSet ); err != nil {
254
254
return ctrl.Result {}, errors .Wrapf (err , "failed to apply %s label to MachineSet %q" , clusterv1 .MachineDeploymentNameLabel , machineSet .Name )
255
255
}
@@ -268,43 +268,43 @@ func (r *Reconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster,
268
268
}
269
269
}
270
270
271
- if d .Spec .Paused {
272
- return ctrl.Result {}, r .sync (ctx , d , msList )
271
+ if md .Spec .Paused {
272
+ return ctrl.Result {}, r .sync (ctx , md , msList )
273
273
}
274
274
275
- if d .Spec .Strategy == nil {
275
+ if md .Spec .Strategy == nil {
276
276
return ctrl.Result {}, errors .Errorf ("missing MachineDeployment strategy" )
277
277
}
278
278
279
- if d .Spec .Strategy .Type == clusterv1 .RollingUpdateMachineDeploymentStrategyType {
280
- if d .Spec .Strategy .RollingUpdate == nil {
281
- return ctrl.Result {}, errors .Errorf ("missing MachineDeployment settings for strategy type: %s" , d .Spec .Strategy .Type )
279
+ if md .Spec .Strategy .Type == clusterv1 .RollingUpdateMachineDeploymentStrategyType {
280
+ if md .Spec .Strategy .RollingUpdate == nil {
281
+ return ctrl.Result {}, errors .Errorf ("missing MachineDeployment settings for strategy type: %s" , md .Spec .Strategy .Type )
282
282
}
283
- return ctrl.Result {}, r .rolloutRolling (ctx , d , msList )
283
+ return ctrl.Result {}, r .rolloutRolling (ctx , md , msList )
284
284
}
285
285
286
- if d .Spec .Strategy .Type == clusterv1 .OnDeleteMachineDeploymentStrategyType {
287
- return ctrl.Result {}, r .rolloutOnDelete (ctx , d , msList )
286
+ if md .Spec .Strategy .Type == clusterv1 .OnDeleteMachineDeploymentStrategyType {
287
+ return ctrl.Result {}, r .rolloutOnDelete (ctx , md , msList )
288
288
}
289
289
290
- return ctrl.Result {}, errors .Errorf ("unexpected deployment strategy type: %s" , d .Spec .Strategy .Type )
290
+ return ctrl.Result {}, errors .Errorf ("unexpected deployment strategy type: %s" , md .Spec .Strategy .Type )
291
291
}
292
292
293
293
// getMachineSetsForDeployment returns a list of MachineSets associated with a MachineDeployment.
294
- func (r * Reconciler ) getMachineSetsForDeployment (ctx context.Context , d * clusterv1.MachineDeployment ) ([]* clusterv1.MachineSet , error ) {
294
+ func (r * Reconciler ) getMachineSetsForDeployment (ctx context.Context , md * clusterv1.MachineDeployment ) ([]* clusterv1.MachineSet , error ) {
295
295
log := ctrl .LoggerFrom (ctx )
296
296
297
297
// List all MachineSets to find those we own but that no longer match our selector.
298
298
machineSets := & clusterv1.MachineSetList {}
299
- if err := r .Client .List (ctx , machineSets , client .InNamespace (d .Namespace )); err != nil {
299
+ if err := r .Client .List (ctx , machineSets , client .InNamespace (md .Namespace )); err != nil {
300
300
return nil , err
301
301
}
302
302
303
303
filtered := make ([]* clusterv1.MachineSet , 0 , len (machineSets .Items ))
304
304
for idx := range machineSets .Items {
305
305
ms := & machineSets .Items [idx ]
306
306
log .WithValues ("MachineSet" , klog .KObj (ms ))
307
- selector , err := metav1 .LabelSelectorAsSelector (& d .Spec .Selector )
307
+ selector , err := metav1 .LabelSelectorAsSelector (& md .Spec .Selector )
308
308
if err != nil {
309
309
log .Error (err , "Skipping MachineSet, failed to get label selector from spec selector" )
310
310
continue
@@ -317,23 +317,23 @@ func (r *Reconciler) getMachineSetsForDeployment(ctx context.Context, d *cluster
317
317
}
318
318
319
319
// Skip this MachineSet unless either selector matches or it has a controller ref pointing to this MachineDeployment
320
- if ! selector .Matches (labels .Set (ms .Labels )) && ! metav1 .IsControlledBy (ms , d ) {
320
+ if ! selector .Matches (labels .Set (ms .Labels )) && ! metav1 .IsControlledBy (ms , md ) {
321
321
log .V (4 ).Info ("Skipping MachineSet, label mismatch" )
322
322
continue
323
323
}
324
324
325
325
// Attempt to adopt MachineSet if it meets previous conditions and it has no controller references.
326
326
if metav1 .GetControllerOf (ms ) == nil {
327
- if err := r .adoptOrphan (ctx , d , ms ); err != nil {
327
+ if err := r .adoptOrphan (ctx , md , ms ); err != nil {
328
328
log .Error (err , "Failed to adopt MachineSet into MachineDeployment" )
329
- r .recorder .Eventf (d , corev1 .EventTypeWarning , "FailedAdopt" , "Failed to adopt MachineSet %q: %v" , ms .Name , err )
329
+ r .recorder .Eventf (md , corev1 .EventTypeWarning , "FailedAdopt" , "Failed to adopt MachineSet %q: %v" , ms .Name , err )
330
330
continue
331
331
}
332
332
log .Info ("Adopted MachineSet into MachineDeployment" )
333
- r .recorder .Eventf (d , corev1 .EventTypeNormal , "SuccessfulAdopt" , "Adopted MachineSet %q" , ms .Name )
333
+ r .recorder .Eventf (md , corev1 .EventTypeNormal , "SuccessfulAdopt" , "Adopted MachineSet %q" , ms .Name )
334
334
}
335
335
336
- if ! metav1 .IsControlledBy (ms , d ) {
336
+ if ! metav1 .IsControlledBy (ms , md ) {
337
337
continue
338
338
}
339
339
0 commit comments