Skip to content

Commit b242fa6

Browse files
committed
Reconcile dockermachine.status.address after move
Clusterctl move resets all status fields including the status.Address field. After move, docker machine controller checks if the providerID field is set on spec, and then sets the machine.Status.Ready field to true and does not reconcile the machine further. Due to this the address field never gets reconciled on a dockerMachine after move. This commit sets the machine address if the corresponding container exists.
1 parent e33f04d commit b242fa6

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

test/infrastructure/docker/internal/controllers/dockermachine_controller.go

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, cluster *
195195

196196
if externalMachine.Exists() {
197197
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+
}
198202
} else {
199203
conditions.MarkFalse(dockerMachine, infrav1.ContainerProvisionedCondition, infrav1.ContainerDeletedReason, clusterv1.ConditionSeverityError, fmt.Sprintf("Container %s does not exists anymore", externalMachine.Name()))
200204
}
@@ -291,28 +295,11 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, cluster *
291295
// Update the BootstrapExecSucceededCondition condition
292296
conditions.MarkTrue(dockerMachine, infrav1.BootstrapExecSucceededCondition)
293297

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")
298300
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
299301
}
300302

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-
316303
// Usually a cloud provider will do this, but there is no docker-cloud provider.
317304
// Requeue if there is an error, as this is likely momentary load balancer
318305
// state changes during control plane provisioning.
@@ -444,3 +431,27 @@ func (r *DockerMachineReconciler) getBootstrapData(ctx context.Context, machine
444431

445432
return base64.StdEncoding.EncodeToString(value), nil
446433
}
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

Comments
 (0)