Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def capz():
local_resource(
"manager",
cmd = 'mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \'-extldflags "-static"\' -o .tiltbuild/manager',
deps = ["api", "cloud", "config", "controllers", "exp", "feature", "pkg", "go.mod", "go.sum", "main.go"]
deps = ["api", "azure", "config", "controllers", "exp", "feature", "pkg", "go.mod", "go.sum", "main.go"]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably pull this out into another PR, but what's 1 line on 4k+ 😞

)

k8s_resource('capz-controller-manager:deployment:capz-system', objects=[
Expand Down
22 changes: 22 additions & 0 deletions api/v1alpha3/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,25 @@ const (
// WaitingForBootstrapDataReason used when machine is waiting for bootstrap data to be ready before proceeding.
WaitingForBootstrapDataReason = "WaitingForBootstrapData"
)

// AzureMachinePool Conditions and Reasons
const (
// PoolRunningCondition reports on current status of the Azure VM.
PoolRunningCondition clusterv1.ConditionType = "PoolRunning"
// PoolCreatingReason describes the machine pool creating
PoolCreatingReason = "PoolCreating"
// PoolCreatingReason describes the machine pool deleting
PoolDeletingReason = "PoolDeleting"

// PoolDesiredReplicasCondition reports on the scaling state of the machine pool
PoolDesiredReplicasCondition clusterv1.ConditionType = "PoolDesiredReplicas"
// PoolScaleUpReason describes the machine pool scaling up
PoolScaleUpReason = "PoolScalingUp"
// PoolScaleUpReason describes the machine pool scaling down
PoolScaleDownReason = "PoolScalingDown"

// PoolModelUpdatingCondition reports on the model state of the pool
PoolModelUpdatedCondition clusterv1.ConditionType = "PoolModelUpdated"
// PoolModelOutOfDateReason describes the machine pool model being out of date
PoolModelOutOfDateReason = "PoolModelOutOfDate"
)
17 changes: 0 additions & 17 deletions api/v1alpha3/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ func (t Tags) Equals(other Tags) bool {
return reflect.DeepEqual(t, other)
}

// HasMatchingSpecVersionHash returns true if the resource has been tagged with a matching resource spec hash value.
func (t Tags) HasMatchingSpecVersionHash(hash string) bool {
value, ok := t[SpecVersionHashTagKey()]
return ok && value == hash
}

// HasOwned returns true if the tags contains a tag that marks the resource as owned by the cluster from the perspective of this management tooling.
func (t Tags) HasOwned(cluster string) bool {
value, ok := t[ClusterTagKey(cluster)]
Expand Down Expand Up @@ -74,12 +68,6 @@ func (t Tags) Merge(other Tags) {
}
}

// AddSpecVersionHashTag adds a spec version hash to the Azure resource tags to determine if state has changed quickly
func (t Tags) AddSpecVersionHashTag(hash string) Tags {
t[SpecVersionHashTagKey()] = hash
return t
}

// ResourceLifecycle configures the lifecycle of a resource
type ResourceLifecycle string

Expand Down Expand Up @@ -138,11 +126,6 @@ const (
VMTagsLastAppliedAnnotation = "sigs.k8s.io/cluster-api-provider-azure-last-applied-tags-vm"
)

// SpecVersionHashTagKey is the key for the spec version hash used to enable quick spec difference comparison
func SpecVersionHashTagKey() string {
return fmt.Sprintf("%s%s", NameAzureProviderPrefix, "spec-version-hash")
}

// ClusterTagKey generates the key for resources associated with a cluster.
func ClusterTagKey(name string) string {
return fmt.Sprintf("%s%s", NameAzureProviderOwned, name)
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,8 @@ type AddressRecord struct {
Hostname string
IP string
}

// IsTerminalVMState returns true if the VMState is a terminal state for an Azure resource
func IsTerminalVMState(state VMState) bool {
return state == VMStateFailed || state == VMStateSucceeded
}
65 changes: 50 additions & 15 deletions azure/converters/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,58 @@ func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.Vi
if len(sdkinstances) > 0 {
vmss.Instances = make([]infrav1exp.VMSSVM, len(sdkinstances))
for i, vm := range sdkinstances {
instance := infrav1exp.VMSSVM{
ID: to.String(vm.ID),
InstanceID: to.String(vm.InstanceID),
Name: to.String(vm.OsProfile.ComputerName),
State: infrav1.VMState(to.String(vm.ProvisioningState)),
}

if vm.LatestModelApplied != nil {
instance.LatestModelApplied = *vm.LatestModelApplied
}

if vm.Zones != nil && len(*vm.Zones) > 0 {
instance.AvailabilityZone = to.StringSlice(vm.Zones)[0]
}
vmss.Instances[i] = instance
vmss.Instances[i] = *SDKToVMSSVM(vm)
}
}

if sdkvmss.VirtualMachineProfile != nil &&
sdkvmss.VirtualMachineProfile.StorageProfile != nil &&
sdkvmss.VirtualMachineProfile.StorageProfile.ImageReference != nil {

imageRef := sdkvmss.VirtualMachineProfile.StorageProfile.ImageReference
vmss.Image = infrav1.Image{
ID: imageRef.ID,
Marketplace: &infrav1.AzureMarketplaceImage{
Publisher: to.String(imageRef.Publisher),
Offer: to.String(imageRef.Offer),
SKU: to.String(imageRef.Sku),
Version: to.String(imageRef.Version),
ThirdPartyImage: false,
},
}
}

return vmss
}

// SDKToVMSSVM converts an Azure SDK VirtualMachineScaleSetVM into an infrav1exp.VMSSVM
func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *infrav1exp.VMSSVM {
instance := infrav1exp.VMSSVM{
ID: to.String(sdkInstance.ID),
InstanceID: to.String(sdkInstance.InstanceID),
LatestModelApplied: true,
}

if sdkInstance.VirtualMachineScaleSetVMProperties == nil {
return &instance
}

instance.State = infrav1.VMStateCreating
if sdkInstance.ProvisioningState != nil {
instance.State = infrav1.VMState(to.String(sdkInstance.ProvisioningState))
}

if sdkInstance.OsProfile != nil && sdkInstance.OsProfile.ComputerName != nil {
instance.Name = *sdkInstance.OsProfile.ComputerName
}

if sdkInstance.LatestModelApplied != nil {
instance.LatestModelApplied = *sdkInstance.LatestModelApplied
}

if sdkInstance.Zones != nil && len(*sdkInstance.Zones) > 0 {
instance.AvailabilityZone = to.StringSlice(sdkInstance.Zones)[0]
}

return &instance
}
11 changes: 6 additions & 5 deletions azure/converters/vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ func Test_SDKToVMSS(t *testing.T) {

for i := 0; i < 2; i++ {
expected.Instances[i] = infrav1exp.VMSSVM{
ID: fmt.Sprintf("vm/%d", i),
InstanceID: fmt.Sprintf("%d", i),
Name: fmt.Sprintf("instance-00000%d", i),
AvailabilityZone: fmt.Sprintf("zone%d", i),
State: "Succeeded",
ID: fmt.Sprintf("vm/%d", i),
InstanceID: fmt.Sprintf("%d", i),
Name: fmt.Sprintf("instance-00000%d", i),
AvailabilityZone: fmt.Sprintf("zone%d", i),
State: "Succeeded",
LatestModelApplied: true,
}
}
g.Expect(actual).To(gomega.Equal(&expected))
Expand Down
4 changes: 2 additions & 2 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ func (m *MachineScope) GetVMImage() (*infrav1.Image, error) {
}

if m.AzureMachine.Spec.OSDisk.OSType == azure.WindowsOS {
m.Info("No image specified for machine, using default Windows Image", "machine", m.AzureMachine.GetName())
m.V(4).Info("No image specified for machine, using default Windows Image", "machine", m.AzureMachine.GetName())
return azure.GetDefaultWindowsImage(to.String(m.Machine.Spec.Version))
}

m.Info("No image specified for machine, using default Linux Image", "machine", m.AzureMachine.GetName())
m.V(4).Info("No image specified for machine, using default Linux Image", "machine", m.AzureMachine.GetName())
return azure.GetDefaultUbuntuImage(to.String(m.Machine.Spec.Version))
}
Loading