Skip to content

Commit

Permalink
⚠️ Rename VMState to ProvisioningState
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecile Robert-Michon committed Mar 18, 2021
1 parent 5dfdbb5 commit ad702de
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 105 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/v1alpha4/azuremachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type AzureMachineStatus struct {

// VMState is the provisioning state of the Azure virtual machine.
// +optional
VMState *VMState `json:"vmState,omitempty"`
VMState *ProvisioningState `json:"vmState,omitempty"`

// ErrorReason will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a succinct value suitable
Expand Down
38 changes: 21 additions & 17 deletions api/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,28 @@ type PublicIPSpec struct {
}

// VMState describes the state of an Azure virtual machine.
// DEPRECATED: use ProvisioningState
type VMState string

// VMState describes the provisioning state of an Azure resource.
type ProvisioningState string

const (
// VMStateCreating ...
VMStateCreating VMState = "Creating"
// VMStateDeleting ...
VMStateDeleting VMState = "Deleting"
// VMStateFailed ...
VMStateFailed VMState = "Failed"
// VMStateMigrating ...
VMStateMigrating VMState = "Migrating"
// VMStateSucceeded ...
VMStateSucceeded VMState = "Succeeded"
// VMStateUpdating ...
VMStateUpdating VMState = "Updating"
// VMStateDeleted represents a deleted VM
// Creating ...
Creating ProvisioningState = "Creating"
// Deleting ...
Deleting ProvisioningState = "Deleting"
// Failed ...
Failed ProvisioningState = "Failed"
// Migrating ...
Migrating ProvisioningState = "Migrating"
// Succeeded ...
Succeeded ProvisioningState = "Succeeded"
// Updating ...
Updating ProvisioningState = "Updating"
// Deleted represents a deleted VM
// NOTE: This state is specific to capz, and does not have corresponding mapping in Azure API (https://docs.microsoft.com/en-us/azure/virtual-machines/states-lifecycle#provisioning-states)
VMStateDeleted VMState = "Deleted"
Deleted ProvisioningState = "Deleted"
)

// VM describes an Azure virtual machine.
Expand All @@ -235,9 +239,9 @@ type VM struct {
OSDisk OSDisk `json:"osDisk,omitempty"`
StartupScript string `json:"startupScript,omitempty"`
// State - The provisioning state, which only appears in the response.
State VMState `json:"vmState,omitempty"`
Identity VMIdentity `json:"identity,omitempty"`
Tags Tags `json:"tags,omitempty"`
State ProvisioningState `json:"vmState,omitempty"`
Identity VMIdentity `json:"identity,omitempty"`
Tags Tags `json:"tags,omitempty"`

// Addresses contains the addresses associated with the Azure VM.
Addresses []corev1.NodeAddress `json:"addresses,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure/converters/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func SDKToVM(v compute.VirtualMachine) (*infrav1.VM, error) {
vm := &infrav1.VM{
ID: to.String(v.ID),
Name: to.String(v.Name),
State: infrav1.VMState(to.String(v.ProvisioningState)),
State: infrav1.ProvisioningState(to.String(v.ProvisioningState)),
}

if v.VirtualMachineProperties != nil && v.VirtualMachineProperties.HardwareProfile != nil {
Expand Down
4 changes: 2 additions & 2 deletions azure/converters/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.Vi
vmss := &infrav1exp.VMSS{
ID: to.String(sdkvmss.ID),
Name: to.String(sdkvmss.Name),
State: infrav1.VMState(to.String(sdkvmss.ProvisioningState)),
State: infrav1.ProvisioningState(to.String(sdkvmss.ProvisioningState)),
}

if sdkvmss.Sku != nil {
Expand All @@ -52,7 +52,7 @@ func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.Vi
ID: to.String(vm.ID),
InstanceID: to.String(vm.InstanceID),
Name: to.String(vm.OsProfile.ComputerName),
State: infrav1.VMState(to.String(vm.ProvisioningState)),
State: infrav1.ProvisioningState(to.String(vm.ProvisioningState)),
}

if vm.LatestModelApplied != nil {
Expand Down
22 changes: 11 additions & 11 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ func (m *MachineScope) SetProviderID(v string) {
}

// VMState returns the AzureMachine VM state.
func (m *MachineScope) VMState() infrav1.VMState {
func (m *MachineScope) VMState() infrav1.ProvisioningState {
if m.AzureMachine.Status.VMState != nil {
return *m.AzureMachine.Status.VMState
}
return ""
}

// SetVMState sets the AzureMachine VM state.
func (m *MachineScope) SetVMState(v infrav1.VMState) {
func (m *MachineScope) SetVMState(v infrav1.ProvisioningState) {
m.AzureMachine.Status.VMState = &v
}

Expand All @@ -387,16 +387,16 @@ func (m *MachineScope) SetFailureReason(v capierrors.MachineStatusError) {
}

func (m *MachineScope) SetBootstrapConditions(provisioningState string, extensionName string) error {
switch infrav1.VMState(provisioningState) {
case infrav1.VMStateSucceeded:
switch infrav1.ProvisioningState(provisioningState) {
case infrav1.Succeeded:
m.V(4).Info("extension provisioning state is succeeded", "vm extension", extensionName, "virtual machine", m.Name())
conditions.MarkTrue(m.AzureMachine, infrav1.BootstrapSucceededCondition)
return nil
case infrav1.VMStateCreating:
case infrav1.Creating:
m.V(4).Info("extension provisioning state is creating", "vm extension", extensionName, "virtual machine", m.Name())
conditions.MarkFalse(m.AzureMachine, infrav1.BootstrapSucceededCondition, infrav1.BootstrapInProgressReason, clusterv1.ConditionSeverityInfo, "")
return azure.WithTransientError(errors.New("extension still provisioning"), 30*time.Second)
case infrav1.VMStateFailed:
case infrav1.Failed:
m.V(4).Info("extension provisioning state is failed", "vm extension", extensionName, "virtual machine", m.Name())
conditions.MarkFalse(m.AzureMachine, infrav1.BootstrapSucceededCondition, infrav1.BootstrapFailedReason, clusterv1.ConditionSeverityError, "")
return azure.WithTerminalError(errors.New("extension state failed"))
Expand All @@ -407,19 +407,19 @@ func (m *MachineScope) SetBootstrapConditions(provisioningState string, extensio

func (m *MachineScope) UpdateStatus() {
switch m.VMState() {
case infrav1.VMStateSucceeded:
case infrav1.Succeeded:
m.V(2).Info("VM is running", "id", m.GetVMID())
conditions.MarkTrue(m.AzureMachine, infrav1.VMRunningCondition)
case infrav1.VMStateCreating:
case infrav1.Creating:
m.V(2).Info("VM is creating", "id", m.GetVMID())
conditions.MarkFalse(m.AzureMachine, infrav1.VMRunningCondition, infrav1.VMCreatingReason, clusterv1.ConditionSeverityInfo, "")
case infrav1.VMStateUpdating:
case infrav1.Updating:
m.V(2).Info("VM is updating", "id", m.GetVMID())
conditions.MarkFalse(m.AzureMachine, infrav1.VMRunningCondition, infrav1.VMUpdatingReason, clusterv1.ConditionSeverityInfo, "")
case infrav1.VMStateDeleting:
case infrav1.Deleting:
m.Info("Unexpected VM deletion", "id", m.GetVMID())
conditions.MarkFalse(m.AzureMachine, infrav1.VMRunningCondition, infrav1.VMDeletingReason, clusterv1.ConditionSeverityWarning, "")
case infrav1.VMStateFailed:
case infrav1.Failed:
m.Error(errors.New("Failed to create or update VM"), "VM is in failed state", "id", m.GetVMID())
m.SetFailureReason(capierrors.UpdateMachineError)
m.SetFailureMessage(errors.Errorf("Azure VM state is %s", m.VMState()))
Expand Down
34 changes: 22 additions & 12 deletions azure/scope/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/util/conditions"
"time"

"github.com/Azure/go-autorest/autorest/to"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (m *MachinePoolScope) SetProviderID(v string) {
}

// ProvisioningState returns the AzureMachinePool provisioning state.
func (m *MachinePoolScope) ProvisioningState() infrav1.VMState {
func (m *MachinePoolScope) ProvisioningState() infrav1.ProvisioningState {
if m.AzureMachinePool.Status.ProvisioningState != nil {
return *m.AzureMachinePool.Status.ProvisioningState
}
Expand Down Expand Up @@ -227,14 +228,14 @@ func (m *MachinePoolScope) GetLongRunningOperationState() *infrav1.Future {
}

// SetProvisioningState sets the AzureMachinePool provisioning state.
func (m *MachinePoolScope) SetProvisioningState(v infrav1.VMState) {
func (m *MachinePoolScope) SetProvisioningState(v infrav1.ProvisioningState) {
switch {
case v == infrav1.VMStateSucceeded && *m.MachinePool.Spec.Replicas == m.AzureMachinePool.Status.Replicas:
case v == infrav1.Succeeded && *m.MachinePool.Spec.Replicas == m.AzureMachinePool.Status.Replicas:
// vmss is provisioned with enough ready replicas
m.AzureMachinePool.Status.ProvisioningState = &v
case v == infrav1.VMStateSucceeded && *m.MachinePool.Spec.Replicas != m.AzureMachinePool.Status.Replicas:
case v == infrav1.Succeeded && *m.MachinePool.Spec.Replicas != m.AzureMachinePool.Status.Replicas:
// not enough ready or too many ready replicas we must still be scaling up or down
updatingState := infrav1.VMStateUpdating
updatingState := infrav1.Updating
m.AzureMachinePool.Status.ProvisioningState = &updatingState
default:
m.AzureMachinePool.Status.ProvisioningState = &v
Expand All @@ -261,15 +262,24 @@ func (m *MachinePoolScope) SetFailureReason(v capierrors.MachineStatusError) {
m.AzureMachinePool.Status.FailureReason = &v
}

// SetCondition sets a condition on the AzureMachinePool.
func (m *MachinePoolScope) SetCondition(condition clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, value bool) {
if value {
conditions.MarkTrue(m.AzureMachinePool, condition)
} else {
conditions.MarkFalse(m.AzureMachinePool, condition, reason, severity, "")
func (m *MachinePoolScope) SetBootstrapConditions(provisioningState string, extensionName string) error {
switch infrav1.ProvisioningState(provisioningState) {
case infrav1.Succeeded:
m.V(4).Info("extension provisioning state is succeeded", "vm extension", extensionName, "scale set", m.Name())
conditions.MarkTrue(m.AzureMachinePool, infrav1.BootstrapSucceededCondition)
return nil
case infrav1.Creating:
m.V(4).Info("extension provisioning state is creating", "vm extension", extensionName, "scale set", m.Name())
conditions.MarkFalse(m.AzureMachinePool, infrav1.BootstrapSucceededCondition, infrav1.BootstrapInProgressReason, clusterv1.ConditionSeverityInfo, "")
return azure.WithTransientError(errors.New("extension still provisioning"), 30*time.Second)
case infrav1.Failed:
m.V(4).Info("extension provisioning state is failed", "vm extension", extensionName, "scale set", m.Name())
conditions.MarkFalse(m.AzureMachinePool, infrav1.BootstrapSucceededCondition, infrav1.BootstrapFailedReason, clusterv1.ConditionSeverityError, "")
return azure.WithTerminalError(errors.New("extension state failed"))
default:
return nil
}
}

// AdditionalTags merges AdditionalTags from the scope's AzureCluster and AzureMachinePool. If the same key is present in both,
// the value from AzureMachinePool takes precedence.
func (m *MachinePoolScope) AdditionalTags() infrav1.Tags {
Expand Down
2 changes: 1 addition & 1 deletion azure/services/scalesets/mock_scalesets/scalesets_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions azure/services/scalesets/scalesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type ScaleSetScope interface {
UpdateInstanceStatuses(context.Context, []infrav1exp.VMSSVM) error
NeedsK8sVersionUpdate() bool
SaveK8sVersion()
SetProvisioningState(infrav1.VMState)
SetProvisioningState(infrav1.ProvisioningState)
SetLongRunningOperationState(*infrav1.Future)
GetLongRunningOperationState() *infrav1.Future
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *Service) createVMSS(ctx context.Context) (*infrav1.Future, error) {

vmss := result.VMSSWithoutHash
vmss.Tags = converters.TagsToMap(result.Tags.AddSpecVersionHashTag(result.Hash))
s.Scope.SetProvisioningState(infrav1.VMStateCreating)
s.Scope.SetProvisioningState(infrav1.Creating)
future, err := s.Client.CreateOrUpdateAsync(ctx, s.Scope.ResourceGroup(), spec.Name, vmss)
if err != nil {
return future, errors.Wrap(err, "cannot create VMSS")
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *Service) patchVMSSIfNeeded(ctx context.Context, infraVMSS *infrav1exp.V
return future, errors.Wrap(err, "failed updating VMSS")
}

s.Scope.SetProvisioningState(infrav1.VMStateUpdating)
s.Scope.SetProvisioningState(infrav1.Updating)
s.Scope.SetLongRunningOperationState(future)
s.Scope.V(2).Info("successfully started to update vmss", "scale set", spec.Name)
return future, err
Expand Down
12 changes: 6 additions & 6 deletions azure/services/scalesets/scalesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestReconcileVMSS(t *testing.T) {
createdVMSS = setupDefaultVMSSInProgressOperationDoneExpectations(g, s, m, createdVMSS, instances)
s.SetProviderID(fmt.Sprintf("azure://%s", *createdVMSS.ID))
s.SetLongRunningOperationState(nil)
s.SetProvisioningState(infrav1.VMStateSucceeded)
s.SetProvisioningState(infrav1.Succeeded)
s.NeedsK8sVersionUpdate().Return(false)
infraVMSS := converters.SDKToVMSS(createdVMSS, instances)
s.UpdateInstanceStatuses(gomockinternal.AContext(), infraVMSS.Instances).Return(nil)
Expand All @@ -287,7 +287,7 @@ func TestReconcileVMSS(t *testing.T) {
instances := newDefaultInstances()
vmss = setupDefaultVMSSInProgressOperationDoneExpectations(g, s, m, vmss, instances)
s.SetProviderID(fmt.Sprintf("azure://%s", *vmss.ID))
s.SetProvisioningState(infrav1.VMStateUpdating)
s.SetProvisioningState(infrav1.Updating)

// create a VMSS patch with an updated hash to match the spec
updatedVMSS := newDefaultVMSS()
Expand Down Expand Up @@ -315,7 +315,7 @@ func TestReconcileVMSS(t *testing.T) {
createdVMSS = setupDefaultVMSSInProgressOperationDoneExpectations(g, s, m, createdVMSS, instances)
s.SetProviderID(fmt.Sprintf("azure://%s", *createdVMSS.ID))
s.SetLongRunningOperationState(nil)
s.SetProvisioningState(infrav1.VMStateSucceeded)
s.SetProvisioningState(infrav1.Succeeded)
s.NeedsK8sVersionUpdate().Return(false)
infraVMSS := converters.SDKToVMSS(createdVMSS, instances)
s.UpdateInstanceStatuses(gomockinternal.AContext(), infraVMSS.Instances).Return(nil)
Expand Down Expand Up @@ -1041,7 +1041,7 @@ func setHashOnVMSSUpdate(g *WithT, vmss compute.VirtualMachineScaleSet, update c
func setupDefaultVMSSInProgressOperationDoneExpectations(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder, createdVMSS compute.VirtualMachineScaleSet, instances []compute.VirtualMachineScaleSetVM) compute.VirtualMachineScaleSet {
setHashOnVMSS(g, createdVMSS)
createdVMSS.ID = to.StringPtr("vmss-id")
createdVMSS.ProvisioningState = to.StringPtr(string(infrav1.VMStateSucceeded))
createdVMSS.ProvisioningState = to.StringPtr(string(infrav1.Succeeded))
setupDefaultVMSSExpectations(s)
future := &infrav1.Future{
Type: PutFuture,
Expand All @@ -1060,7 +1060,7 @@ func setupDefaultVMSSStartCreatingExpectations(s *mock_scalesets.MockScaleSetSco
s.GetLongRunningOperationState().Return(nil)
m.Get(gomockinternal.AContext(), defaultResourceGroup, defaultVMSSName).
Return(compute.VirtualMachineScaleSet{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found"))
s.SetProvisioningState(infrav1.VMStateCreating)
s.SetProvisioningState(infrav1.Creating)
}

func setupCreatingSucceededExpectations(s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder, future *infrav1.Future) {
Expand Down Expand Up @@ -1097,6 +1097,6 @@ func setupDefaultVMSSExpectations(s *mock_scalesets.MockScaleSetScopeMockRecorde
func setupDefaultVMSSUpdateExpectations(s *mock_scalesets.MockScaleSetScopeMockRecorder) {
setupDefaultVMSSExpectations(s)
s.SetProviderID("azure://vmss-id")
s.SetProvisioningState(infrav1.VMStateUpdating)
s.SetProvisioningState(infrav1.Updating)
s.GetLongRunningOperationState().Return(nil)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions azure/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type VMScope interface {
AvailabilitySet() (string, bool)
SetProviderID(string)
SetAddresses([]corev1.NodeAddress)
SetVMState(infrav1.VMState)
SetVMState(infrav1.ProvisioningState)
UpdateStatus()
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
switch {
// VM got deleted outside of capz
case err != nil && azure.ResourceNotFound(err) && s.Scope.ProviderID() != "":
s.Scope.SetVMState(infrav1.VMStateDeleted)
s.Scope.SetVMState(infrav1.Deleted)
return azure.VMDeletedError{ProviderID: s.Scope.ProviderID()}
case err != nil && !azure.ResourceNotFound(err):
return errors.Wrapf(err, "failed to get VM %s", vmSpec.Name)
Expand Down
2 changes: 1 addition & 1 deletion azure/services/virtualmachines/virtualmachines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ func TestReconcileVM(t *testing.T) {
s.ResourceGroup().AnyTimes().Return("my-rg")
s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New())
s.ProviderID().Times(2).Return("ExistingVM-ProviderID")
s.SetVMState(infrav1.VMStateDeleted)
s.SetVMState(infrav1.Deleted)
m.Get(gomockinternal.AContext(), "my-rg", "my-vm").
Return(compute.VirtualMachine{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found"))
},
Expand Down
Loading

0 comments on commit ad702de

Please sign in to comment.