Skip to content

Commit

Permalink
Update subnet test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Feb 24, 2022
1 parent e9c0c42 commit a1e3947
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
5 changes: 1 addition & 4 deletions azure/services/subnets/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
} else {
subnet, ok := result.(network.Subnet)
if !ok {
resultErr = errors.Errorf("%T is not a network.Subnet", result)
break
return errors.Errorf("%T is not a network.Subnet", result)
}
var addresses []string
if subnet.SubnetPropertiesFormat != nil && subnet.SubnetPropertiesFormat.AddressPrefix != nil {
Expand Down Expand Up @@ -113,8 +112,6 @@ func (s *Service) Delete(ctx context.Context) error {

if !s.Scope.IsVnetManaged() {
log.V(4).Info("Skipping subnets deletion in custom vnet mode")

s.Scope.UpdateDeleteStatus(infrav1.SubnetsReadyCondition, serviceName, nil)
return nil
}

Expand Down
27 changes: 12 additions & 15 deletions azure/services/subnets/subnets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestReconcileSubnets(t *testing.T) {
s.UpdateSubnetID(fakeSubnetSpec1.Name, to.String(fakeSubnet1.ID))
s.UpdateSubnetCIDRs(fakeSubnetSpec1.Name, []string{to.String(fakeSubnet1.AddressPrefix)})

s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil)
},
},
Expand All @@ -232,7 +232,7 @@ func TestReconcileSubnets(t *testing.T) {
s.UpdateSubnetID(fakeSubnetSpec2.Name, to.String(fakeSubnet2.ID))
s.UpdateSubnetCIDRs(fakeSubnetSpec2.Name, []string{to.String(fakeSubnet2.AddressPrefix)})

s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil)
},
},
Expand All @@ -246,7 +246,7 @@ func TestReconcileSubnets(t *testing.T) {
s.UpdateSubnetID(fakeSubnetSpecNotManaged.Name, to.String(fakeSubnetNotManaged.ID))
s.UpdateSubnetCIDRs(fakeSubnetSpecNotManaged.Name, []string{to.String(fakeSubnetNotManaged.AddressPrefix)})

s.IsVnetManaged().Return(false)
s.IsVnetManaged().AnyTimes().Return(false)
},
},
{
Expand All @@ -259,7 +259,7 @@ func TestReconcileSubnets(t *testing.T) {
s.UpdateSubnetID(fakeIpv6SubnetSpec.Name, to.String(fakeIpv6Subnet.ID))
s.UpdateSubnetCIDRs(fakeIpv6SubnetSpec.Name, to.StringSlice(fakeIpv6Subnet.AddressPrefixes))

s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil)
},
},
Expand All @@ -277,7 +277,7 @@ func TestReconcileSubnets(t *testing.T) {
s.UpdateSubnetID(fakeIpv6SubnetSpecCP.Name, to.String(fakeIpv6SubnetCP.ID))
s.UpdateSubnetCIDRs(fakeIpv6SubnetSpecCP.Name, to.StringSlice(fakeIpv6SubnetCP.AddressPrefixes))

s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, nil)
},
},
Expand All @@ -288,7 +288,7 @@ func TestReconcileSubnets(t *testing.T) {
s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1})
r.CreateResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(nil, internalError)

s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, internalError)
},
},
Expand All @@ -298,9 +298,6 @@ func TestReconcileSubnets(t *testing.T) {
expect: func(s *mock_subnets.MockSubnetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1})
r.CreateResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(notASubnet, nil)

s.IsVnetManaged().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, notASubnetErr)
},
},
{
Expand All @@ -314,7 +311,7 @@ func TestReconcileSubnets(t *testing.T) {
s.UpdateSubnetID(fakeSubnetSpec2.Name, to.String(fakeSubnet2.ID))
s.UpdateSubnetCIDRs(fakeSubnetSpec2.Name, []string{to.String(fakeSubnet2.AddressPrefix)})

s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.UpdatePutStatus(infrav1.SubnetsReadyCondition, serviceName, internalError)
},
},
Expand Down Expand Up @@ -359,15 +356,15 @@ func TestDeleteSubnets(t *testing.T) {
name: "noop if no subnet specs are found",
expectedError: "",
expect: func(s *mock_subnets.MockSubnetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.SubnetSpecs().Return([]azure.ResourceSpecGetter{})
},
},
{
name: "subnets deleted successfully",
expectedError: "",
expect: func(s *mock_subnets.MockSubnetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1, &fakeSubnetSpec2})
r.DeleteResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(nil)
r.DeleteResource(gomockinternal.AContext(), &fakeSubnetSpec2, serviceName).Return(nil)
Expand All @@ -378,7 +375,7 @@ func TestDeleteSubnets(t *testing.T) {
name: "node subnet and controlplane subnet deleted successfully",
expectedError: "",
expect: func(s *mock_subnets.MockSubnetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1, &fakeCtrlPlaneSubnetSpec})
r.DeleteResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(nil)
r.DeleteResource(gomockinternal.AContext(), &fakeCtrlPlaneSubnetSpec, serviceName).Return(nil)
Expand All @@ -389,14 +386,14 @@ func TestDeleteSubnets(t *testing.T) {
name: "skip delete if vnet is not managed",
expectedError: "",
expect: func(s *mock_subnets.MockSubnetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.IsVnetManaged().Return(false)
s.IsVnetManaged().AnyTimes().Return(false)
},
},
{
name: "fail delete subnet",
expectedError: "#: Internal Server Error: StatusCode=500",
expect: func(s *mock_subnets.MockSubnetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.IsVnetManaged().Return(true)
s.IsVnetManaged().AnyTimes().Return(true)
s.SubnetSpecs().Return([]azure.ResourceSpecGetter{&fakeSubnetSpec1})
r.DeleteResource(gomockinternal.AContext(), &fakeSubnetSpec1, serviceName).Return(internalError)
s.UpdateDeleteStatus(infrav1.SubnetsReadyCondition, serviceName, internalError)
Expand Down
1 change: 1 addition & 0 deletions controllers/azurecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (acr *AzureClusterReconciler) reconcileNormal(ctx context.Context, clusterS

wrappedErr := errors.Wrap(err, "failed to reconcile cluster services")
acr.Recorder.Eventf(azureCluster, corev1.EventTypeWarning, "ClusterReconcilerNormalFailed", wrappedErr.Error())
conditions.MarkFalse(azureCluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.FailedReason, clusterv1.ConditionSeverityError, wrappedErr.Error())
return reconcile.Result{}, wrappedErr
}

Expand Down

0 comments on commit a1e3947

Please sign in to comment.