Skip to content

Commit

Permalink
only update the status once for node recreation
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanad committed Dec 3, 2018
1 parent 9b8fd56 commit a5b920d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
8 changes: 6 additions & 2 deletions pkg/cloud/azure/actuators/machine/machineactuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (azure *AzureClient) Update(cluster *clusterv1.Cluster, goalMachine *cluste
if err != nil || vm == nil {
return fmt.Errorf("error checking if vm exists: %v", err)
}
// update annotations for bootstrap machine
if vm != nil {
return azure.updateAnnotations(cluster, goalMachine)
}
Expand All @@ -153,6 +154,7 @@ func (azure *AzureClient) Update(cluster *clusterv1.Cluster, goalMachine *cluste
if err != nil {
return fmt.Errorf("error updating master machine %v in place: %v", currentMachine.ObjectMeta.Name, err)
}
return azure.updateStatus(goalMachine)
} else {
// delete and recreate machine for nodes
glog.Infof("replacing node machine %v", currentMachine.ObjectMeta.Name)
Expand All @@ -165,7 +167,7 @@ func (azure *AzureClient) Update(cluster *clusterv1.Cluster, goalMachine *cluste
glog.Errorf("error updating node machine %v, creating node machine failed: %v", goalMachine.ObjectMeta.Name, err)
}
}
return azure.updateStatus(goalMachine)
return nil
}

func (azure *AzureClient) updateMaster(cluster *clusterv1.Cluster, currentMachine *clusterv1.Machine, goalMachine *clusterv1.Machine) error {
Expand All @@ -192,11 +194,13 @@ func (azure *AzureClient) updateMaster(cluster *clusterv1.Cluster, currentMachin
}
}

// update kubelet and kubectl client version
// update master and node packages
if currentMachine.Spec.Versions.Kubelet != goalMachine.Spec.Versions.Kubelet {
nodeName := strings.ToLower(resourcemanagement.GetVMName(goalMachine))
// prepare node for maintenance
cmd := fmt.Sprintf("sudo kubectl drain %s --kubeconfig /etc/kubernetes/admin.conf --ignore-daemonsets;"+
"sudo apt-get install kubelet=%s;", nodeName, goalMachine.Spec.Versions.Kubelet+"-00")
// mark the node as schedulable
cmd += fmt.Sprintf("sudo kubectl uncordon %s --kubeconfig /etc/kubernetes/admin.conf;", nodeName)
// update kubectl client version
cmd += fmt.Sprintf("curl -sSL https://dl.k8s.io/release/v%s/bin/linux/amd64/kubectl | "+
Expand Down
15 changes: 1 addition & 14 deletions pkg/cloud/azure/actuators/machine/machineactuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func TestExistsFailureVMNotExists(t *testing.T) {
t.Fatalf("expected machine: %v to not exist", machine.ObjectMeta.Name)
}
}

func TestUpdateVMNotExists(t *testing.T) {
azureServicesClient := mockVMNotExists()
params := MachineActuatorParams{Services: &azureServicesClient}
Expand All @@ -140,20 +141,6 @@ func TestUpdateVMNotExists(t *testing.T) {
}
}

func TestUpdateMachineNotExists(t *testing.T) {
azureServicesClient := mockVMExists()
machineConfig := newMachineProviderConfig()
machine := newMachine(t, machineConfig)
cluster := newCluster(t)

params := MachineActuatorParams{Services: &azureServicesClient}
actuator, err := NewMachineActuator(params)
err = actuator.Update(cluster, machine)
if err == nil {
t.Fatal("expected error calling Update but got none")
}
}

// func TestUpdateNoSpecChange(t *testing.T) {
// azureServicesClient := mockVMExists()
// machineConfig := newMachineProviderConfig()
Expand Down

0 comments on commit a5b920d

Please sign in to comment.