@@ -195,6 +195,10 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, cluster *
195
195
196
196
if externalMachine .Exists () {
197
197
conditions .MarkTrue (dockerMachine , infrav1 .ContainerProvisionedCondition )
198
+ // Setting machine address is required after move, because status.Address field is not retained during move.
199
+ if err := setMachineAddress (ctx , dockerMachine , externalMachine ); err != nil {
200
+ return ctrl.Result {}, errors .Wrap (err , "failed to set the machine address" )
201
+ }
198
202
} else {
199
203
conditions .MarkFalse (dockerMachine , infrav1 .ContainerProvisionedCondition , infrav1 .ContainerDeletedReason , clusterv1 .ConditionSeverityError , fmt .Sprintf ("Container %s does not exists anymore" , externalMachine .Name ()))
200
204
}
@@ -291,28 +295,11 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, cluster *
291
295
// Update the BootstrapExecSucceededCondition condition
292
296
conditions .MarkTrue (dockerMachine , infrav1 .BootstrapExecSucceededCondition )
293
297
294
- // set address in machine status
295
- machineAddress , err := externalMachine .Address (ctx )
296
- if err != nil {
297
- log .Error (err , "failed to get the machine address" )
298
+ if err := setMachineAddress (ctx , dockerMachine , externalMachine ); err != nil {
299
+ log .Error (err , "failed to set the machine address" )
298
300
return ctrl.Result {RequeueAfter : 5 * time .Second }, nil
299
301
}
300
302
301
- dockerMachine .Status .Addresses = []clusterv1.MachineAddress {
302
- {
303
- Type : clusterv1 .MachineHostName ,
304
- Address : externalMachine .ContainerName (),
305
- },
306
- {
307
- Type : clusterv1 .MachineInternalIP ,
308
- Address : machineAddress ,
309
- },
310
- {
311
- Type : clusterv1 .MachineExternalIP ,
312
- Address : machineAddress ,
313
- },
314
- }
315
-
316
303
// Usually a cloud provider will do this, but there is no docker-cloud provider.
317
304
// Requeue if there is an error, as this is likely momentary load balancer
318
305
// state changes during control plane provisioning.
@@ -444,3 +431,27 @@ func (r *DockerMachineReconciler) getBootstrapData(ctx context.Context, machine
444
431
445
432
return base64 .StdEncoding .EncodeToString (value ), nil
446
433
}
434
+
435
+ // setMachineAddress gets the address from the container corresponding to a docker node and sets it on the Machine object.
436
+ func setMachineAddress (ctx context.Context , dockerMachine * infrav1.DockerMachine , externalMachine * docker.Machine ) error {
437
+ machineAddress , err := externalMachine .Address (ctx )
438
+ if err != nil {
439
+ return err
440
+ }
441
+
442
+ dockerMachine .Status .Addresses = []clusterv1.MachineAddress {
443
+ {
444
+ Type : clusterv1 .MachineHostName ,
445
+ Address : externalMachine .ContainerName (),
446
+ },
447
+ {
448
+ Type : clusterv1 .MachineInternalIP ,
449
+ Address : machineAddress ,
450
+ },
451
+ {
452
+ Type : clusterv1 .MachineExternalIP ,
453
+ Address : machineAddress ,
454
+ },
455
+ }
456
+ return nil
457
+ }
0 commit comments