diff --git a/azure/scope/machine.go b/azure/scope/machine.go index 46830c0d3c1..49c831063dd 100644 --- a/azure/scope/machine.go +++ b/azure/scope/machine.go @@ -72,6 +72,9 @@ func NewMachineScope(params MachineScopeParams) (*MachineScope, error) { if params.AzureMachine == nil { return nil, errors.New("azure machine is required when creating a MachineScope") } + if params.Cache == nil { + params.Cache = &MachineCache{} + } helper, err := patch.NewHelper(params.AzureMachine, params.Client) if err != nil { @@ -101,59 +104,21 @@ type MachineScope struct { // MachineCache stores common machine information so we don't have to hit the API multiple times within the same reconcile loop. type MachineCache struct { - BootstrapData string + BootstrapData *string VMImage *infrav1.Image - VMSKU resourceskus.SKU - availabilitySetSKU resourceskus.SKU -} - -// InitMachineCache sets cached information about the machine to be used in the scope. -func (m *MachineScope) InitMachineCache(ctx context.Context) error { - ctx, _, done := tele.StartSpanWithLogger(ctx, "azure.MachineScope.InitMachineCache") - defer done() - - if m.cache == nil { - var err error - m.cache = &MachineCache{} - - m.cache.BootstrapData, err = m.GetBootstrapData(ctx) - if err != nil { - return err - } - - m.cache.VMImage, err = m.GetVMImage(ctx) - if err != nil { - return err - } - - skuCache, err := resourceskus.GetCache(m, m.Location()) - if err != nil { - return err - } - - m.cache.VMSKU, err = skuCache.Get(ctx, m.AzureMachine.Spec.VMSize, resourceskus.VirtualMachines) - if err != nil { - return errors.Wrapf(err, "failed to get VM SKU %s in compute api", m.AzureMachine.Spec.VMSize) - } - - m.cache.availabilitySetSKU, err = skuCache.Get(ctx, string(compute.AvailabilitySetSkuTypesAligned), resourceskus.AvailabilitySets) - if err != nil { - return errors.Wrapf(err, "failed to get availability set SKU %s in compute api", string(compute.AvailabilitySetSkuTypesAligned)) - } - } - - return nil + VMSKU *resourceskus.SKU + availabilitySetSKU *resourceskus.SKU } // VMSpec returns the VM spec. -func (m *MachineScope) VMSpec() azure.ResourceSpecGetter { +func (m *MachineScope) VMSpec(ctx context.Context) azure.ResourceSpecGetter { spec := &virtualmachines.VMSpec{ Name: m.Name(), Location: m.Location(), ResourceGroup: m.ResourceGroup(), ClusterName: m.ClusterName(), Role: m.Role(), - NICIDs: m.NICIDs(), + NICIDs: m.NICIDs(ctx), SSHKeyData: m.AzureMachine.Spec.SSHPublicKey, Size: m.AzureMachine.Spec.VMSize, OSDisk: m.AzureMachine.Spec.OSDisk, @@ -168,10 +133,14 @@ func (m *MachineScope) VMSpec() azure.ResourceSpecGetter { AdditionalCapabilities: m.AzureMachine.Spec.AdditionalCapabilities, ProviderID: m.ProviderID(), } - if m.cache != nil { - spec.SKU = m.cache.VMSKU - spec.Image = m.cache.VMImage - spec.BootstrapData = m.cache.BootstrapData + if bootstrapData, err := m.GetBootstrapData(ctx); err == nil { + spec.BootstrapData = bootstrapData + } + if vmSKU, err := m.GetVMSKU(ctx); err == nil { + spec.SKU = *vmSKU + } + if image, err := m.GetVMImage(ctx); err == nil { + spec.Image = image } return spec } @@ -227,7 +196,7 @@ func (m *MachineScope) InboundNatSpecs() []azure.ResourceSpecGetter { } // NICSpecs returns the network interface specs. -func (m *MachineScope) NICSpecs() []azure.ResourceSpecGetter { +func (m *MachineScope) NICSpecs(ctx context.Context) []azure.ResourceSpecGetter { spec := &networkinterfaces.NICSpec{ Name: azure.GenerateNICName(m.Name()), ResourceGroup: m.ResourceGroup(), @@ -267,16 +236,16 @@ func (m *MachineScope) NICSpecs() []azure.ResourceSpecGetter { spec.PublicIPName = azure.GenerateNodePublicIPName(m.Name()) } - if m.cache != nil { - spec.SKU = &m.cache.VMSKU + if vmSKU, err := m.GetVMSKU(ctx); err == nil { + spec.SKU = vmSKU } return []azure.ResourceSpecGetter{spec} } // NICIDs returns the NIC resource IDs. -func (m *MachineScope) NICIDs() []string { - nicspecs := m.NICSpecs() +func (m *MachineScope) NICIDs(ctx context.Context) []string { + nicspecs := m.NICSpecs(ctx) nicIDs := make([]string, len(nicspecs)) for i, nic := range nicspecs { nicIDs[i] = azure.NetworkInterfaceID(m.SubscriptionID(), nic.ResourceGroupName(), nic.ResourceName()) @@ -359,9 +328,9 @@ func (m *MachineScope) Subnet() infrav1.SubnetSpec { // AvailabilityZone returns the AzureMachine Availability Zone. // Priority for selecting the AZ is -// 1) Machine.Spec.FailureDomain -// 2) AzureMachine.Spec.FailureDomain (This is to support deprecated AZ) -// 3) No AZ +// 1. Machine.Spec.FailureDomain +// 2. AzureMachine.Spec.FailureDomain (This is to support deprecated AZ) +// 3. No AZ func (m *MachineScope) AvailabilityZone() string { if m.Machine.Spec.FailureDomain != nil { return *m.Machine.Spec.FailureDomain @@ -423,7 +392,7 @@ func (m *MachineScope) ProviderID() string { } // AvailabilitySetSpec returns the availability set spec for this machine if available. -func (m *MachineScope) AvailabilitySetSpec() azure.ResourceSpecGetter { +func (m *MachineScope) AvailabilitySetSpec(ctx context.Context) azure.ResourceSpecGetter { availabilitySetName, ok := m.AvailabilitySet() if !ok { return nil @@ -434,14 +403,12 @@ func (m *MachineScope) AvailabilitySetSpec() azure.ResourceSpecGetter { ResourceGroup: m.ResourceGroup(), ClusterName: m.ClusterName(), Location: m.Location(), - SKU: nil, AdditionalTags: m.AdditionalTags(), } - if m.cache != nil { - spec.SKU = &m.cache.availabilitySetSKU + if avSKU, err := m.GetAvailabilitySetSKU(ctx); err == nil { + spec.SKU = avSKU } - return spec } @@ -617,6 +584,10 @@ func (m *MachineScope) GetBootstrapData(ctx context.Context) (string, error) { ctx, _, done := tele.StartSpanWithLogger(ctx, "scope.MachineScope.GetBootstrapData") defer done() + if m.cache.BootstrapData != nil { + return to.String(m.cache.BootstrapData), nil + } + if m.Machine.Spec.Bootstrap.DataSecretName == nil { return "", errors.New("error retrieving bootstrap data: linked Machine's bootstrap.dataSecretName is nil") } @@ -630,7 +601,9 @@ func (m *MachineScope) GetBootstrapData(ctx context.Context) (string, error) { if !ok { return "", errors.New("error retrieving bootstrap data: secret value key is missing") } - return base64.StdEncoding.EncodeToString(value), nil + bootstrapData := base64.StdEncoding.EncodeToString(value) + m.cache.BootstrapData = to.StringPtr(bootstrapData) + return bootstrapData, nil } // GetVMImage returns the image from the machine configuration, or a default one. @@ -643,17 +616,70 @@ func (m *MachineScope) GetVMImage(ctx context.Context) (*infrav1.Image, error) { return m.AzureMachine.Spec.Image, nil } + if m.cache.VMImage != nil { + return m.cache.VMImage, nil + } + svc := virtualmachineimages.New(m) + var ( + err error + defaultImage *infrav1.Image + ) if m.AzureMachine.Spec.OSDisk.OSType == azure.WindowsOS { runtime := m.AzureMachine.Annotations["runtime"] windowsServerVersion := m.AzureMachine.Annotations["windowsServerVersion"] log.Info("No image specified for machine, using default Windows Image", "machine", m.AzureMachine.GetName(), "runtime", runtime, "windowsServerVersion", windowsServerVersion) - return svc.GetDefaultWindowsImage(ctx, m.Location(), to.String(m.Machine.Spec.Version), runtime, windowsServerVersion) + defaultImage, err = svc.GetDefaultWindowsImage(ctx, m.Location(), to.String(m.Machine.Spec.Version), runtime, windowsServerVersion) + } else { + log.Info("No image specified for machine, using default Linux Image", "machine", m.AzureMachine.GetName()) + defaultImage, err = svc.GetDefaultUbuntuImage(ctx, m.Location(), to.String(m.Machine.Spec.Version)) + } + + if err != nil { + return defaultImage, err + } + + m.cache.VMImage = defaultImage + return defaultImage, nil +} + +// GetVMSKU returns the VM image SKU. +func (m *MachineScope) GetVMSKU(ctx context.Context) (*resourceskus.SKU, error) { + if m.cache.VMSKU != nil { + return m.cache.VMSKU, nil + } + + skuCache, err := resourceskus.GetCache(m, m.Location()) + if err != nil { + return nil, err } - log.Info("No image specified for machine, using default Linux Image", "machine", m.AzureMachine.GetName()) - return svc.GetDefaultUbuntuImage(ctx, m.Location(), to.String(m.Machine.Spec.Version)) + sku, err := skuCache.Get(ctx, m.AzureMachine.Spec.VMSize, resourceskus.VirtualMachines) + if err != nil { + return nil, errors.Wrapf(err, "failed to get VM SKU %s in compute api", m.AzureMachine.Spec.VMSize) + } + m.cache.VMSKU = &sku + return &sku, nil +} + +// GetAvailabilitySetSKU returns the VM image SKU. +func (m *MachineScope) GetAvailabilitySetSKU(ctx context.Context) (*resourceskus.SKU, error) { + if m.cache.availabilitySetSKU != nil { + return m.cache.availabilitySetSKU, nil + } + + skuCache, err := resourceskus.GetCache(m, m.Location()) + if err != nil { + return nil, err + } + + sku, err := skuCache.Get(ctx, string(compute.AvailabilitySetSkuTypesAligned), resourceskus.AvailabilitySets) + if err != nil { + return nil, errors.Wrapf(err, "failed to get availability set SKU %s in compute api", string(compute.AvailabilitySetSkuTypesAligned)) + } + m.cache.availabilitySetSKU = &sku + return &sku, nil } // SetSubnetName defaults the AzureMachine subnet name to the name of one the subnets with the machine role when there is only one of them. diff --git a/azure/scope/machine_test.go b/azure/scope/machine_test.go index 3ce296756ed..5c01ce39957 100644 --- a/azure/scope/machine_test.go +++ b/azure/scope/machine_test.go @@ -1270,6 +1270,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: &infrav1.Image{ ID: pointer.StringPtr("1"), @@ -1298,6 +1299,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.20.1", "dockershim", "") @@ -1327,6 +1329,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.22.1", "containerd", "") @@ -1359,6 +1362,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.22.1", "dockershim", "") @@ -1391,6 +1395,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.21.1", "dockershim", "") @@ -1423,6 +1428,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: nil, expectedErr: "containerd image only supported in 1.22+", @@ -1452,6 +1458,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.23.3", "", "windows-2019") @@ -1484,6 +1491,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultWindowsImage(context.TODO(), "", "1.23.3", "", "windows-2022") @@ -1508,6 +1516,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { }, }, ClusterScoper: clusterMock, + cache: &MachineCache{}, }, want: func() *infrav1.Image { image, _ := svc.GetDefaultUbuntuImage(context.TODO(), "", "1.20.1") @@ -1606,6 +1615,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ @@ -1707,7 +1717,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, cache: &MachineCache{ - VMSKU: resourceskus.SKU{ + VMSKU: &resourceskus.SKU{ Name: to.StringPtr("Standard_D2v2"), }, }, @@ -1818,6 +1828,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ @@ -1919,6 +1930,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ @@ -2025,6 +2037,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ @@ -2128,6 +2141,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ @@ -2232,6 +2246,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + cache: &MachineCache{}, }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ @@ -2264,7 +2279,7 @@ func TestMachineScope_NICSpecs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotNicSpecs := tt.machineScope.NICSpecs() + gotNicSpecs := tt.machineScope.NICSpecs(context.TODO()) if !reflect.DeepEqual(gotNicSpecs, tt.want) { t.Errorf("NICSpecs(), gotNicSpecs = %s, want %s", specArrayToString(gotNicSpecs), specArrayToString(tt.want)) } diff --git a/azure/scope/machinepool.go b/azure/scope/machinepool.go index 6286b9c753f..cc1ec7e627a 100644 --- a/azure/scope/machinepool.go +++ b/azure/scope/machinepool.go @@ -58,6 +58,7 @@ type ( MachinePool *expv1.MachinePool AzureMachinePool *infrav1exp.AzureMachinePool ClusterScope azure.ClusterScoper + Cache *MachinePoolCache } // MachinePoolScope defines a scope defined around a machine pool and its cluster. @@ -68,6 +69,7 @@ type ( client client.Client patchHelper *patch.Helper vmssState *azure.VMSS + cache *MachinePoolCache } // NodeStatus represents the status of a Kubernetes node. @@ -75,6 +77,12 @@ type ( Ready bool Version string } + + // MachinePoolCache stores common machine information so we don't have to hit the API multiple times within the same reconcile loop. + MachinePoolCache struct { + BootstrapData *string + VMImage *infrav1.Image + } ) // NewMachinePoolScope creates a new MachinePoolScope from the supplied parameters. @@ -92,6 +100,10 @@ func NewMachinePoolScope(params MachinePoolScopeParams) (*MachinePoolScope, erro return nil, errors.New("azure machine pool is required when creating a MachinePoolScope") } + if params.Cache == nil { + params.Cache = &MachinePoolCache{} + } + helper, err := patch.NewHelper(params.AzureMachinePool, params.Client) if err != nil { return nil, errors.Wrap(err, "failed to init patch helper") @@ -103,6 +115,7 @@ func NewMachinePoolScope(params MachinePoolScopeParams) (*MachinePoolScope, erro AzureMachinePool: params.AzureMachinePool, patchHelper: helper, ClusterScoper: params.ClusterScope, + cache: params.Cache, }, nil } @@ -529,6 +542,10 @@ func (m *MachinePoolScope) GetBootstrapData(ctx context.Context) (string, error) ctx, _, done := tele.StartSpanWithLogger(ctx, "scope.MachinePoolScope.GetBootstrapData") defer done() + if m.cache.BootstrapData != nil { + return to.String(m.cache.BootstrapData), nil + } + dataSecretName := m.MachinePool.Spec.Template.Spec.Bootstrap.DataSecretName if dataSecretName == nil { return "", errors.New("error retrieving bootstrap data: linked MachinePool Spec's bootstrap.dataSecretName is nil") @@ -543,7 +560,9 @@ func (m *MachinePoolScope) GetBootstrapData(ctx context.Context) (string, error) if !ok { return "", errors.New("error retrieving bootstrap data: secret value key is missing") } - return base64.StdEncoding.EncodeToString(value), nil + bootstrapData := base64.StdEncoding.EncodeToString(value) + m.cache.BootstrapData = to.StringPtr(bootstrapData) + return bootstrapData, nil } // GetVMImage picks an image from the AzureMachinePool configuration, or uses a default one. @@ -556,6 +575,10 @@ func (m *MachinePoolScope) GetVMImage(ctx context.Context) (*infrav1.Image, erro return m.AzureMachinePool.Spec.Template.Image, nil } + if m.cache.VMImage != nil { + return m.cache.VMImage, nil + } + svc := virtualmachineimages.New(m) var ( @@ -574,6 +597,7 @@ func (m *MachinePoolScope) GetVMImage(ctx context.Context) (*infrav1.Image, erro if err != nil { return defaultImage, errors.Wrap(err, "failed to get default OS image") } + m.cache.VMImage = defaultImage return defaultImage, nil } diff --git a/azure/scope/machinepool_test.go b/azure/scope/machinepool_test.go index cd82f910349..a328b59b4e7 100644 --- a/azure/scope/machinepool_test.go +++ b/azure/scope/machinepool_test.go @@ -407,6 +407,7 @@ func TestMachinePoolScope_GetVMImage(t *testing.T) { MachinePool: mp, AzureMachinePool: amp, ClusterScoper: clusterMock, + cache: &MachinePoolCache{}, } image, err := s.GetVMImage(context.TODO()) c.Verify(g, amp, image, err) diff --git a/azure/services/availabilitysets/availabilitysets.go b/azure/services/availabilitysets/availabilitysets.go index 1d8b5009d4e..359c323e8c8 100644 --- a/azure/services/availabilitysets/availabilitysets.go +++ b/azure/services/availabilitysets/availabilitysets.go @@ -35,7 +35,7 @@ const serviceName = "availabilitysets" type AvailabilitySetScope interface { azure.ClusterDescriber azure.AsyncStatusUpdater - AvailabilitySetSpec() azure.ResourceSpecGetter + AvailabilitySetSpec(context.Context) azure.ResourceSpecGetter } // Service provides operations on Azure resources. @@ -71,7 +71,7 @@ func (s *Service) Reconcile(ctx context.Context) error { defer cancel() var err error - if setSpec := s.Scope.AvailabilitySetSpec(); setSpec != nil { + if setSpec := s.Scope.AvailabilitySetSpec(ctx); setSpec != nil { _, err = s.CreateResource(ctx, setSpec, serviceName) } else { log.V(2).Info("skip creation when no availability set spec is found") @@ -91,7 +91,7 @@ func (s *Service) Delete(ctx context.Context) error { defer cancel() var resultingErr error - setSpec := s.Scope.AvailabilitySetSpec() + setSpec := s.Scope.AvailabilitySetSpec(ctx) if setSpec == nil { log.V(2).Info("skip deletion when no availability set spec is found") return nil diff --git a/azure/services/availabilitysets/availabilitysets_test.go b/azure/services/availabilitysets/availabilitysets_test.go index 52fcb1a79a9..db8289215ac 100644 --- a/azure/services/availabilitysets/availabilitysets_test.go +++ b/azure/services/availabilitysets/availabilitysets_test.go @@ -83,7 +83,7 @@ func TestReconcileAvailabilitySets(t *testing.T) { name: "create or update availability set", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) r.CreateResource(gomockinternal.AContext(), &fakeSetSpec, serviceName).Return(nil, nil) s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, nil) }, @@ -92,14 +92,14 @@ func TestReconcileAvailabilitySets(t *testing.T) { name: "noop if no availability set spec returns nil", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(nil) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(nil) }, }, { name: "missing required value in availability set spec", expectedError: "some error with parameters", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpecMissing) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpecMissing) r.CreateResource(gomockinternal.AContext(), &fakeSetSpecMissing, serviceName).Return(nil, parameterError) s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, parameterError) }, @@ -108,7 +108,7 @@ func TestReconcileAvailabilitySets(t *testing.T) { name: "error in creating availability set", expectedError: "#: Internal Server Error: StatusCode=500", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) r.CreateResource(gomockinternal.AContext(), &fakeSetSpec, serviceName).Return(nil, internalError) s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, internalError) }, @@ -153,7 +153,7 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "deletes availability set", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpec).Return(compute.AvailabilitySet{}, nil), r.DeleteResource(gomockinternal.AContext(), &fakeSetSpec, serviceName).Return(nil), @@ -165,14 +165,14 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "noop if AvailabilitySetSpec returns nil", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(nil) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(nil) }, }, { name: "delete proceeds with missing required value in availability set spec", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpecMissing) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpecMissing) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpecMissing).Return(compute.AvailabilitySet{}, nil), r.DeleteResource(gomockinternal.AContext(), &fakeSetSpecMissing, serviceName).Return(nil), @@ -184,7 +184,7 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "noop if availability set has vms", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpec).Return(fakeSetWithVMs, nil), s.UpdateDeleteStatus(infrav1.AvailabilitySetReadyCondition, serviceName, nil), @@ -195,7 +195,7 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "availability set not found", expectedError: "", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpec).Return(nil, notFoundError), s.UpdateDeleteStatus(infrav1.AvailabilitySetReadyCondition, serviceName, nil), @@ -206,7 +206,7 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "error in getting availability set", expectedError: "failed to get availability set test-as in resource group test-rg: #: Internal Server Error: StatusCode=500", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpec).Return(nil, internalError), s.UpdateDeleteStatus(infrav1.AvailabilitySetReadyCondition, serviceName, gomockinternal.ErrStrEq("failed to get availability set test-as in resource group test-rg: #: Internal Server Error: StatusCode=500")), @@ -217,7 +217,7 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "availability set get result is not an availability set", expectedError: "string is not a compute.AvailabilitySet", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpec).Return("not an availability set", nil), s.UpdateDeleteStatus(infrav1.AvailabilitySetReadyCondition, serviceName, gomockinternal.ErrStrEq("string is not a compute.AvailabilitySet")), @@ -228,7 +228,7 @@ func TestDeleteAvailabilitySets(t *testing.T) { name: "error in deleting availability set", expectedError: "#: Internal Server Error: StatusCode=500", expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.AvailabilitySetSpec().Return(&fakeSetSpec) + s.AvailabilitySetSpec(gomockinternal.AContext()).Return(&fakeSetSpec) gomock.InOrder( m.Get(gomockinternal.AContext(), &fakeSetSpec).Return(compute.AvailabilitySet{}, nil), r.DeleteResource(gomockinternal.AContext(), &fakeSetSpec, serviceName).Return(internalError), diff --git a/azure/services/availabilitysets/mock_availabilitysets/availabilitysets_mock.go b/azure/services/availabilitysets/mock_availabilitysets/availabilitysets_mock.go index 58aaf983974..d19679191e5 100644 --- a/azure/services/availabilitysets/mock_availabilitysets/availabilitysets_mock.go +++ b/azure/services/availabilitysets/mock_availabilitysets/availabilitysets_mock.go @@ -21,6 +21,7 @@ limitations under the License. package mock_availabilitysets import ( + context "context" reflect "reflect" autorest "github.com/Azure/go-autorest/autorest" @@ -96,17 +97,17 @@ func (mr *MockAvailabilitySetScopeMockRecorder) AvailabilitySetEnabled() *gomock } // AvailabilitySetSpec mocks base method. -func (m *MockAvailabilitySetScope) AvailabilitySetSpec() azure.ResourceSpecGetter { +func (m *MockAvailabilitySetScope) AvailabilitySetSpec(arg0 context.Context) azure.ResourceSpecGetter { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AvailabilitySetSpec") + ret := m.ctrl.Call(m, "AvailabilitySetSpec", arg0) ret0, _ := ret[0].(azure.ResourceSpecGetter) return ret0 } // AvailabilitySetSpec indicates an expected call of AvailabilitySetSpec. -func (mr *MockAvailabilitySetScopeMockRecorder) AvailabilitySetSpec() *gomock.Call { +func (mr *MockAvailabilitySetScopeMockRecorder) AvailabilitySetSpec(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailabilitySetSpec", reflect.TypeOf((*MockAvailabilitySetScope)(nil).AvailabilitySetSpec)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailabilitySetSpec", reflect.TypeOf((*MockAvailabilitySetScope)(nil).AvailabilitySetSpec), arg0) } // BaseURI mocks base method. diff --git a/azure/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go b/azure/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go index 0abcd0143ee..e305ac30bba 100644 --- a/azure/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go +++ b/azure/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go @@ -21,6 +21,7 @@ limitations under the License. package mock_networkinterfaces import ( + context "context" reflect "reflect" autorest "github.com/Azure/go-autorest/autorest" @@ -248,17 +249,17 @@ func (mr *MockNICScopeMockRecorder) Location() *gomock.Call { } // NICSpecs mocks base method. -func (m *MockNICScope) NICSpecs() []azure.ResourceSpecGetter { +func (m *MockNICScope) NICSpecs(arg0 context.Context) []azure.ResourceSpecGetter { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NICSpecs") + ret := m.ctrl.Call(m, "NICSpecs", arg0) ret0, _ := ret[0].([]azure.ResourceSpecGetter) return ret0 } // NICSpecs indicates an expected call of NICSpecs. -func (mr *MockNICScopeMockRecorder) NICSpecs() *gomock.Call { +func (mr *MockNICScopeMockRecorder) NICSpecs(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NICSpecs", reflect.TypeOf((*MockNICScope)(nil).NICSpecs)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NICSpecs", reflect.TypeOf((*MockNICScope)(nil).NICSpecs), arg0) } // ResourceGroup mocks base method. diff --git a/azure/services/networkinterfaces/networkinterfaces.go b/azure/services/networkinterfaces/networkinterfaces.go index 75178f063e9..801e754cabf 100644 --- a/azure/services/networkinterfaces/networkinterfaces.go +++ b/azure/services/networkinterfaces/networkinterfaces.go @@ -33,7 +33,7 @@ const serviceName = "interfaces" type NICScope interface { azure.ClusterDescriber azure.AsyncStatusUpdater - NICSpecs() []azure.ResourceSpecGetter + NICSpecs(context.Context) []azure.ResourceSpecGetter } // Service provides operations on Azure resources. @@ -66,7 +66,7 @@ func (s *Service) Reconcile(ctx context.Context) error { ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout) defer cancel() - specs := s.Scope.NICSpecs() + specs := s.Scope.NICSpecs(ctx) if len(specs) == 0 { return nil } @@ -95,7 +95,7 @@ func (s *Service) Delete(ctx context.Context) error { ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout) defer cancel() - specs := s.Scope.NICSpecs() + specs := s.Scope.NICSpecs(ctx) if len(specs) == 0 { return nil } diff --git a/azure/services/networkinterfaces/networkinterfaces_test.go b/azure/services/networkinterfaces/networkinterfaces_test.go index 4529567bf98..4f6a09caa4b 100644 --- a/azure/services/networkinterfaces/networkinterfaces_test.go +++ b/azure/services/networkinterfaces/networkinterfaces_test.go @@ -71,14 +71,14 @@ func TestReconcileNetworkInterface(t *testing.T) { name: "noop if no network interface specs are found", expectedError: "", expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{}) }, }, { name: "successfully create a network interface", expectedError: "", expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{&fakeNICSpec1}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{&fakeNICSpec1}) r.CreateResource(gomockinternal.AContext(), &fakeNICSpec1, serviceName).Return(nil, nil) s.UpdatePutStatus(infrav1.NetworkInterfaceReadyCondition, serviceName, nil) }, @@ -87,7 +87,7 @@ func TestReconcileNetworkInterface(t *testing.T) { name: "successfully create multiple network interfaces", expectedError: "", expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) r.CreateResource(gomockinternal.AContext(), &fakeNICSpec1, serviceName).Return(nil, nil) r.CreateResource(gomockinternal.AContext(), &fakeNICSpec2, serviceName).Return(nil, nil) s.UpdatePutStatus(infrav1.NetworkInterfaceReadyCondition, serviceName, nil) @@ -97,7 +97,7 @@ func TestReconcileNetworkInterface(t *testing.T) { name: "network interface create fails", expectedError: internalError.Error(), expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) r.CreateResource(gomockinternal.AContext(), &fakeNICSpec1, serviceName).Return(nil, internalError) r.CreateResource(gomockinternal.AContext(), &fakeNICSpec2, serviceName).Return(nil, nil) s.UpdatePutStatus(infrav1.NetworkInterfaceReadyCondition, serviceName, internalError) @@ -145,14 +145,14 @@ func TestDeleteNetworkInterface(t *testing.T) { name: "noop if no network interface specs are found", expectedError: "", expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{}) }, }, { name: "successfully delete an existing network interface", expectedError: "", expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{&fakeNICSpec1}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{&fakeNICSpec1}) r.DeleteResource(gomockinternal.AContext(), &fakeNICSpec1, serviceName).Return(nil) s.UpdateDeleteStatus(infrav1.NetworkInterfaceReadyCondition, serviceName, nil) }, @@ -161,7 +161,7 @@ func TestDeleteNetworkInterface(t *testing.T) { name: "successfully delete multiple existing network interfaces", expectedError: "", expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) r.DeleteResource(gomockinternal.AContext(), &fakeNICSpec1, serviceName).Return(nil) r.DeleteResource(gomockinternal.AContext(), &fakeNICSpec2, serviceName).Return(nil) s.UpdateDeleteStatus(infrav1.NetworkInterfaceReadyCondition, serviceName, nil) @@ -171,7 +171,7 @@ func TestDeleteNetworkInterface(t *testing.T) { name: "network interface deletion fails", expectedError: internalError.Error(), expect: func(s *mock_networkinterfaces.MockNICScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.NICSpecs().Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) + s.NICSpecs(gomockinternal.AContext()).Return([]azure.ResourceSpecGetter{&fakeNICSpec1, &fakeNICSpec2}) r.DeleteResource(gomockinternal.AContext(), &fakeNICSpec1, serviceName).Return(nil) r.DeleteResource(gomockinternal.AContext(), &fakeNICSpec2, serviceName).Return(internalError) s.UpdateDeleteStatus(infrav1.NetworkInterfaceReadyCondition, serviceName, internalError) diff --git a/azure/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go b/azure/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go index 200aca50596..35041a75777 100644 --- a/azure/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go +++ b/azure/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go @@ -21,6 +21,7 @@ limitations under the License. package mock_virtualmachines import ( + context "context" reflect "reflect" autorest "github.com/Azure/go-autorest/autorest" @@ -289,15 +290,15 @@ func (mr *MockVMScopeMockRecorder) UpdatePutStatus(arg0, arg1, arg2 interface{}) } // VMSpec mocks base method. -func (m *MockVMScope) VMSpec() azure.ResourceSpecGetter { +func (m *MockVMScope) VMSpec(arg0 context.Context) azure.ResourceSpecGetter { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "VMSpec") + ret := m.ctrl.Call(m, "VMSpec", arg0) ret0, _ := ret[0].(azure.ResourceSpecGetter) return ret0 } // VMSpec indicates an expected call of VMSpec. -func (mr *MockVMScopeMockRecorder) VMSpec() *gomock.Call { +func (mr *MockVMScopeMockRecorder) VMSpec(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VMSpec", reflect.TypeOf((*MockVMScope)(nil).VMSpec)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VMSpec", reflect.TypeOf((*MockVMScope)(nil).VMSpec), arg0) } diff --git a/azure/services/virtualmachines/virtualmachines.go b/azure/services/virtualmachines/virtualmachines.go index 4f8ea3efbe3..6b25e61d0e9 100644 --- a/azure/services/virtualmachines/virtualmachines.go +++ b/azure/services/virtualmachines/virtualmachines.go @@ -42,7 +42,7 @@ const serviceName = "virtualmachine" type VMScope interface { azure.Authorizer azure.AsyncStatusUpdater - VMSpec() azure.ResourceSpecGetter + VMSpec(context.Context) azure.ResourceSpecGetter SetAnnotation(string, string) SetProviderID(string) SetAddresses([]corev1.NodeAddress) @@ -81,7 +81,7 @@ func (s *Service) Reconcile(ctx context.Context) error { ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout) defer cancel() - vmSpec := s.Scope.VMSpec() + vmSpec := s.Scope.VMSpec(ctx) if vmSpec == nil { return nil } @@ -123,7 +123,7 @@ func (s *Service) Delete(ctx context.Context) error { ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout) defer cancel() - vmSpec := s.Scope.VMSpec() + vmSpec := s.Scope.VMSpec(ctx) if vmSpec == nil { return nil } diff --git a/azure/services/virtualmachines/virtualmachines_test.go b/azure/services/virtualmachines/virtualmachines_test.go index 002be825bfe..0dc21ba4eaa 100644 --- a/azure/services/virtualmachines/virtualmachines_test.go +++ b/azure/services/virtualmachines/virtualmachines_test.go @@ -120,14 +120,14 @@ func TestReconcileVM(t *testing.T) { name: "noop if no vm spec is found", expectedError: "", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, mnic *mock_async.MockGetterMockRecorder, mpip *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().Return(nil) + s.VMSpec(gomockinternal.AContext()).Return(nil) }, }, { name: "create vm succeeds", expectedError: "", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, mnic *mock_async.MockGetterMockRecorder, mpip *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).Return(&fakeVMSpec) r.CreateResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(fakeExistingVM, nil) s.UpdatePutStatus(infrav1.VMRunningCondition, serviceName, nil) s.UpdatePutStatus(infrav1.DisksReadyCondition, serviceName, nil) @@ -143,7 +143,7 @@ func TestReconcileVM(t *testing.T) { name: "creating vm fails", expectedError: "#: Internal Server Error: StatusCode=500", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, mnic *mock_async.MockGetterMockRecorder, mpip *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).Return(&fakeVMSpec) r.CreateResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(nil, internalError) s.UpdatePutStatus(infrav1.VMRunningCondition, serviceName, internalError) s.UpdatePutStatus(infrav1.DisksReadyCondition, serviceName, internalError) @@ -153,7 +153,7 @@ func TestReconcileVM(t *testing.T) { name: "create vm succeeds but failed to get network interfaces", expectedError: "failed to fetch VM addresses: #: Internal Server Error: StatusCode=500", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, mnic *mock_async.MockGetterMockRecorder, mpip *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).Return(&fakeVMSpec) r.CreateResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(fakeExistingVM, nil) s.UpdatePutStatus(infrav1.VMRunningCondition, serviceName, nil) s.UpdatePutStatus(infrav1.DisksReadyCondition, serviceName, nil) @@ -166,7 +166,7 @@ func TestReconcileVM(t *testing.T) { name: "create vm succeeds but failed to get public IPs", expectedError: "failed to fetch VM addresses: #: Internal Server Error: StatusCode=500", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, mnic *mock_async.MockGetterMockRecorder, mpip *mock_async.MockGetterMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).Return(&fakeVMSpec) r.CreateResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(fakeExistingVM, nil) s.UpdatePutStatus(infrav1.VMRunningCondition, serviceName, nil) s.UpdatePutStatus(infrav1.DisksReadyCondition, serviceName, nil) @@ -221,14 +221,14 @@ func TestDeleteVM(t *testing.T) { name: "noop if no vm spec is found", expectedError: "", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().Return(nil) + s.VMSpec(gomockinternal.AContext()).Return(nil) }, }, { name: "vm doesn't exist", expectedError: "", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().AnyTimes().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).AnyTimes().Return(&fakeVMSpec) r.DeleteResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(nil) s.SetVMState(infrav1.Deleted) s.UpdateDeleteStatus(infrav1.VMRunningCondition, serviceName, nil) @@ -238,7 +238,7 @@ func TestDeleteVM(t *testing.T) { name: "error occurs when deleting vm", expectedError: "#: Internal Server Error: StatusCode=500", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().AnyTimes().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).AnyTimes().Return(&fakeVMSpec) r.DeleteResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(internalError) s.SetVMState(infrav1.Deleting) s.UpdateDeleteStatus(infrav1.VMRunningCondition, serviceName, internalError) @@ -248,7 +248,7 @@ func TestDeleteVM(t *testing.T) { name: "delete the vm successfully", expectedError: "", expect: func(s *mock_virtualmachines.MockVMScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) { - s.VMSpec().AnyTimes().Return(&fakeVMSpec) + s.VMSpec(gomockinternal.AContext()).AnyTimes().Return(&fakeVMSpec) r.DeleteResource(gomockinternal.AContext(), &fakeVMSpec, serviceName).Return(nil) s.SetVMState(infrav1.Deleted) s.UpdateDeleteStatus(infrav1.VMRunningCondition, serviceName, nil) diff --git a/controllers/azuremachine_controller.go b/controllers/azuremachine_controller.go index 08519f4092c..6d645691c36 100644 --- a/controllers/azuremachine_controller.go +++ b/controllers/azuremachine_controller.go @@ -270,20 +270,6 @@ func (amr *AzureMachineReconciler) reconcileNormal(ctx context.Context, machineS var reconcileError azure.ReconcileError - // Initialize the cache to be used by the AzureMachine services. - err := machineScope.InitMachineCache(ctx) - if err != nil { - if errors.As(err, &reconcileError) && reconcileError.IsTerminal() { - amr.Recorder.Eventf(machineScope.AzureMachine, corev1.EventTypeWarning, "SKUNotFound", errors.Wrap(err, "failed to initialize machine cache").Error()) - log.Error(err, "Failed to initialize machine cache") - machineScope.SetFailureReason(capierrors.InvalidConfigurationMachineError) - machineScope.SetFailureMessage(err) - machineScope.SetNotReady() - return reconcile.Result{}, nil - } - return reconcile.Result{}, errors.Wrap(err, "failed to init machine scope cache") - } - ams, err := amr.createAzureMachineService(machineScope) if err != nil { return reconcile.Result{}, errors.Wrap(err, "failed to create azure machine service")