Skip to content

Commit

Permalink
Merge branch 'master' into docofix
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns authored Jul 16, 2020
2 parents 60fed1c + 90ce90f commit acec0d5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: azure.microsoft.com/v1alpha1
kind: AzurePublicIPAddress
metadata:
name: nic-pip-sample-01
spec:
location: SouthCentralUS
resourceGroup: resourcegroup-azure-operators
publicIPAllocationMethod: "Static"
idleTimeoutInMinutes: 10
publicIPAddressVersion: "IPv4"
skuName: "Basic"
---
apiVersion: azure.microsoft.com/v1alpha1
kind: VirtualNetwork
metadata:
name: vnet-sample-01
spec:
location: SouthCentralUS
resourceGroup: resourcegroup-azure-operators
addressSpace: "10.0.0.0/8"
subnets:
- subnetName: test1
subnetAddressPrefix: "10.1.0.0/16"
- subnetName: test2
subnetAddressPrefix: "10.2.0.0/16"
---
apiVersion: azure.microsoft.com/v1alpha1
kind: AzureNetworkInterface
metadata:
name: nic-sample-01
spec:
location: SouthCentralUS
resourceGroup: resourcegroup-azure-operators
vnetName: vnet-sample-01
subnetName: test1
publicIPAddressName: nic-pip-sample-01
---
apiVersion: azure.microsoft.com/v1alpha1
kind: AzureVirtualMachine
metadata:
name: hpfvm1
spec:
location: SouthCentralUS
resourceGroup: resourcegroup-azure-operators
vmSize: Standard_DS1_v2
osType: Linux
adminUserName: azureuser
# SSH public key to be used with VM (eg cat ~/.ssh/id_rsa.pub)
sshPublicKeyData: {ssh key}
networkInterfaceName: nic-sample-01
platformImageURN: Canonical:UbuntuServer:16.04-LTS:latest
42 changes: 27 additions & 15 deletions pkg/resourcemanager/vm/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (g *AzureVirtualMachineClient) Ensure(ctx context.Context, obj runtime.Obje
nicName := instance.Spec.NetworkInterfaceName
imageURN := instance.Spec.PlatformImageURN

const SucceededProvisioningState = "Succeeded"

// Check to see if secret exists and if yes retrieve the admin login and password
secret, err := g.GetOrPrepareSecret(ctx, instance)
if err != nil {
Expand All @@ -52,11 +54,22 @@ func (g *AzureVirtualMachineClient) Ensure(ctx context.Context, obj runtime.Obje
// to overcome the issue with the lack of idempotence of the Create call
item, err := g.GetVirtualMachine(ctx, resourceGroup, resourceName)
if err == nil {
instance.Status.Provisioned = true
instance.Status.Provisioning = false
instance.Status.Message = resourcemanager.SuccessMsg
instance.Status.ResourceId = *item.ID
return true, nil

if *item.ProvisioningState == SucceededProvisioningState {

instance.Status.Provisioned = true
instance.Status.Provisioning = false
instance.Status.Message = resourcemanager.SuccessMsg
instance.Status.ResourceId = *item.ID
instance.Status.State = *item.ProvisioningState
return true, nil
}

instance.Status.Provisioned = false
instance.Status.State = *item.ProvisioningState
instance.Status.Message = "Requested resource has been requested but is not ready yet"
return false, nil

}
future, err := g.CreateVirtualMachine(
ctx,
Expand Down Expand Up @@ -91,10 +104,17 @@ func (g *AzureVirtualMachineClient) Ensure(ctx context.Context, obj runtime.Obje
switch azerr.Type {
case errhelp.AsyncOpIncompleteError:
instance.Status.Provisioning = true

}
// reconciliation is not done but error is acceptable
return false, nil
}
//change to spec is required
if future.Response().StatusCode == 400 {
instance.Status.FailedProvisioning = true
return false, nil
}

// reconciliation not done and we don't know what happened
return false, err
}
Expand Down Expand Up @@ -123,19 +143,11 @@ func (g *AzureVirtualMachineClient) Ensure(ctx context.Context, obj runtime.Obje
// reconciliation is not done but error is acceptable
return false, nil
}

// reconciliation not done and we don't know what happened
return false, err
}

if instance.Status.Provisioning {
instance.Status.Provisioned = true
instance.Status.Provisioning = false
instance.Status.Message = resourcemanager.SuccessMsg
} else {
instance.Status.Provisioned = false
instance.Status.Provisioning = true
}
return true, nil
return false, nil
}

func (g *AzureVirtualMachineClient) Delete(ctx context.Context, obj runtime.Object, opts ...resourcemanager.ConfigOption) (bool, error) {
Expand Down

0 comments on commit acec0d5

Please sign in to comment.