Skip to content

Commit

Permalink
Merge pull request #4208 from sedefsavas/dockermachinepool
Browse files Browse the repository at this point in the history
🐛 Fix docker machine pool status update
  • Loading branch information
k8s-ci-robot authored Feb 22, 2021
2 parents a877397 + 1e8af4d commit 0274cfb
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions test/infrastructure/docker/exp/docker/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,15 @@ func (np *NodePool) refresh() error {
func (np *NodePool) reconcileMachine(ctx context.Context, machine *docker.Machine) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)

machineStatus, err := getInstanceStatusByMachineName(np.dockerMachinePool, machine.Name())
if err != nil {
var machineStatus infrav1exp.DockerMachinePoolInstanceStatus
isFound := false
for _, instanceStatus := range np.dockerMachinePool.Status.Instances {
if instanceStatus.InstanceName == machine.Name() {
machineStatus = instanceStatus
isFound = true
}
}
if !isFound {
log.Info("Creating instance record", "instance", machine.Name())
machineStatus = infrav1exp.DockerMachinePoolInstanceStatus{
InstanceName: machine.Name(),
Expand All @@ -226,6 +233,14 @@ func (np *NodePool) reconcileMachine(ctx context.Context, machine *docker.Machin
return ctrl.Result{Requeue: true}, nil
}

defer func() {
for i, instanceStatus := range np.dockerMachinePool.Status.Instances {
if instanceStatus.InstanceName == machine.Name() {
np.dockerMachinePool.Status.Instances[i] = machineStatus
}
}
}()

externalMachine, err := docker.NewMachine(np.cluster.Name, machine.Name(), np.dockerMachinePool.Spec.Template.CustomImage, np.labelFilters)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to create helper for managing the externalMachine named %s", machine.Name())
Expand Down Expand Up @@ -322,14 +337,3 @@ func getBootstrapData(ctx context.Context, kClient client.Client, machinePool *c

return base64.StdEncoding.EncodeToString(value), nil
}

// getInstanceStatusByMachineName returns the instance status for a given machine by name or error if it doesn't exist
func getInstanceStatusByMachineName(dockerMachinePool *infrav1exp.DockerMachinePool, machineName string) (infrav1exp.DockerMachinePoolInstanceStatus, error) {
var machine infrav1exp.DockerMachinePoolInstanceStatus
for _, machine = range dockerMachinePool.Status.Instances {
if machine.InstanceName == machineName {
return machine, nil
}
}
return machine, errors.Errorf("no machine found with name %s", machineName)
}

0 comments on commit 0274cfb

Please sign in to comment.