From 009ac6019bdcefe2111e1e1f6c8758fc545c89de Mon Sep 17 00:00:00 2001 From: Pierre Prinetti Date: Thu, 6 Feb 2020 09:15:28 +0100 Subject: [PATCH] Bug 1751471: Machine update: create before delete With this change, the new machine is created first. The desired outcome is that in case the new machine specification is not valid, its creation fails and the old one does not get deleted. Addresses https://bugzilla.redhat.com/show_bug.cgi?id=1751471 --- pkg/cloud/openstack/machine/actuator.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/cloud/openstack/machine/actuator.go b/pkg/cloud/openstack/machine/actuator.go index 9ca53b40a0..867e014a26 100644 --- a/pkg/cloud/openstack/machine/actuator.go +++ b/pkg/cloud/openstack/machine/actuator.go @@ -295,7 +295,7 @@ func (oc *OpenstackClient) Create(ctx context.Context, cluster *clusterv1.Cluste return nil } - oc.eventRecorder.Eventf(machine, corev1.EventTypeNormal, "Created", "Created Machine %v", machine.Name) + oc.eventRecorder.Eventf(machine, corev1.EventTypeNormal, "Created", "Created machine %v", machine.Name) return oc.updateAnnotation(machine, instance.ID) } @@ -363,12 +363,20 @@ func (oc *OpenstackClient) Update(ctx context.Context, cluster *clusterv1.Cluste } if _, ok := currentMachine.Labels["node-role.kubernetes.io/master"]; ok { + // In this conditional block, Machine is Control Plane // TODO: add master inplace klog.Errorf("master inplace update failed: not supported") return oc.handleMachineError(machine, apierrors.UpdateMachine( "master inplace update failed: not supported"), updateEventAction) } else { + // In this conditional block, Machine is Compute Node klog.Infof("re-creating machine %s for update.", currentMachine.ObjectMeta.Name) + err = oc.Create(ctx, cluster, machine) + if err != nil { + klog.Errorf("create machine %s for update failed: %v", machine.ObjectMeta.Name, err) + return fmt.Errorf("Cannot create machine %s: %v", machine.ObjectMeta.Name, err) + } + err = oc.Delete(ctx, cluster, currentMachine) if err != nil { klog.Errorf("delete machine %s for update failed: %v", currentMachine.ObjectMeta.Name, err) @@ -387,11 +395,6 @@ func (oc *OpenstackClient) Update(ctx context.Context, cluster *clusterv1.Cluste return oc.handleMachineError(machine, apierrors.DeleteMachine( "error deleting Openstack instance: %v", err), updateEventAction) } - err = oc.Create(ctx, cluster, machine) - if err != nil { - klog.Errorf("create machine %s for update failed: %v", machine.ObjectMeta.Name, err) - return fmt.Errorf("Cannot create machine %s: %v", machine.ObjectMeta.Name, err) - } klog.Infof("Successfully updated machine %s", currentMachine.ObjectMeta.Name) }