Skip to content

Commit

Permalink
Merge pull request kubernetes#101499 from ialidzhikov/automated-cherr…
Browse files Browse the repository at this point in the history
…y-pick-of-#100944-upstream-release-1.19

Automated cherry pick of kubernetes#100944: Ensure service deleted when the Azure resource group has been deleted
  • Loading branch information
k8s-ci-robot committed May 7, 2021
2 parents 834f555 + a3f3937 commit 59dede3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func (az *Cloud) ListLB(service *v1.Service) ([]network.LoadBalancer, error) {
rgName := az.getLoadBalancerResourceGroup()
allLBs, rerr := az.LoadBalancerClient.List(ctx, rgName)
if rerr != nil {
if rerr.IsNotFound() {
return nil, nil
}
az.Event(service, v1.EventTypeWarning, "ListLoadBalancers", rerr.Error().Error())
klog.Errorf("LoadBalancerClient.List(%v) failure with err=%v", rgName, rerr)
return nil, rerr.Error()
Expand All @@ -288,6 +291,9 @@ func (az *Cloud) ListPIP(service *v1.Service, pipResourceGroup string) ([]networ

allPIPs, rerr := az.PublicIPAddressesClient.List(ctx, pipResourceGroup)
if rerr != nil {
if rerr.IsNotFound() {
return nil, nil
}
az.Event(service, v1.EventTypeWarning, "ListPublicIPs", rerr.Error().Error())
klog.Errorf("PublicIPAddressesClient.List(%v) failure with err=%v", pipResourceGroup, rerr)
return nil, rerr.Error()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,57 @@ func TestListLB(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

az := GetTestCloud(ctrl)
mockLBClient := az.LoadBalancerClient.(*mockloadbalancerclient.MockInterface)
mockLBClient.EXPECT().List(gomock.Any(), az.ResourceGroup).Return(nil, &retry.Error{HTTPStatusCode: http.StatusInternalServerError})
tests := []struct {
clientErr *retry.Error
expectedErr error
}{
{
clientErr: &retry.Error{HTTPStatusCode: http.StatusInternalServerError},
expectedErr: fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 500, RawError: <nil>"),
},
{
clientErr: &retry.Error{HTTPStatusCode: http.StatusNotFound},
expectedErr: nil,
},
}
for _, test := range tests {
az := GetTestCloud(ctrl)
mockLBClient := az.LoadBalancerClient.(*mockloadbalancerclient.MockInterface)
mockLBClient.EXPECT().List(gomock.Any(), az.ResourceGroup).Return(nil, test.clientErr)

pips, err := az.ListLB(&v1.Service{})
assert.Equal(t, test.expectedErr, err)
assert.Empty(t, pips)
}

pips, err := az.ListLB(&v1.Service{})
assert.Equal(t, fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 500, RawError: <nil>"), err)
assert.Empty(t, pips)
}

func TestListPIP(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

az := GetTestCloud(ctrl)
mockPIPClient := az.PublicIPAddressesClient.(*mockpublicipclient.MockInterface)
mockPIPClient.EXPECT().List(gomock.Any(), az.ResourceGroup).Return(nil, &retry.Error{HTTPStatusCode: http.StatusInternalServerError})
tests := []struct {
clientErr *retry.Error
expectedErr error
}{
{
clientErr: &retry.Error{HTTPStatusCode: http.StatusInternalServerError},
expectedErr: fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 500, RawError: <nil>"),
},
{
clientErr: &retry.Error{HTTPStatusCode: http.StatusNotFound},
expectedErr: nil,
},
}
for _, test := range tests {
az := GetTestCloud(ctrl)
mockPIPClient := az.PublicIPAddressesClient.(*mockpublicipclient.MockInterface)
mockPIPClient.EXPECT().List(gomock.Any(), az.ResourceGroup).Return(nil, test.clientErr)

pips, err := az.ListPIP(&v1.Service{}, az.ResourceGroup)
assert.Equal(t, fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 500, RawError: <nil>"), err)
assert.Empty(t, pips)
pips, err := az.ListPIP(&v1.Service{}, az.ResourceGroup)
assert.Equal(t, test.expectedErr, err)
assert.Empty(t, pips)
}
}

func TestCreateOrUpdatePIP(t *testing.T) {
Expand Down

0 comments on commit 59dede3

Please sign in to comment.