Merge pull request #88405 from feiskyer/mock-vmset

Swith to mock clients for route/routetable/networkinterface tests
This commit is contained in:
Kubernetes Prow Robot 2020-02-22 00:09:02 -08:00 committed by GitHub
commit de75bf9443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 769 additions and 445 deletions

View File

@ -68,11 +68,14 @@ go_library(
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/publicipclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/publicipclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routeclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routeclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/snapshotclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/snapshotclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/subnetclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/subnetclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssclient:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssclient:go_default_library",
@ -85,6 +88,7 @@ go_library(
"//vendor/github.com/Azure/go-autorest/autorest:go_default_library", "//vendor/github.com/Azure/go-autorest/autorest:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest/azure:go_default_library", "//vendor/github.com/Azure/go-autorest/autorest/azure:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest/to:go_default_library", "//vendor/github.com/Azure/go-autorest/autorest/to:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/rubiojr/go-vhd/vhd:go_default_library", "//vendor/github.com/rubiojr/go-vhd/vhd:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/net:go_default_library", "//vendor/k8s.io/utils/net:go_default_library",
@ -125,11 +129,15 @@ go_test(
"//staging/src/k8s.io/legacy-cloud-providers/azure/auth:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/auth:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/cache:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/cache:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/mockvmsets:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:go_default_library", "//staging/src/k8s.io/legacy-cloud-providers/azure/retry:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute:go_default_library", "//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network:go_default_library", "//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage:go_default_library", "//vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest/to:go_default_library", "//vendor/github.com/Azure/go-autorest/autorest/to:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library",
"//vendor/sigs.k8s.io/yaml:go_default_library", "//vendor/sigs.k8s.io/yaml:go_default_library",
@ -151,6 +159,7 @@ filegroup(
"//staging/src/k8s.io/legacy-cloud-providers/azure/cache:all-srcs", "//staging/src/k8s.io/legacy-cloud-providers/azure/cache:all-srcs",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:all-srcs", "//staging/src/k8s.io/legacy-cloud-providers/azure/clients:all-srcs",
"//staging/src/k8s.io/legacy-cloud-providers/azure/metrics:all-srcs", "//staging/src/k8s.io/legacy-cloud-providers/azure/metrics:all-srcs",
"//staging/src/k8s.io/legacy-cloud-providers/azure/mockvmsets:all-srcs",
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:all-srcs", "//staging/src/k8s.io/legacy-cloud-providers/azure/retry:all-srcs",
], ],
tags = ["automanaged"], tags = ["automanaged"],

View File

@ -24,6 +24,7 @@ import (
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@ -31,6 +32,9 @@ import (
) )
func TestCommonAttachDisk(t *testing.T) { func TestCommonAttachDisk(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
vmList map[string]string vmList map[string]string
@ -63,7 +67,7 @@ func TestCommonAttachDisk(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
common := &controllerCommon{ common := &controllerCommon{
location: testCloud.Location, location: testCloud.Location,
storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix,
@ -83,6 +87,9 @@ func TestCommonAttachDisk(t *testing.T) {
} }
func TestCommonDetachDisk(t *testing.T) { func TestCommonDetachDisk(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
vmList map[string]string vmList map[string]string
@ -112,7 +119,7 @@ func TestCommonDetachDisk(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
common := &controllerCommon{ common := &controllerCommon{
location: testCloud.Location, location: testCloud.Location,
storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix,
@ -131,6 +138,9 @@ func TestCommonDetachDisk(t *testing.T) {
} }
func TestGetDiskLun(t *testing.T) { func TestGetDiskLun(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
diskName string diskName string
@ -153,7 +163,7 @@ func TestGetDiskLun(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
common := &controllerCommon{ common := &controllerCommon{
location: testCloud.Location, location: testCloud.Location,
storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix,
@ -171,6 +181,9 @@ func TestGetDiskLun(t *testing.T) {
} }
func TestGetNextDiskLun(t *testing.T) { func TestGetNextDiskLun(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
isDataDisksFull bool isDataDisksFull bool
@ -192,7 +205,7 @@ func TestGetNextDiskLun(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
common := &controllerCommon{ common := &controllerCommon{
location: testCloud.Location, location: testCloud.Location,
storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix,
@ -210,6 +223,9 @@ func TestGetNextDiskLun(t *testing.T) {
} }
func TestDisksAreAttached(t *testing.T) { func TestDisksAreAttached(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
diskNames []string diskNames []string
@ -234,7 +250,7 @@ func TestDisksAreAttached(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
common := &controllerCommon{ common := &controllerCommon{
location: testCloud.Location, location: testCloud.Location,
storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix, storageEndpointSuffix: testCloud.Environment.StorageEndpointSuffix,

View File

@ -24,6 +24,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@ -35,6 +36,9 @@ var (
) )
func TestStandardAttachDisk(t *testing.T) { func TestStandardAttachDisk(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
nodeName types.NodeName nodeName types.NodeName
@ -53,7 +57,7 @@ func TestStandardAttachDisk(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
vmSet := testCloud.vmSet vmSet := testCloud.vmSet
setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false) setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false)
@ -64,6 +68,9 @@ func TestStandardAttachDisk(t *testing.T) {
} }
func TestStandardDetachDisk(t *testing.T) { func TestStandardDetachDisk(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
nodeName types.NodeName nodeName types.NodeName
@ -90,7 +97,7 @@ func TestStandardDetachDisk(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
vmSet := testCloud.vmSet vmSet := testCloud.vmSet
setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false) setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false)
@ -100,6 +107,9 @@ func TestStandardDetachDisk(t *testing.T) {
} }
func TestGetDataDisks(t *testing.T) { func TestGetDataDisks(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
var testCases = []struct { var testCases = []struct {
desc string desc string
nodeName types.NodeName nodeName types.NodeName
@ -140,7 +150,7 @@ func TestGetDataDisks(t *testing.T) {
}, },
} }
for i, test := range testCases { for i, test := range testCases {
testCloud := GetTestCloud() testCloud := GetTestCloud(ctrl)
vmSet := testCloud.vmSet vmSet := testCloud.vmSet
setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false) setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false)

View File

@ -24,21 +24,20 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"net/http" "net/http"
"strings"
"sync" "sync"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/legacy-cloud-providers/azure/auth" "k8s.io/legacy-cloud-providers/azure/auth"
azcache "k8s.io/legacy-cloud-providers/azure/cache" "k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient"
"k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient"
"k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient"
"k8s.io/legacy-cloud-providers/azure/retry" "k8s.io/legacy-cloud-providers/azure/retry"
) )
@ -382,81 +381,6 @@ func (fVMC *fakeAzureVirtualMachinesClient) setFakeStore(store map[string]map[st
fVMC.FakeStore = store fVMC.FakeStore = store
} }
type fakeAzureSubnetsClient struct {
mutex *sync.Mutex
FakeStore map[string]map[string]network.Subnet
}
func newFakeAzureSubnetsClient() *fakeAzureSubnetsClient {
fASC := &fakeAzureSubnetsClient{}
fASC.FakeStore = make(map[string]map[string]network.Subnet)
fASC.mutex = &sync.Mutex{}
return fASC
}
func (fASC *fakeAzureSubnetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters network.Subnet) *retry.Error {
fASC.mutex.Lock()
defer fASC.mutex.Unlock()
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
if _, ok := fASC.FakeStore[rgVnet]; !ok {
fASC.FakeStore[rgVnet] = make(map[string]network.Subnet)
}
fASC.FakeStore[rgVnet][subnetName] = subnetParameters
return nil
}
func (fASC *fakeAzureSubnetsClient) Delete(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string) *retry.Error {
fASC.mutex.Lock()
defer fASC.mutex.Unlock()
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
if rgSubnets, ok := fASC.FakeStore[rgVnet]; ok {
if _, ok := rgSubnets[subnetName]; ok {
delete(rgSubnets, subnetName)
return nil
}
}
return retry.GetError(
&http.Response{
StatusCode: http.StatusNotFound,
},
errors.New("Not such Subnet"))
}
func (fASC *fakeAzureSubnetsClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, expand string) (result network.Subnet, err *retry.Error) {
fASC.mutex.Lock()
defer fASC.mutex.Unlock()
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
if _, ok := fASC.FakeStore[rgVnet]; ok {
if entity, ok := fASC.FakeStore[rgVnet][subnetName]; ok {
return entity, nil
}
}
return result, retry.GetError(
&http.Response{
StatusCode: http.StatusNotFound,
},
errors.New("Not such Subnet"))
}
func (fASC *fakeAzureSubnetsClient) List(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result []network.Subnet, err *retry.Error) {
fASC.mutex.Lock()
defer fASC.mutex.Unlock()
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
var value []network.Subnet
if _, ok := fASC.FakeStore[rgVnet]; ok {
for _, v := range fASC.FakeStore[rgVnet] {
value = append(value, v)
}
}
return value, nil
}
type fakeAzureNSGClient struct { type fakeAzureNSGClient struct {
mutex *sync.Mutex mutex *sync.Mutex
FakeStore map[string]map[string]network.SecurityGroup FakeStore map[string]map[string]network.SecurityGroup
@ -677,98 +601,6 @@ func (fVMSSC *fakeVirtualMachineScaleSetsClient) DeleteInstances(ctx context.Con
return nil return nil
} }
type fakeRoutesClient struct {
mutex *sync.Mutex
FakeStore map[string]map[string]network.Route
Calls []string
}
func newFakeRoutesClient() *fakeRoutesClient {
fRC := &fakeRoutesClient{}
fRC.FakeStore = make(map[string]map[string]network.Route)
fRC.mutex = &sync.Mutex{}
return fRC
}
func (fRC *fakeRoutesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters network.Route, etag string) *retry.Error {
fRC.mutex.Lock()
defer fRC.mutex.Unlock()
fRC.Calls = append(fRC.Calls, "CreateOrUpdate")
if _, ok := fRC.FakeStore[routeTableName]; !ok {
fRC.FakeStore[routeTableName] = make(map[string]network.Route)
}
fRC.FakeStore[routeTableName][routeName] = routeParameters
return nil
}
func (fRC *fakeRoutesClient) Delete(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) *retry.Error {
fRC.mutex.Lock()
defer fRC.mutex.Unlock()
fRC.Calls = append(fRC.Calls, "Delete")
if routes, ok := fRC.FakeStore[routeTableName]; ok {
if _, ok := routes[routeName]; ok {
delete(routes, routeName)
return nil
}
}
return retry.GetError(
&http.Response{
StatusCode: http.StatusNotFound,
},
errors.New("Not such Route"))
}
type fakeRouteTablesClient struct {
mutex *sync.Mutex
FakeStore map[string]map[string]network.RouteTable
Calls []string
}
func newFakeRouteTablesClient() *fakeRouteTablesClient {
fRTC := &fakeRouteTablesClient{}
fRTC.FakeStore = make(map[string]map[string]network.RouteTable)
fRTC.mutex = &sync.Mutex{}
return fRTC
}
func (fRTC *fakeRouteTablesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters network.RouteTable, etag string) *retry.Error {
fRTC.mutex.Lock()
defer fRTC.mutex.Unlock()
fRTC.Calls = append(fRTC.Calls, "CreateOrUpdate")
if _, ok := fRTC.FakeStore[resourceGroupName]; !ok {
fRTC.FakeStore[resourceGroupName] = make(map[string]network.RouteTable)
}
fRTC.FakeStore[resourceGroupName][routeTableName] = parameters
return nil
}
func (fRTC *fakeRouteTablesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, expand string) (result network.RouteTable, err *retry.Error) {
fRTC.mutex.Lock()
defer fRTC.mutex.Unlock()
fRTC.Calls = append(fRTC.Calls, "Get")
if _, ok := fRTC.FakeStore[resourceGroupName]; ok {
if entity, ok := fRTC.FakeStore[resourceGroupName][routeTableName]; ok {
return entity, nil
}
}
return result, retry.GetError(
&http.Response{
StatusCode: http.StatusNotFound,
},
errors.New("Not such RouteTable"))
}
type fakeFileClient struct { type fakeFileClient struct {
} }
@ -925,82 +757,8 @@ func (fDC *fakeDisksClient) Get(ctx context.Context, resourceGroupName string, d
errors.New("Not such Disk")) errors.New("Not such Disk"))
} }
type fakeVMSet struct {
NodeToIP map[string]string
Err error
}
func (f *fakeVMSet) GetInstanceIDByNodeName(name string) (string, error) {
return "", fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetInstanceTypeByNodeName(name string) (string, error) {
return "", fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetPrivateIPsByNodeName(nodeName string) ([]string, error) {
return []string{}, fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetIPByNodeName(name string) (string, string, error) {
ip, found := f.NodeToIP[name]
if !found {
return "", "", fmt.Errorf("not found")
}
return ip, "", nil
}
func (f *fakeVMSet) GetPrimaryInterface(nodeName string) (network.Interface, error) {
return network.Interface{}, fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetNodeNameByProviderID(providerID string) (types.NodeName, error) {
return types.NodeName(""), fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
return cloudprovider.Zone{}, fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetPrimaryVMSetName() string {
return ""
}
func (f *fakeVMSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (availabilitySetNames *[]string, err error) {
return nil, fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) EnsureHostsInPool(service *v1.Service, nodes []*v1.Node, backendPoolID string, vmSetName string, isInternal bool) error {
return fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeName, backendPoolID string, vmSetName string, isInternal bool) error {
return fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error {
return fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string, writeAcceleratorEnabled bool) error {
return fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) DetachDisk(diskName, diskURI string, nodeName types.NodeName) error {
return fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]compute.DataDisk, error) {
return nil, fmt.Errorf("unimplemented")
}
func (f *fakeVMSet) GetPowerStatusByNodeName(name string) (string, error) {
return "", fmt.Errorf("unimplemented")
}
// GetTestCloud returns a fake azure cloud for unit tests in Azure related CSI drivers // GetTestCloud returns a fake azure cloud for unit tests in Azure related CSI drivers
func GetTestCloud() (az *Cloud) { func GetTestCloud(ctrl *gomock.Controller) (az *Cloud) {
az = &Cloud{ az = &Cloud{
Config: Config{ Config: Config{
AzureAuthConfig: auth.AzureAuthConfig{ AzureAuthConfig: auth.AzureAuthConfig{
@ -1031,10 +789,10 @@ func GetTestCloud() (az *Cloud) {
az.InterfacesClient = newFakeAzureInterfacesClient() az.InterfacesClient = newFakeAzureInterfacesClient()
az.LoadBalancerClient = newFakeAzureLBClient() az.LoadBalancerClient = newFakeAzureLBClient()
az.PublicIPAddressesClient = newFakeAzurePIPClient(az.Config.SubscriptionID) az.PublicIPAddressesClient = newFakeAzurePIPClient(az.Config.SubscriptionID)
az.RoutesClient = newFakeRoutesClient() az.RoutesClient = mockrouteclient.NewMockInterface(ctrl)
az.RouteTablesClient = newFakeRouteTablesClient() az.RouteTablesClient = mockroutetableclient.NewMockInterface(ctrl)
az.SecurityGroupsClient = newFakeAzureNSGClient() az.SecurityGroupsClient = newFakeAzureNSGClient()
az.SubnetsClient = newFakeAzureSubnetsClient() az.SubnetsClient = mocksubnetclient.NewMockInterface(ctrl)
az.VirtualMachineScaleSetsClient = newFakeVirtualMachineScaleSetsClient() az.VirtualMachineScaleSetsClient = newFakeVirtualMachineScaleSetsClient()
az.VirtualMachineScaleSetVMsClient = newFakeVirtualMachineScaleSetVMsClient() az.VirtualMachineScaleSetVMsClient = newFakeVirtualMachineScaleSetVMsClient()
az.VirtualMachinesClient = newFakeAzureVirtualMachinesClient() az.VirtualMachinesClient = newFakeAzureVirtualMachinesClient()

View File

@ -28,6 +28,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
@ -82,7 +83,10 @@ func setTestVirtualMachines(c *Cloud, vmList map[string]string, isDataDisksFull
} }
func TestInstanceID(t *testing.T) { func TestInstanceID(t *testing.T) {
cloud := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
cloud := GetTestCloud(ctrl)
cloud.Config.UseInstanceMetadata = true cloud.Config.UseInstanceMetadata = true
testcases := []struct { testcases := []struct {
@ -214,8 +218,10 @@ func TestInstanceShutdownByProviderID(t *testing.T) {
}, },
} }
ctrl := gomock.NewController(t)
defer ctrl.Finish()
for _, test := range testcases { for _, test := range testcases {
cloud := GetTestCloud() cloud := GetTestCloud(ctrl)
setTestVirtualMachines(cloud, test.vmList, false) setTestVirtualMachines(cloud, test.vmList, false)
providerID := "azure://" + cloud.getStandardMachineID("subscription", "rg", test.nodeName) providerID := "azure://" + cloud.getStandardMachineID("subscription", "rg", test.nodeName)
hasShutdown, err := cloud.InstanceShutdownByProviderID(context.Background(), providerID) hasShutdown, err := cloud.InstanceShutdownByProviderID(context.Background(), providerID)
@ -236,7 +242,9 @@ func TestInstanceShutdownByProviderID(t *testing.T) {
} }
func TestNodeAddresses(t *testing.T) { func TestNodeAddresses(t *testing.T) {
cloud := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
cloud := GetTestCloud(ctrl)
cloud.Config.UseInstanceMetadata = true cloud.Config.UseInstanceMetadata = true
metadataTemplate := `{"compute":{"name":"%s"},"network":{"interface":[{"ipv4":{"ipAddress":[{"privateIpAddress":"%s","publicIpAddress":"%s"}]},"ipv6":{"ipAddress":[{"privateIpAddress":"%s","publicIpAddress":"%s"}]}}]}}` metadataTemplate := `{"compute":{"name":"%s"},"network":{"interface":[{"ipv4":{"ipAddress":[{"privateIpAddress":"%s","publicIpAddress":"%s"}]},"ipv6":{"ipAddress":[{"privateIpAddress":"%s","publicIpAddress":"%s"}]}}]}}`

View File

@ -29,10 +29,12 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient"
) )
func TestFindProbe(t *testing.T) { func TestFindProbe(t *testing.T) {
@ -378,12 +380,14 @@ func TestEnsureLoadBalancerDeleted(t *testing.T) {
}, },
} }
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
for i, c := range tests { for i, c := range tests {
clusterResources := getClusterResources(az, vmCount, availabilitySetCount) clusterResources := getClusterResources(az, vmCount, availabilitySetCount)
getTestSecurityGroup(az) getTestSecurityGroup(az)
if c.service.Annotations[ServiceAnnotationLoadBalancerInternal] == "true" { if c.service.Annotations[ServiceAnnotationLoadBalancerInternal] == "true" {
addTestSubnet(t, az, &c.service) validateTestSubnet(t, az, &c.service)
} }
// create the service first. // create the service first.
@ -488,7 +492,9 @@ func TestServiceOwnsPublicIP(t *testing.T) {
} }
func TestGetPublicIPAddressResourceGroup(t *testing.T) { func TestGetPublicIPAddressResourceGroup(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
for i, c := range []struct { for i, c := range []struct {
desc string desc string
@ -692,8 +698,10 @@ func TestGetServiceLoadBalancer(t *testing.T) {
}, },
} }
ctrl := gomock.NewController(t)
defer ctrl.Finish()
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 3, 3) clusterResources := getClusterResources(az, 3, 3)
for _, existingLB := range test.existingLBs { for _, existingLB := range test.existingLBs {
@ -714,6 +722,9 @@ func TestGetServiceLoadBalancer(t *testing.T) {
} }
func TestIsFrontendIPChanged(t *testing.T) { func TestIsFrontendIPChanged(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
config network.FrontendIPConfiguration config network.FrontendIPConfiguration
@ -903,7 +914,10 @@ func TestIsFrontendIPChanged(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
mockSubnetsClient := az.SubnetsClient.(*mocksubnetclient.MockInterface)
mockSubnetsClient.EXPECT().Get(gomock.Any(), "rg", "vnet", "testSubnet", "").Return(test.exsistingSubnet, nil).AnyTimes()
mockSubnetsClient.EXPECT().CreateOrUpdate(gomock.Any(), "rg", "vnet", "testSubnet", test.exsistingSubnet).Return(nil)
err := az.SubnetsClient.CreateOrUpdate(context.TODO(), "rg", "vnet", "testSubnet", test.exsistingSubnet) err := az.SubnetsClient.CreateOrUpdate(context.TODO(), "rg", "vnet", "testSubnet", test.exsistingSubnet)
if err != nil { if err != nil {
t.Fatalf("TestCase[%d] meets unexpected error: %v", i, err) t.Fatalf("TestCase[%d] meets unexpected error: %v", i, err)
@ -924,6 +938,9 @@ func TestIsFrontendIPChanged(t *testing.T) {
} }
func TestDeterminePublicIPName(t *testing.T) { func TestDeterminePublicIPName(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
loadBalancerIP string loadBalancerIP string
@ -960,7 +977,7 @@ func TestDeterminePublicIPName(t *testing.T) {
}, },
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
service := getTestService("test1", v1.ProtocolTCP, nil, 80) service := getTestService("test1", v1.ProtocolTCP, nil, 80)
service.Spec.LoadBalancerIP = test.loadBalancerIP service.Spec.LoadBalancerIP = test.loadBalancerIP
for _, existingPIP := range test.exsistingPIPs { for _, existingPIP := range test.exsistingPIPs {
@ -976,6 +993,9 @@ func TestDeterminePublicIPName(t *testing.T) {
} }
func TestReconcileLoadBalancerRule(t *testing.T) { func TestReconcileLoadBalancerRule(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
service v1.Service service v1.Service
@ -1117,7 +1137,7 @@ func TestReconcileLoadBalancerRule(t *testing.T) {
}, },
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
az.Config.LoadBalancerSku = test.loadBalancerSku az.Config.LoadBalancerSku = test.loadBalancerSku
probe, lbrule, err := az.reconcileLoadBalancerRule(&test.service, test.wantLb, probe, lbrule, err := az.reconcileLoadBalancerRule(&test.service, test.wantLb,
"frontendIPConfigID", "backendPoolID", "lbname", to.Int32Ptr(0)) "frontendIPConfigID", "backendPoolID", "lbname", to.Int32Ptr(0))
@ -1191,6 +1211,9 @@ func getTestLoadBalancer(name, rgName, clusterName, identifier *string, service
} }
func TestReconcileLoadBalancer(t *testing.T) { func TestReconcileLoadBalancer(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
service1 := getTestService("test1", v1.ProtocolTCP, nil, 80) service1 := getTestService("test1", v1.ProtocolTCP, nil, 80)
basicLb1 := getTestLoadBalancer(to.StringPtr("lb1"), to.StringPtr("rg"), to.StringPtr("testCluster"), to.StringPtr("atest1"), service1, "Basic") basicLb1 := getTestLoadBalancer(to.StringPtr("lb1"), to.StringPtr("rg"), to.StringPtr("testCluster"), to.StringPtr("atest1"), service1, "Basic")
@ -1547,7 +1570,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
az.Config.LoadBalancerSku = test.loadBalancerSku az.Config.LoadBalancerSku = test.loadBalancerSku
az.DisableOutboundSNAT = test.disableOutboundSnat az.DisableOutboundSNAT = test.disableOutboundSnat
if test.preConfigLBType != "" { if test.preConfigLBType != "" {
@ -1583,7 +1606,10 @@ func TestReconcileLoadBalancer(t *testing.T) {
} }
func TestGetServiceLoadBalancerStatus(t *testing.T) { func TestGetServiceLoadBalancerStatus(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
service := getTestService("test1", v1.ProtocolTCP, nil, 80) service := getTestService("test1", v1.ProtocolTCP, nil, 80)
internalService := getInternalTestService("test1", 80) internalService := getInternalTestService("test1", 80)
@ -1721,6 +1747,9 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
} }
func TestReconcileSecurityGroup(t *testing.T) { func TestReconcileSecurityGroup(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
service v1.Service service v1.Service
@ -1804,7 +1833,7 @@ func TestReconcileSecurityGroup(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
for name, sg := range test.existingSgs { for name, sg := range test.existingSgs {
err := az.SecurityGroupsClient.CreateOrUpdate(context.TODO(), "rg", name, sg, "") err := az.SecurityGroupsClient.CreateOrUpdate(context.TODO(), "rg", name, sg, "")
if err != nil { if err != nil {
@ -1818,6 +1847,9 @@ func TestReconcileSecurityGroup(t *testing.T) {
} }
func TestSafeDeletePublicIP(t *testing.T) { func TestSafeDeletePublicIP(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
pip *network.PublicIPAddress pip *network.PublicIPAddress
@ -1852,7 +1884,7 @@ func TestSafeDeletePublicIP(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
err := az.PublicIPAddressesClient.CreateOrUpdate(context.TODO(), "rg", "pip1", network.PublicIPAddress{ err := az.PublicIPAddressesClient.CreateOrUpdate(context.TODO(), "rg", "pip1", network.PublicIPAddress{
Name: to.StringPtr("pip1"), Name: to.StringPtr("pip1"),
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{ PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
@ -1873,6 +1905,9 @@ func TestSafeDeletePublicIP(t *testing.T) {
} }
func TestReconcilePublicIP(t *testing.T) { func TestReconcilePublicIP(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
wantLb bool wantLb bool
@ -1971,7 +2006,7 @@ func TestReconcilePublicIP(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
service := getTestService("test1", v1.ProtocolTCP, nil, 80) service := getTestService("test1", v1.ProtocolTCP, nil, 80)
service.Annotations = test.annotations service.Annotations = test.annotations
for _, pip := range test.existingPIPs { for _, pip := range test.existingPIPs {
@ -1991,6 +2026,9 @@ func TestReconcilePublicIP(t *testing.T) {
} }
func TestEnsurePublicIPExists(t *testing.T) { func TestEnsurePublicIPExists(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
existingPIPs []network.PublicIPAddress existingPIPs []network.PublicIPAddress
@ -2082,7 +2120,7 @@ func TestEnsurePublicIPExists(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
service := getTestService("test1", v1.ProtocolTCP, nil, 80) service := getTestService("test1", v1.ProtocolTCP, nil, 80)
for _, pip := range test.existingPIPs { for _, pip := range test.existingPIPs {
err := az.PublicIPAddressesClient.CreateOrUpdate(context.TODO(), "rg", to.String(pip.Name), pip) err := az.PublicIPAddressesClient.CreateOrUpdate(context.TODO(), "rg", to.String(pip.Name), pip)
@ -2101,6 +2139,9 @@ func TestEnsurePublicIPExists(t *testing.T) {
} }
func TestShouldUpdateLoadBalancer(t *testing.T) { func TestShouldUpdateLoadBalancer(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
lbHasDeletionTimestamp bool lbHasDeletionTimestamp bool
@ -2134,7 +2175,7 @@ func TestShouldUpdateLoadBalancer(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
service := getTestService("test1", v1.ProtocolTCP, nil, 80) service := getTestService("test1", v1.ProtocolTCP, nil, 80)
if test.lbHasDeletionTimestamp { if test.lbHasDeletionTimestamp {
service.ObjectMeta.DeletionTimestamp = &metav1.Time{Time: time.Now()} service.ObjectMeta.DeletionTimestamp = &metav1.Time{Time: time.Now()}
@ -2164,6 +2205,9 @@ func TestShouldUpdateLoadBalancer(t *testing.T) {
} }
func TestIsBackendPoolPreConfigured(t *testing.T) { func TestIsBackendPoolPreConfigured(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
desc string desc string
preConfiguredBackendPoolLoadBalancerTypes string preConfiguredBackendPoolLoadBalancerTypes string
@ -2221,7 +2265,7 @@ func TestIsBackendPoolPreConfigured(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
az := GetTestCloud() az := GetTestCloud(ctrl)
az.Config.PreConfiguredBackendPoolLoadBalancerTypes = test.preConfiguredBackendPoolLoadBalancerTypes az.Config.PreConfiguredBackendPoolLoadBalancerTypes = test.preConfiguredBackendPoolLoadBalancerTypes
var service v1.Service var service v1.Service
if test.isInternalService { if test.isInternalService {

View File

@ -27,18 +27,23 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
cloudprovider "k8s.io/cloud-provider" cloudprovider "k8s.io/cloud-provider"
"k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient"
"k8s.io/legacy-cloud-providers/azure/mockvmsets"
) )
func TestDeleteRoute(t *testing.T) { func TestDeleteRoute(t *testing.T) {
fakeTable := newFakeRouteTablesClient() ctrl := gomock.NewController(t)
defer ctrl.Finish()
routeTableClient := mockroutetableclient.NewMockInterface(ctrl)
cloud := &Cloud{ cloud := &Cloud{
RouteTablesClient: fakeTable, RouteTablesClient: routeTableClient,
Config: Config{ Config: Config{
RouteTableResourceGroup: "foo", RouteTableResourceGroup: "foo",
RouteTableName: "bar", RouteTableName: "bar",
@ -67,30 +72,21 @@ func TestDeleteRoute(t *testing.T) {
}, },
}, },
} }
fakeTable.FakeStore = map[string]map[string]network.RouteTable{} routeTablesAfterDeletion := network.RouteTable{
fakeTable.FakeStore[cloud.RouteTableResourceGroup] = map[string]network.RouteTable{ Name: &cloud.RouteTableName,
cloud.RouteTableName: routeTables, Location: &cloud.Location,
RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{
Routes: &[]network.Route{},
},
} }
routeTableClient.EXPECT().Get(gomock.Any(), cloud.RouteTableResourceGroup, cloud.RouteTableName, "").Return(routeTables, nil)
routeTableClient.EXPECT().CreateOrUpdate(gomock.Any(), cloud.RouteTableResourceGroup, cloud.RouteTableName, routeTablesAfterDeletion, "").Return(nil)
err := cloud.DeleteRoute(context.TODO(), "cluster", &route) err := cloud.DeleteRoute(context.TODO(), "cluster", &route)
if err != nil { if err != nil {
t.Errorf("unexpected error deleting route: %v", err) t.Errorf("unexpected error deleting route: %v", err)
t.FailNow() t.FailNow()
} }
rt, found := fakeTable.FakeStore[cloud.RouteTableResourceGroup][cloud.RouteTableName]
if !found {
t.Errorf("unexpected missing routetable for %s", cloud.RouteTableName)
t.FailNow()
}
for _, r := range *rt.Routes {
if to.String(r.Name) == routeName {
t.Errorf("unexpectedly found: %v that should have been deleted.", routeName)
t.FailNow()
}
}
// test delete route for unmanaged nodes. // test delete route for unmanaged nodes.
nodeName := "node1" nodeName := "node1"
nodeCIDR := "4.3.2.1/24" nodeCIDR := "4.3.2.1/24"
@ -114,12 +110,14 @@ func TestDeleteRoute(t *testing.T) {
} }
func TestCreateRoute(t *testing.T) { func TestCreateRoute(t *testing.T) {
fakeTable := newFakeRouteTablesClient() ctrl := gomock.NewController(t)
fakeVM := &fakeVMSet{} defer ctrl.Finish()
routeTableClient := mockroutetableclient.NewMockInterface(ctrl)
mockVMSet := mockvmsets.NewMockVMSet(ctrl)
cloud := &Cloud{ cloud := &Cloud{
RouteTablesClient: fakeTable, RouteTablesClient: routeTableClient,
vmSet: fakeVM, vmSet: mockVMSet,
Config: Config{ Config: Config{
RouteTableResourceGroup: "foo", RouteTableResourceGroup: "foo",
RouteTableName: "bar", RouteTableName: "bar",
@ -133,69 +131,46 @@ func TestCreateRoute(t *testing.T) {
cloud.routeUpdater = newDelayedRouteUpdater(cloud, 100*time.Millisecond) cloud.routeUpdater = newDelayedRouteUpdater(cloud, 100*time.Millisecond)
go cloud.routeUpdater.run() go cloud.routeUpdater.run()
expectedTable := network.RouteTable{ currentTable := network.RouteTable{
Name: &cloud.RouteTableName, Name: &cloud.RouteTableName,
Location: &cloud.Location, Location: &cloud.Location,
RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{}, RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{},
} }
fakeTable.FakeStore = map[string]map[string]network.RouteTable{} updatedTable := network.RouteTable{
fakeTable.FakeStore[cloud.RouteTableResourceGroup] = map[string]network.RouteTable{ Name: &cloud.RouteTableName,
cloud.RouteTableName: expectedTable, Location: &cloud.Location,
RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{
Routes: &[]network.Route{
{
Name: to.StringPtr("node"),
RoutePropertiesFormat: &network.RoutePropertiesFormat{
AddressPrefix: to.StringPtr("1.2.3.4/24"),
NextHopIPAddress: to.StringPtr("2.4.6.8"),
NextHopType: network.RouteNextHopTypeVirtualAppliance,
},
},
},
},
} }
route := cloudprovider.Route{TargetNode: "node", DestinationCIDR: "1.2.3.4/24"} route := cloudprovider.Route{TargetNode: "node", DestinationCIDR: "1.2.3.4/24"}
nodeIP := "2.4.6.8" nodeIP := "2.4.6.8"
fakeVM.NodeToIP = map[string]string{
"node": nodeIP,
}
routeTableClient.EXPECT().Get(gomock.Any(), cloud.RouteTableResourceGroup, cloud.RouteTableName, "").Return(currentTable, nil)
routeTableClient.EXPECT().CreateOrUpdate(gomock.Any(), cloud.RouteTableResourceGroup, cloud.RouteTableName, updatedTable, "").Return(nil)
mockVMSet.EXPECT().GetIPByNodeName("node").Return(nodeIP, "", nil).AnyTimes()
err := cloud.CreateRoute(context.TODO(), "cluster", "unused", &route) err := cloud.CreateRoute(context.TODO(), "cluster", "unused", &route)
if err != nil { if err != nil {
t.Errorf("unexpected error create if not exists route table: %v", err) t.Errorf("unexpected error create if not exists route table: %v", err)
t.FailNow() t.FailNow()
} }
if len(fakeTable.Calls) != 2 {
t.Errorf("unexpected calls create if not exists, exists: %v", fakeTable.Calls)
}
routeName := mapNodeNameToRouteName(false, route.TargetNode, string(route.DestinationCIDR)) // test create again without real creation.
rt, found := fakeTable.FakeStore[cloud.RouteTableResourceGroup][cloud.RouteTableName] routeTableClient.EXPECT().Get(gomock.Any(), cloud.RouteTableResourceGroup, cloud.RouteTableName, "").Return(updatedTable, nil).Times(1)
if !found {
t.Errorf("unexpected missing routetable for %s", cloud.RouteTableName)
t.FailNow()
}
foundRoute := false
for _, r := range *rt.Routes {
if to.String(r.Name) == routeName {
foundRoute = true
if *r.AddressPrefix != route.DestinationCIDR {
t.Errorf("Expected cidr: %s, saw %s", *r.AddressPrefix, route.DestinationCIDR)
}
if r.NextHopType != network.RouteNextHopTypeVirtualAppliance {
t.Errorf("Expected next hop: %v, saw %v", network.RouteNextHopTypeVirtualAppliance, r.NextHopType)
}
if *r.NextHopIPAddress != nodeIP {
t.Errorf("Expected IP address: %s, saw %s", nodeIP, *r.NextHopIPAddress)
}
}
}
if !foundRoute {
t.Errorf("could not find route: %v in %v", routeName, fakeTable.FakeStore)
t.FailNow()
}
// test create again without real creation, clean fakeTable calls
fakeTable.Calls = []string{}
err = cloud.CreateRoute(context.TODO(), "cluster", "unused", &route) err = cloud.CreateRoute(context.TODO(), "cluster", "unused", &route)
if err != nil { if err != nil {
t.Errorf("unexpected error creating route: %v", err) t.Errorf("unexpected error creating route: %v", err)
t.FailNow() t.FailNow()
} }
if len(fakeTable.Calls) != 1 || fakeTable.Calls[0] != "Get" {
t.Errorf("unexpected route calls create if not exists, exists: %v", fakeTable.Calls)
}
// test create route for unmanaged nodes. // test create route for unmanaged nodes.
nodeName := "node1" nodeName := "node1"
@ -222,9 +197,12 @@ func TestCreateRoute(t *testing.T) {
} }
func TestCreateRouteTable(t *testing.T) { func TestCreateRouteTable(t *testing.T) {
fake := newFakeRouteTablesClient() ctrl := gomock.NewController(t)
defer ctrl.Finish()
routeTableClient := mockroutetableclient.NewMockInterface(ctrl)
cloud := &Cloud{ cloud := &Cloud{
RouteTablesClient: fake, RouteTablesClient: routeTableClient,
Config: Config{ Config: Config{
RouteTableResourceGroup: "foo", RouteTableResourceGroup: "foo",
RouteTableName: "bar", RouteTableName: "bar",
@ -235,23 +213,16 @@ func TestCreateRouteTable(t *testing.T) {
cloud.rtCache = cache cloud.rtCache = cache
expectedTable := network.RouteTable{ expectedTable := network.RouteTable{
Name: &cloud.RouteTableName, Name: &cloud.RouteTableName,
Location: &cloud.Location, Location: &cloud.Location,
RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{},
} }
routeTableClient.EXPECT().CreateOrUpdate(gomock.Any(), cloud.RouteTableResourceGroup, cloud.RouteTableName, expectedTable, "").Return(nil)
err := cloud.createRouteTable() err := cloud.createRouteTable()
if err != nil { if err != nil {
t.Errorf("unexpected error in creating route table: %v", err) t.Errorf("unexpected error in creating route table: %v", err)
t.FailNow() t.FailNow()
} }
table := fake.FakeStore["foo"]["bar"]
if *table.Location != *expectedTable.Location {
t.Errorf("mismatch: %s vs %s", *table.Location, *expectedTable.Location)
}
if *table.Name != *expectedTable.Name {
t.Errorf("mismatch: %s vs %s", *table.Name, *expectedTable.Name)
}
} }
func TestProcessRoutes(t *testing.T) { func TestProcessRoutes(t *testing.T) {

View File

@ -22,6 +22,7 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
@ -127,7 +128,9 @@ func TestGenerateStorageAccountName(t *testing.T) {
} }
func TestMapLoadBalancerNameToVMSet(t *testing.T) { func TestMapLoadBalancerNameToVMSet(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
az.PrimaryAvailabilitySetName = "primary" az.PrimaryAvailabilitySetName = "primary"
cases := []struct { cases := []struct {
@ -175,7 +178,9 @@ func TestMapLoadBalancerNameToVMSet(t *testing.T) {
} }
func TestGetAzureLoadBalancerName(t *testing.T) { func TestGetAzureLoadBalancerName(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
az.PrimaryAvailabilitySetName = "primary" az.PrimaryAvailabilitySetName = "primary"
cases := []struct { cases := []struct {
@ -256,7 +261,9 @@ func TestGetAzureLoadBalancerName(t *testing.T) {
} }
func TestGetLoadBalancingRuleName(t *testing.T) { func TestGetLoadBalancingRuleName(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
az.PrimaryAvailabilitySetName = "primary" az.PrimaryAvailabilitySetName = "primary"
svc := &v1.Service{ svc := &v1.Service{
@ -337,7 +344,9 @@ func TestGetLoadBalancingRuleName(t *testing.T) {
} }
func TestGetFrontendIPConfigName(t *testing.T) { func TestGetFrontendIPConfigName(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
az.PrimaryAvailabilitySetName = "primary" az.PrimaryAvailabilitySetName = "primary"
svc := &v1.Service{ svc := &v1.Service{

View File

@ -29,6 +29,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
@ -36,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
servicehelpers "k8s.io/cloud-provider/service/helpers" servicehelpers "k8s.io/cloud-provider/service/helpers"
"k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient"
"k8s.io/legacy-cloud-providers/azure/retry" "k8s.io/legacy-cloud-providers/azure/retry"
) )
@ -67,7 +69,10 @@ func TestFlipServiceInternalAnnotation(t *testing.T) {
// Test additional of a new service/port. // Test additional of a new service/port.
func TestAddPort(t *testing.T) { func TestAddPort(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -108,7 +113,10 @@ func TestLoadBalancerExternalServiceModeSelection(t *testing.T) {
} }
func testLoadBalancerServiceDefaultModeSelection(t *testing.T, isInternal bool) { func testLoadBalancerServiceDefaultModeSelection(t *testing.T, isInternal bool) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
const vmCount = 8 const vmCount = 8
const availabilitySetCount = 4 const availabilitySetCount = 4
const serviceCount = 9 const serviceCount = 9
@ -121,7 +129,7 @@ func testLoadBalancerServiceDefaultModeSelection(t *testing.T, isInternal bool)
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -163,7 +171,10 @@ func testLoadBalancerServiceDefaultModeSelection(t *testing.T, isInternal bool)
// Validate even distribution of external services across load balancers // Validate even distribution of external services across load balancers
// based on number of availability sets // based on number of availability sets
func testLoadBalancerServiceAutoModeSelection(t *testing.T, isInternal bool) { func testLoadBalancerServiceAutoModeSelection(t *testing.T, isInternal bool) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
const vmCount = 8 const vmCount = 8
const availabilitySetCount = 4 const availabilitySetCount = 4
const serviceCount = 9 const serviceCount = 9
@ -176,7 +187,7 @@ func testLoadBalancerServiceAutoModeSelection(t *testing.T, isInternal bool) {
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -224,7 +235,10 @@ func testLoadBalancerServiceAutoModeSelection(t *testing.T, isInternal bool) {
// services will be assigned load balancers that are part of the provided availability sets // services will be assigned load balancers that are part of the provided availability sets
// specified in service annotation // specified in service annotation
func testLoadBalancerServicesSpecifiedSelection(t *testing.T, isInternal bool) { func testLoadBalancerServicesSpecifiedSelection(t *testing.T, isInternal bool) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
const vmCount = 8 const vmCount = 8
const availabilitySetCount = 4 const availabilitySetCount = 4
const serviceCount = 9 const serviceCount = 9
@ -239,7 +253,7 @@ func testLoadBalancerServicesSpecifiedSelection(t *testing.T, isInternal bool) {
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -267,7 +281,10 @@ func testLoadBalancerServicesSpecifiedSelection(t *testing.T, isInternal bool) {
} }
func testLoadBalancerMaxRulesServices(t *testing.T, isInternal bool) { func testLoadBalancerMaxRulesServices(t *testing.T, isInternal bool) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
const vmCount = 1 const vmCount = 1
const availabilitySetCount = 1 const availabilitySetCount = 1
@ -281,7 +298,7 @@ func testLoadBalancerMaxRulesServices(t *testing.T, isInternal bool) {
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -310,7 +327,7 @@ func testLoadBalancerMaxRulesServices(t *testing.T, isInternal bool) {
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -327,7 +344,10 @@ func testLoadBalancerMaxRulesServices(t *testing.T, isInternal bool) {
// Validate service deletion in lb auto selection mode // Validate service deletion in lb auto selection mode
func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal bool) { func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal bool) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
const vmCount = 8 const vmCount = 8
const availabilitySetCount = 4 const availabilitySetCount = 4
const serviceCount = 9 const serviceCount = 9
@ -340,7 +360,7 @@ func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal boo
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -359,7 +379,7 @@ func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal boo
var svc v1.Service var svc v1.Service
if isInternal { if isInternal {
svc = getInternalTestService(svcName, 8081) svc = getInternalTestService(svcName, 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
} else { } else {
svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081) svc = getTestService(svcName, v1.ProtocolTCP, nil, 8081)
} }
@ -385,10 +405,13 @@ func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal boo
// Test addition of a new service on an internal LB with a subnet. // Test addition of a new service on an internal LB with a subnet.
func TestReconcileLoadBalancerAddServiceOnInternalSubnet(t *testing.T) { func TestReconcileLoadBalancerAddServiceOnInternalSubnet(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc := getInternalTestService("servicea", 80) svc := getInternalTestService("svc1", 80)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */) lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
if err != nil { if err != nil {
@ -404,7 +427,10 @@ func TestReconcileLoadBalancerAddServiceOnInternalSubnet(t *testing.T) {
} }
func TestReconcileSecurityGroupFromAnyDestinationAddressPrefixToLoadBalancerIP(t *testing.T) { func TestReconcileSecurityGroupFromAnyDestinationAddressPrefixToLoadBalancerIP(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("serviceea", v1.ProtocolTCP, nil, 80) svc1 := getTestService("serviceea", v1.ProtocolTCP, nil, 80)
svc1.Spec.LoadBalancerIP = "192.168.0.0" svc1.Spec.LoadBalancerIP = "192.168.0.0"
getTestSecurityGroup(az) getTestSecurityGroup(az)
@ -421,7 +447,10 @@ func TestReconcileSecurityGroupFromAnyDestinationAddressPrefixToLoadBalancerIP(t
} }
func TestReconcileSecurityGroupDynamicLoadBalancerIP(t *testing.T) { func TestReconcileSecurityGroupDynamicLoadBalancerIP(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicea", v1.ProtocolTCP, nil, 80) svc1 := getTestService("servicea", v1.ProtocolTCP, nil, 80)
svc1.Spec.LoadBalancerIP = "" svc1.Spec.LoadBalancerIP = ""
getTestSecurityGroup(az) getTestSecurityGroup(az)
@ -435,14 +464,14 @@ func TestReconcileSecurityGroupDynamicLoadBalancerIP(t *testing.T) {
// Test addition of services on an internal LB using both default and explicit subnets. // Test addition of services on an internal LB using both default and explicit subnets.
func TestReconcileLoadBalancerAddServicesOnMultipleSubnets(t *testing.T) { func TestReconcileLoadBalancerAddServicesOnMultipleSubnets(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc1 := getTestService("service1", v1.ProtocolTCP, nil, 8081) svc1 := getTestService("service1", v1.ProtocolTCP, nil, 8081)
svc2 := getInternalTestService("service2", 8081) svc2 := getInternalTestService("service2", 8081)
// Internal and External service cannot reside on the same LB resource
addTestSubnet(t, az, &svc2)
// svc1 is using LB without "-internal" suffix // svc1 is using LB without "-internal" suffix
lb, err := az.reconcileLoadBalancer(testClusterName, &svc1, clusterResources.nodes, true /* wantLb */) lb, err := az.reconcileLoadBalancer(testClusterName, &svc1, clusterResources.nodes, true /* wantLb */)
if err != nil { if err != nil {
@ -456,6 +485,9 @@ func TestReconcileLoadBalancerAddServicesOnMultipleSubnets(t *testing.T) {
validateLoadBalancer(t, lb, svc1) validateLoadBalancer(t, lb, svc1)
// Internal and External service cannot reside on the same LB resource
validateTestSubnet(t, az, &svc2)
// svc2 is using LB with "-internal" suffix // svc2 is using LB with "-internal" suffix
lb, err = az.reconcileLoadBalancer(testClusterName, &svc2, nil, true /* wantLb */) lb, err = az.reconcileLoadBalancer(testClusterName, &svc2, nil, true /* wantLb */)
if err != nil { if err != nil {
@ -472,10 +504,13 @@ func TestReconcileLoadBalancerAddServicesOnMultipleSubnets(t *testing.T) {
// Test moving a service exposure from one subnet to another. // Test moving a service exposure from one subnet to another.
func TestReconcileLoadBalancerEditServiceSubnet(t *testing.T) { func TestReconcileLoadBalancerEditServiceSubnet(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc := getInternalTestService("service1", 8081) svc := getInternalTestService("service1", 8081)
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */) lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
if err != nil { if err != nil {
@ -485,7 +520,7 @@ func TestReconcileLoadBalancerEditServiceSubnet(t *testing.T) {
validateLoadBalancer(t, lb, svc) validateLoadBalancer(t, lb, svc)
svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = "NewSubnet" svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = "NewSubnet"
addTestSubnet(t, az, &svc) validateTestSubnet(t, az, &svc)
lb, err = az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */) lb, err = az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
if err != nil { if err != nil {
@ -501,7 +536,10 @@ func TestReconcileLoadBalancerEditServiceSubnet(t *testing.T) {
} }
func TestReconcileLoadBalancerNodeHealth(t *testing.T) { func TestReconcileLoadBalancerNodeHealth(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80)
svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeLocal svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeLocal
@ -522,7 +560,10 @@ func TestReconcileLoadBalancerNodeHealth(t *testing.T) {
// Test removing all services results in removing the frontend ip configuration // Test removing all services results in removing the frontend ip configuration
func TestReconcileLoadBalancerRemoveService(t *testing.T) { func TestReconcileLoadBalancerRemoveService(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
@ -546,7 +587,10 @@ func TestReconcileLoadBalancerRemoveService(t *testing.T) {
// Test removing all service ports results in removing the frontend ip configuration // Test removing all service ports results in removing the frontend ip configuration
func TestReconcileLoadBalancerRemoveAllPortsRemovesFrontendConfig(t *testing.T) { func TestReconcileLoadBalancerRemoveAllPortsRemovesFrontendConfig(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80)
@ -572,7 +616,10 @@ func TestReconcileLoadBalancerRemoveAllPortsRemovesFrontendConfig(t *testing.T)
// Test removal of a port from an existing service. // Test removal of a port from an existing service.
func TestReconcileLoadBalancerRemovesPort(t *testing.T) { func TestReconcileLoadBalancerRemovesPort(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
@ -592,7 +639,10 @@ func TestReconcileLoadBalancerRemovesPort(t *testing.T) {
// Test reconciliation of multiple services on same port // Test reconciliation of multiple services on same port
func TestReconcileLoadBalancerMultipleServices(t *testing.T) { func TestReconcileLoadBalancerMultipleServices(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
svc1 := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc1 := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
svc2 := getTestService("serviceb", v1.ProtocolTCP, nil, 80) svc2 := getTestService("serviceb", v1.ProtocolTCP, nil, 80)
@ -620,7 +670,10 @@ func findLBRuleForPort(lbRules []network.LoadBalancingRule, port int32) (network
} }
func TestServiceDefaultsToNoSessionPersistence(t *testing.T) { func TestServiceDefaultsToNoSessionPersistence(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("service-sa-omitted", v1.ProtocolTCP, nil, 7170) svc := getTestService("service-sa-omitted", v1.ProtocolTCP, nil, 7170)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -640,7 +693,10 @@ func TestServiceDefaultsToNoSessionPersistence(t *testing.T) {
} }
func TestServiceRespectsNoSessionAffinity(t *testing.T) { func TestServiceRespectsNoSessionAffinity(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("service-sa-none", v1.ProtocolTCP, nil, 7170) svc := getTestService("service-sa-none", v1.ProtocolTCP, nil, 7170)
svc.Spec.SessionAffinity = v1.ServiceAffinityNone svc.Spec.SessionAffinity = v1.ServiceAffinityNone
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -663,7 +719,10 @@ func TestServiceRespectsNoSessionAffinity(t *testing.T) {
} }
func TestServiceRespectsClientIPSessionAffinity(t *testing.T) { func TestServiceRespectsClientIPSessionAffinity(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("service-sa-clientip", v1.ProtocolTCP, nil, 7170) svc := getTestService("service-sa-clientip", v1.ProtocolTCP, nil, 7170)
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -686,7 +745,10 @@ func TestServiceRespectsClientIPSessionAffinity(t *testing.T) {
} }
func TestReconcileSecurityGroupNewServiceAddsPort(t *testing.T) { func TestReconcileSecurityGroupNewServiceAddsPort(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
getTestSecurityGroup(az) getTestSecurityGroup(az)
svc1 := getTestService("servicea", v1.ProtocolTCP, nil, 80) svc1 := getTestService("servicea", v1.ProtocolTCP, nil, 80)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -702,10 +764,13 @@ func TestReconcileSecurityGroupNewServiceAddsPort(t *testing.T) {
} }
func TestReconcileSecurityGroupNewInternalServiceAddsPort(t *testing.T) { func TestReconcileSecurityGroupNewInternalServiceAddsPort(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
getTestSecurityGroup(az) getTestSecurityGroup(az)
svc1 := getInternalTestService("serviceea", 80) svc1 := getInternalTestService("serviceea", 80)
addTestSubnet(t, az, &svc1) validateTestSubnet(t, az, &svc1)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
lb, _ := az.reconcileLoadBalancer(testClusterName, &svc1, clusterResources.nodes, true) lb, _ := az.reconcileLoadBalancer(testClusterName, &svc1, clusterResources.nodes, true)
@ -719,7 +784,10 @@ func TestReconcileSecurityGroupNewInternalServiceAddsPort(t *testing.T) {
} }
func TestReconcileSecurityGroupRemoveService(t *testing.T) { func TestReconcileSecurityGroupRemoveService(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
service1 := getTestService("servicea", v1.ProtocolTCP, nil, 81) service1 := getTestService("servicea", v1.ProtocolTCP, nil, 81)
service2 := getTestService("serviceb", v1.ProtocolTCP, nil, 82) service2 := getTestService("serviceb", v1.ProtocolTCP, nil, 82)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -741,7 +809,10 @@ func TestReconcileSecurityGroupRemoveService(t *testing.T) {
} }
func TestReconcileSecurityGroupRemoveServiceRemovesPort(t *testing.T) { func TestReconcileSecurityGroupRemoveServiceRemovesPort(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
clusterResources := getClusterResources(az, 1, 1) clusterResources := getClusterResources(az, 1, 1)
@ -759,7 +830,10 @@ func TestReconcileSecurityGroupRemoveServiceRemovesPort(t *testing.T) {
} }
func TestReconcileSecurityWithSourceRanges(t *testing.T) { func TestReconcileSecurityWithSourceRanges(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
svc.Spec.LoadBalancerSourceRanges = []string{ svc.Spec.LoadBalancerSourceRanges = []string{
"192.168.0.0/24", "192.168.0.0/24",
@ -780,7 +854,9 @@ func TestReconcileSecurityWithSourceRanges(t *testing.T) {
} }
func TestReconcileSecurityGroupEtagMismatch(t *testing.T) { func TestReconcileSecurityGroupEtagMismatch(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
sg := getTestSecurityGroup(az) sg := getTestSecurityGroup(az)
cachedSG := *sg cachedSG := *sg
@ -802,8 +878,11 @@ func TestReconcileSecurityGroupEtagMismatch(t *testing.T) {
assert.Equal(t, expectedError.Error(), err) assert.Equal(t, expectedError.Error(), err)
} }
func TestReconcilePublicIPWithNewService(t *testing.T) { func TestReconcilePuablicIPWithNewService(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/) pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/)
@ -824,7 +903,10 @@ func TestReconcilePublicIPWithNewService(t *testing.T) {
} }
func TestReconcilePublicIPRemoveService(t *testing.T) { func TestReconcilePublicIPRemoveService(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443) svc := getTestService("servicea", v1.ProtocolTCP, nil, 80, 443)
pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/) pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/)
@ -844,7 +926,10 @@ func TestReconcilePublicIPRemoveService(t *testing.T) {
} }
func TestReconcilePublicIPWithInternalService(t *testing.T) { func TestReconcilePublicIPWithInternalService(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getInternalTestService("servicea", 80, 443) svc := getInternalTestService("servicea", 80, 443)
pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/) pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/)
@ -856,7 +941,10 @@ func TestReconcilePublicIPWithInternalService(t *testing.T) {
} }
func TestReconcilePublicIPWithExternalAndInternalSwitch(t *testing.T) { func TestReconcilePublicIPWithExternalAndInternalSwitch(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getInternalTestService("servicea", 80, 443) svc := getInternalTestService("servicea", 80, 443)
pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/) pip, err := az.reconcilePublicIP(testClusterName, &svc, "", true /* wantLb*/)
@ -1109,7 +1197,10 @@ func getTestSecurityGroup(az *Cloud, services ...v1.Service) *network.SecurityGr
} }
func validateLoadBalancer(t *testing.T, loadBalancer *network.LoadBalancer, services ...v1.Service) { func validateLoadBalancer(t *testing.T, loadBalancer *network.LoadBalancer, services ...v1.Service) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
expectedRuleCount := 0 expectedRuleCount := 0
expectedFrontendIPCount := 0 expectedFrontendIPCount := 0
expectedProbeCount := 0 expectedProbeCount := 0
@ -1117,9 +1208,16 @@ func validateLoadBalancer(t *testing.T, loadBalancer *network.LoadBalancer, serv
for _, svc := range services { for _, svc := range services {
if len(svc.Spec.Ports) > 0 { if len(svc.Spec.Ports) > 0 {
expectedFrontendIPCount++ expectedFrontendIPCount++
expectedSubnetName := ""
if requiresInternalLoadBalancer(&svc) {
expectedSubnetName = svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet]
if expectedSubnetName == "" {
expectedSubnetName = az.SubnetName
}
}
expectedFrontendIP := ExpectedFrontendIPInfo{ expectedFrontendIP := ExpectedFrontendIPInfo{
Name: az.getFrontendIPConfigName(&svc), Name: az.getFrontendIPConfigName(&svc),
Subnet: subnet(&svc), Subnet: to.StringPtr(expectedSubnetName),
} }
expectedFrontendIPs = append(expectedFrontendIPs, expectedFrontendIP) expectedFrontendIPs = append(expectedFrontendIPs, expectedFrontendIP)
} }
@ -1325,7 +1423,10 @@ func securityRuleMatches(serviceSourceRange string, servicePort v1.ServicePort,
} }
func validateSecurityGroup(t *testing.T, securityGroup *network.SecurityGroup, services ...v1.Service) { func validateSecurityGroup(t *testing.T, securityGroup *network.SecurityGroup, services ...v1.Service) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
seenRules := make(map[string]string) seenRules := make(map[string]string)
for _, svc := range services { for _, svc := range services {
for _, wantedRule := range svc.Spec.Ports { for _, wantedRule := range svc.Spec.Ports {
@ -1652,7 +1753,10 @@ func validateEmptyConfig(t *testing.T, config string) {
} }
func TestGetNodeNameByProviderID(t *testing.T) { func TestGetNodeNameByProviderID(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
providers := []struct { providers := []struct {
providerID string providerID string
name types.NodeName name types.NodeName
@ -1703,37 +1807,33 @@ func TestGetNodeNameByProviderID(t *testing.T) {
} }
} }
func addTestSubnet(t *testing.T, az *Cloud, svc *v1.Service) { func validateTestSubnet(t *testing.T, az *Cloud, svc *v1.Service) {
if svc.Annotations[ServiceAnnotationLoadBalancerInternal] != "true" { if svc.Annotations[ServiceAnnotationLoadBalancerInternal] != "true" {
t.Error("Subnet added to non-internal service") t.Error("Subnet added to non-internal service")
} }
subName := svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] subName := svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet]
if subName == "" { if subName == "" {
subName = az.SubnetName subName = az.SubnetName
} }
subnetID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", subnetID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s",
az.SubscriptionID, az.SubscriptionID,
az.VnetResourceGroup, az.VnetResourceGroup,
az.VnetName, az.VnetName,
subName) subName)
mockSubnetsClient := az.SubnetsClient.(*mocksubnetclient.MockInterface)
ctx, cancel := getContextWithCancel() mockSubnetsClient.EXPECT().Get(gomock.Any(), az.VnetResourceGroup, az.VnetName, subName, "").Return(
defer cancel()
err := az.SubnetsClient.CreateOrUpdate(ctx, az.VnetResourceGroup, az.VnetName, subName,
network.Subnet{ network.Subnet{
ID: &subnetID, ID: &subnetID,
Name: &subName, Name: &subName,
}) }, nil).AnyTimes()
if err != nil {
t.Errorf("Subnet cannot be created or update, %v", err)
}
svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = subName
} }
func TestIfServiceSpecifiesSharedRuleAndRuleDoesNotExistItIsCreated(t *testing.T) { func TestIfServiceSpecifiesSharedRuleAndRuleDoesNotExistItIsCreated(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicesr", v1.ProtocolTCP, nil, 80) svc := getTestService("servicesr", v1.ProtocolTCP, nil, 80)
svc.Spec.LoadBalancerIP = "192.168.77.88" svc.Spec.LoadBalancerIP = "192.168.77.88"
svc.Annotations[ServiceAnnotationSharedSecurityRule] = "true" svc.Annotations[ServiceAnnotationSharedSecurityRule] = "true"
@ -1772,7 +1872,10 @@ func TestIfServiceSpecifiesSharedRuleAndRuleDoesNotExistItIsCreated(t *testing.T
} }
func TestIfServiceSpecifiesSharedRuleAndRuleExistsThenTheServicesPortAndAddressAreAdded(t *testing.T) { func TestIfServiceSpecifiesSharedRuleAndRuleExistsThenTheServicesPortAndAddressAreAdded(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc := getTestService("servicesr", v1.ProtocolTCP, nil, 80) svc := getTestService("servicesr", v1.ProtocolTCP, nil, 80)
svc.Spec.LoadBalancerIP = "192.168.77.88" svc.Spec.LoadBalancerIP = "192.168.77.88"
svc.Annotations[ServiceAnnotationSharedSecurityRule] = "true" svc.Annotations[ServiceAnnotationSharedSecurityRule] = "true"
@ -1824,7 +1927,9 @@ func TestIfServiceSpecifiesSharedRuleAndRuleExistsThenTheServicesPortAndAddressA
} }
func TestIfServicesSpecifySharedRuleButDifferentPortsThenSeparateRulesAreCreated(t *testing.T) { func TestIfServicesSpecifySharedRuleButDifferentPortsThenSeparateRulesAreCreated(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -1893,7 +1998,9 @@ func TestIfServicesSpecifySharedRuleButDifferentPortsThenSeparateRulesAreCreated
} }
func TestIfServicesSpecifySharedRuleButDifferentProtocolsThenSeparateRulesAreCreated(t *testing.T) { func TestIfServicesSpecifySharedRuleButDifferentProtocolsThenSeparateRulesAreCreated(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -1960,7 +2067,9 @@ func TestIfServicesSpecifySharedRuleButDifferentProtocolsThenSeparateRulesAreCre
} }
func TestIfServicesSpecifySharedRuleButDifferentSourceAddressesThenSeparateRulesAreCreated(t *testing.T) { func TestIfServicesSpecifySharedRuleButDifferentSourceAddressesThenSeparateRulesAreCreated(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 80) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 80)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -2031,7 +2140,9 @@ func TestIfServicesSpecifySharedRuleButDifferentSourceAddressesThenSeparateRules
} }
func TestIfServicesSpecifySharedRuleButSomeAreOnDifferentPortsThenRulesAreSeparatedOrConsoliatedByPort(t *testing.T) { func TestIfServicesSpecifySharedRuleButSomeAreOnDifferentPortsThenRulesAreSeparatedOrConsoliatedByPort(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -2131,7 +2242,9 @@ func TestIfServicesSpecifySharedRuleButSomeAreOnDifferentPortsThenRulesAreSepara
} }
func TestIfServiceSpecifiesSharedRuleAndServiceIsDeletedThenTheServicesPortAndAddressAreRemoved(t *testing.T) { func TestIfServiceSpecifiesSharedRuleAndServiceIsDeletedThenTheServicesPortAndAddressAreRemoved(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 80) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 80)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -2186,7 +2299,9 @@ func TestIfServiceSpecifiesSharedRuleAndServiceIsDeletedThenTheServicesPortAndAd
} }
func TestIfSomeServicesShareARuleAndOneIsDeletedItIsRemovedFromTheRightRule(t *testing.T) { func TestIfSomeServicesShareARuleAndOneIsDeletedItIsRemovedFromTheRightRule(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -2293,7 +2408,9 @@ func TestIfSomeServicesShareARuleAndOneIsDeletedItIsRemovedFromTheRightRule(t *t
} }
func TestIfServiceSpecifiesSharedRuleAndLastServiceIsDeletedThenRuleIsDeleted(t *testing.T) { func TestIfServiceSpecifiesSharedRuleAndLastServiceIsDeletedThenRuleIsDeleted(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -2373,7 +2490,9 @@ func TestIfServiceSpecifiesSharedRuleAndLastServiceIsDeletedThenRuleIsDeleted(t
} }
func TestCanCombineSharedAndPrivateRulesInSameGroup(t *testing.T) { func TestCanCombineSharedAndPrivateRulesInSameGroup(t *testing.T) {
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444) svc1 := getTestService("servicesr1", v1.ProtocolTCP, nil, 4444)
svc1.Spec.LoadBalancerIP = "192.168.77.88" svc1.Spec.LoadBalancerIP = "192.168.77.88"
@ -2630,7 +2749,9 @@ func TestGetResourceGroups(t *testing.T) {
}, },
} }
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
for _, test := range tests { for _, test := range tests {
az.nodeResourceGroups = test.nodeResourceGroups az.nodeResourceGroups = test.nodeResourceGroups
if test.informerSynced { if test.informerSynced {
@ -2680,7 +2801,9 @@ func TestGetNodeResourceGroup(t *testing.T) {
}, },
} }
az := GetTestCloud() ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)
for _, test := range tests { for _, test := range tests {
az.nodeResourceGroups = test.nodeResourceGroups az.nodeResourceGroups = test.nodeResourceGroups
if test.informerSynced { if test.informerSynced {

View File

@ -30,6 +30,8 @@ import (
// VMSet defines functions all vmsets (including scale set and availability // VMSet defines functions all vmsets (including scale set and availability
// set) should be implemented. // set) should be implemented.
// Don't forget to run the following command to generate the mock client:
// mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmsets.go -package=mockvmsets VMSet > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/mockvmsets/azure_mock_vmsets.go
type VMSet interface { type VMSet interface {
// GetInstanceIDByNodeName gets the cloud provider ID by node name. // GetInstanceIDByNodeName gets the cloud provider ID by node name.
// It must return ("", cloudprovider.InstanceNotFound) if the instance does // It must return ("", cloudprovider.InstanceNotFound) if the instance does

View File

@ -25,6 +25,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
cloudprovider "k8s.io/cloud-provider" cloudprovider "k8s.io/cloud-provider"
azcache "k8s.io/legacy-cloud-providers/azure/cache" azcache "k8s.io/legacy-cloud-providers/azure/cache"
@ -75,9 +76,12 @@ func TestExtractVmssVMName(t *testing.T) {
} }
func TestVMSSVMCache(t *testing.T) { func TestVMSSVMCache(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
vmssName := "vmss" vmssName := "vmss"
vmList := []string{"vmssee6c2000000", "vmssee6c2000001", "vmssee6c2000002"} vmList := []string{"vmssee6c2000000", "vmssee6c2000001", "vmssee6c2000002"}
ss, err := newTestScaleSet(vmssName, "", 0, vmList) ss, err := newTestScaleSet(ctrl, vmssName, "", 0, vmList)
assert.NoError(t, err) assert.NoError(t, err)
// validate getting VMSS VM via cache. // validate getting VMSS VM via cache.
@ -117,9 +121,12 @@ func TestVMSSVMCache(t *testing.T) {
} }
func TestVMSSVMCacheWithDeletingNodes(t *testing.T) { func TestVMSSVMCacheWithDeletingNodes(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
vmssName := "vmss" vmssName := "vmss"
vmList := []string{"vmssee6c2000000", "vmssee6c2000001", "vmssee6c2000002"} vmList := []string{"vmssee6c2000000", "vmssee6c2000001", "vmssee6c2000002"}
ss, err := newTestScaleSetWithState(vmssName, "", 0, vmList, "Deleting") ss, err := newTestScaleSetWithState(ctrl, vmssName, "", 0, vmList, "Deleting")
assert.NoError(t, err) assert.NoError(t, err)
virtualMachines, rerr := ss.VirtualMachineScaleSetVMsClient.List( virtualMachines, rerr := ss.VirtualMachineScaleSetVMsClient.List(

View File

@ -25,6 +25,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -33,12 +34,12 @@ const (
fakePublicIP = "10.10.10.10" fakePublicIP = "10.10.10.10"
) )
func newTestScaleSet(scaleSetName, zone string, faultDomain int32, vmList []string) (*scaleSet, error) { func newTestScaleSet(ctrl *gomock.Controller, scaleSetName, zone string, faultDomain int32, vmList []string) (*scaleSet, error) {
return newTestScaleSetWithState(scaleSetName, zone, faultDomain, vmList, "Running") return newTestScaleSetWithState(ctrl, scaleSetName, zone, faultDomain, vmList, "Running")
} }
func newTestScaleSetWithState(scaleSetName, zone string, faultDomain int32, vmList []string, state string) (*scaleSet, error) { func newTestScaleSetWithState(ctrl *gomock.Controller, scaleSetName, zone string, faultDomain int32, vmList []string, state string) (*scaleSet, error) {
cloud := GetTestCloud() cloud := GetTestCloud(ctrl)
setTestVirtualMachineCloud(cloud, scaleSetName, zone, faultDomain, vmList, state) setTestVirtualMachineCloud(cloud, scaleSetName, zone, faultDomain, vmList, state)
ss, err := newScaleSet(cloud) ss, err := newScaleSet(cloud)
if err != nil { if err != nil {
@ -194,6 +195,9 @@ func TestGetScaleSetVMInstanceID(t *testing.T) {
} }
func TestGetInstanceIDByNodeName(t *testing.T) { func TestGetInstanceIDByNodeName(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
description string description string
scaleSet string scaleSet string
@ -226,7 +230,7 @@ func TestGetInstanceIDByNodeName(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
ss, err := newTestScaleSet(test.scaleSet, "", 0, test.vmList) ss, err := newTestScaleSet(ctrl, test.scaleSet, "", 0, test.vmList)
assert.NoError(t, err, test.description) assert.NoError(t, err, test.description)
real, err := ss.GetInstanceIDByNodeName(test.nodeName) real, err := ss.GetInstanceIDByNodeName(test.nodeName)
@ -241,6 +245,9 @@ func TestGetInstanceIDByNodeName(t *testing.T) {
} }
func TestGetZoneByNodeName(t *testing.T) { func TestGetZoneByNodeName(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
description string description string
scaleSet string scaleSet string
@ -279,7 +286,7 @@ func TestGetZoneByNodeName(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
ss, err := newTestScaleSet(test.scaleSet, test.zone, test.faultDomain, test.vmList) ss, err := newTestScaleSet(ctrl, test.scaleSet, test.zone, test.faultDomain, test.vmList)
assert.NoError(t, err, test.description) assert.NoError(t, err, test.description)
real, err := ss.GetZoneByNodeName(test.nodeName) real, err := ss.GetZoneByNodeName(test.nodeName)
@ -294,6 +301,9 @@ func TestGetZoneByNodeName(t *testing.T) {
} }
func TestGetIPByNodeName(t *testing.T) { func TestGetIPByNodeName(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
testCases := []struct { testCases := []struct {
description string description string
scaleSet string scaleSet string
@ -319,7 +329,7 @@ func TestGetIPByNodeName(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
ss, err := newTestScaleSet(test.scaleSet, "", 0, test.vmList) ss, err := newTestScaleSet(ctrl, test.scaleSet, "", 0, test.vmList)
assert.NoError(t, err, test.description) assert.NoError(t, err, test.description)
privateIP, publicIP, err := ss.GetIPByNodeName(test.nodeName) privateIP, publicIP, err := ss.GetIPByNodeName(test.nodeName)
@ -334,6 +344,9 @@ func TestGetIPByNodeName(t *testing.T) {
} }
func TestGetNodeNameByIPConfigurationID(t *testing.T) { func TestGetNodeNameByIPConfigurationID(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
ipConfigurationIDTemplate := "/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s/networkInterfaces/%s/ipConfigurations/ipconfig1" ipConfigurationIDTemplate := "/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s/networkInterfaces/%s/ipConfigurations/ipconfig1"
testCases := []struct { testCases := []struct {
@ -368,7 +381,7 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
ss, err := newTestScaleSet(test.scaleSet, "", 0, test.vmList) ss, err := newTestScaleSet(ctrl, test.scaleSet, "", 0, test.vmList)
assert.NoError(t, err, test.description) assert.NoError(t, err, test.description)
nodeName, err := ss.getNodeNameByIPConfigurationID(test.ipConfigurationID) nodeName, err := ss.getNodeNameByIPConfigurationID(test.ipConfigurationID)

View File

@ -23,6 +23,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/legacy-cloud-providers/azure/retry" "k8s.io/legacy-cloud-providers/azure/retry"
@ -56,6 +57,9 @@ func TestExtractNotFound(t *testing.T) {
} }
func TestIsNodeUnmanaged(t *testing.T) { func TestIsNodeUnmanaged(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
tests := []struct { tests := []struct {
name string name string
unmanagedNodes sets.String unmanagedNodes sets.String
@ -89,7 +93,7 @@ func TestIsNodeUnmanaged(t *testing.T) {
}, },
} }
az := GetTestCloud() az := GetTestCloud(ctrl)
for _, test := range tests { for _, test := range tests {
az.unmanagedNodes = test.unmanagedNodes az.unmanagedNodes = test.unmanagedNodes
if test.expectErr { if test.expectErr {
@ -110,6 +114,9 @@ func TestIsNodeUnmanaged(t *testing.T) {
} }
func TestIsNodeUnmanagedByProviderID(t *testing.T) { func TestIsNodeUnmanagedByProviderID(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
tests := []struct { tests := []struct {
providerID string providerID string
expected bool expected bool
@ -137,7 +144,7 @@ func TestIsNodeUnmanagedByProviderID(t *testing.T) {
}, },
} }
az := GetTestCloud() az := GetTestCloud(ctrl)
for _, test := range tests { for _, test := range tests {
isUnmanagedNode := az.IsNodeUnmanagedByProviderID(test.providerID) isUnmanagedNode := az.IsNodeUnmanagedByProviderID(test.providerID)
assert.Equal(t, test.expected, isUnmanagedNode, test.providerID) assert.Equal(t, test.expected, isUnmanagedNode, test.providerID)

View File

@ -0,0 +1,35 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"azure_mock_vmsets.go",
"doc.go",
],
importmap = "k8s.io/kubernetes/vendor/k8s.io/legacy-cloud-providers/azure/mockvmsets",
importpath = "k8s.io/legacy-cloud-providers/azure/mockvmsets",
visibility = ["//visibility:public"],
deps = [
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/cloud-provider:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/cache:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,289 @@
// +build !providerless
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package mockvmsets
import (
reflect "reflect"
compute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
network "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
gomock "github.com/golang/mock/gomock"
v1 "k8s.io/api/core/v1"
types "k8s.io/apimachinery/pkg/types"
cloudprovider "k8s.io/cloud-provider"
cache "k8s.io/legacy-cloud-providers/azure/cache"
)
// MockVMSet is a mock of VMSet interface
type MockVMSet struct {
ctrl *gomock.Controller
recorder *MockVMSetMockRecorder
}
// MockVMSetMockRecorder is the mock recorder for MockVMSet
type MockVMSetMockRecorder struct {
mock *MockVMSet
}
// NewMockVMSet creates a new mock instance
func NewMockVMSet(ctrl *gomock.Controller) *MockVMSet {
mock := &MockVMSet{ctrl: ctrl}
mock.recorder = &MockVMSetMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockVMSet) EXPECT() *MockVMSetMockRecorder {
return m.recorder
}
// GetInstanceIDByNodeName mocks base method
func (m *MockVMSet) GetInstanceIDByNodeName(name string) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetInstanceIDByNodeName", name)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetInstanceIDByNodeName indicates an expected call of GetInstanceIDByNodeName
func (mr *MockVMSetMockRecorder) GetInstanceIDByNodeName(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInstanceIDByNodeName", reflect.TypeOf((*MockVMSet)(nil).GetInstanceIDByNodeName), name)
}
// GetInstanceTypeByNodeName mocks base method
func (m *MockVMSet) GetInstanceTypeByNodeName(name string) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetInstanceTypeByNodeName", name)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetInstanceTypeByNodeName indicates an expected call of GetInstanceTypeByNodeName
func (mr *MockVMSetMockRecorder) GetInstanceTypeByNodeName(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInstanceTypeByNodeName", reflect.TypeOf((*MockVMSet)(nil).GetInstanceTypeByNodeName), name)
}
// GetIPByNodeName mocks base method
func (m *MockVMSet) GetIPByNodeName(name string) (string, string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetIPByNodeName", name)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// GetIPByNodeName indicates an expected call of GetIPByNodeName
func (mr *MockVMSetMockRecorder) GetIPByNodeName(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIPByNodeName", reflect.TypeOf((*MockVMSet)(nil).GetIPByNodeName), name)
}
// GetPrimaryInterface mocks base method
func (m *MockVMSet) GetPrimaryInterface(nodeName string) (network.Interface, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPrimaryInterface", nodeName)
ret0, _ := ret[0].(network.Interface)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPrimaryInterface indicates an expected call of GetPrimaryInterface
func (mr *MockVMSetMockRecorder) GetPrimaryInterface(nodeName interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPrimaryInterface", reflect.TypeOf((*MockVMSet)(nil).GetPrimaryInterface), nodeName)
}
// GetNodeNameByProviderID mocks base method
func (m *MockVMSet) GetNodeNameByProviderID(providerID string) (types.NodeName, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetNodeNameByProviderID", providerID)
ret0, _ := ret[0].(types.NodeName)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetNodeNameByProviderID indicates an expected call of GetNodeNameByProviderID
func (mr *MockVMSetMockRecorder) GetNodeNameByProviderID(providerID interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNodeNameByProviderID", reflect.TypeOf((*MockVMSet)(nil).GetNodeNameByProviderID), providerID)
}
// GetZoneByNodeName mocks base method
func (m *MockVMSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetZoneByNodeName", name)
ret0, _ := ret[0].(cloudprovider.Zone)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetZoneByNodeName indicates an expected call of GetZoneByNodeName
func (mr *MockVMSetMockRecorder) GetZoneByNodeName(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetZoneByNodeName", reflect.TypeOf((*MockVMSet)(nil).GetZoneByNodeName), name)
}
// GetPrimaryVMSetName mocks base method
func (m *MockVMSet) GetPrimaryVMSetName() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPrimaryVMSetName")
ret0, _ := ret[0].(string)
return ret0
}
// GetPrimaryVMSetName indicates an expected call of GetPrimaryVMSetName
func (mr *MockVMSetMockRecorder) GetPrimaryVMSetName() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPrimaryVMSetName", reflect.TypeOf((*MockVMSet)(nil).GetPrimaryVMSetName))
}
// GetVMSetNames mocks base method
func (m *MockVMSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (*[]string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetVMSetNames", service, nodes)
ret0, _ := ret[0].(*[]string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetVMSetNames indicates an expected call of GetVMSetNames
func (mr *MockVMSetMockRecorder) GetVMSetNames(service, nodes interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVMSetNames", reflect.TypeOf((*MockVMSet)(nil).GetVMSetNames), service, nodes)
}
// EnsureHostsInPool mocks base method
func (m *MockVMSet) EnsureHostsInPool(service *v1.Service, nodes []*v1.Node, backendPoolID, vmSetName string, isInternal bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "EnsureHostsInPool", service, nodes, backendPoolID, vmSetName, isInternal)
ret0, _ := ret[0].(error)
return ret0
}
// EnsureHostsInPool indicates an expected call of EnsureHostsInPool
func (mr *MockVMSetMockRecorder) EnsureHostsInPool(service, nodes, backendPoolID, vmSetName, isInternal interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureHostsInPool", reflect.TypeOf((*MockVMSet)(nil).EnsureHostsInPool), service, nodes, backendPoolID, vmSetName, isInternal)
}
// EnsureHostInPool mocks base method
func (m *MockVMSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeName, backendPoolID, vmSetName string, isInternal bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "EnsureHostInPool", service, nodeName, backendPoolID, vmSetName, isInternal)
ret0, _ := ret[0].(error)
return ret0
}
// EnsureHostInPool indicates an expected call of EnsureHostInPool
func (mr *MockVMSetMockRecorder) EnsureHostInPool(service, nodeName, backendPoolID, vmSetName, isInternal interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureHostInPool", reflect.TypeOf((*MockVMSet)(nil).EnsureHostInPool), service, nodeName, backendPoolID, vmSetName, isInternal)
}
// EnsureBackendPoolDeleted mocks base method
func (m *MockVMSet) EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "EnsureBackendPoolDeleted", service, backendPoolID, vmSetName, backendAddressPools)
ret0, _ := ret[0].(error)
return ret0
}
// EnsureBackendPoolDeleted indicates an expected call of EnsureBackendPoolDeleted
func (mr *MockVMSetMockRecorder) EnsureBackendPoolDeleted(service, backendPoolID, vmSetName, backendAddressPools interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureBackendPoolDeleted", reflect.TypeOf((*MockVMSet)(nil).EnsureBackendPoolDeleted), service, backendPoolID, vmSetName, backendAddressPools)
}
// AttachDisk mocks base method
func (m *MockVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string, writeAcceleratorEnabled bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AttachDisk", isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID, writeAcceleratorEnabled)
ret0, _ := ret[0].(error)
return ret0
}
// AttachDisk indicates an expected call of AttachDisk
func (mr *MockVMSetMockRecorder) AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID, writeAcceleratorEnabled interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttachDisk", reflect.TypeOf((*MockVMSet)(nil).AttachDisk), isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID, writeAcceleratorEnabled)
}
// DetachDisk mocks base method
func (m *MockVMSet) DetachDisk(diskName, diskURI string, nodeName types.NodeName) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DetachDisk", diskName, diskURI, nodeName)
ret0, _ := ret[0].(error)
return ret0
}
// DetachDisk indicates an expected call of DetachDisk
func (mr *MockVMSetMockRecorder) DetachDisk(diskName, diskURI, nodeName interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DetachDisk", reflect.TypeOf((*MockVMSet)(nil).DetachDisk), diskName, diskURI, nodeName)
}
// GetDataDisks mocks base method
func (m *MockVMSet) GetDataDisks(nodeName types.NodeName, string cache.AzureCacheReadType) ([]compute.DataDisk, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetDataDisks", nodeName, string)
ret0, _ := ret[0].([]compute.DataDisk)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetDataDisks indicates an expected call of GetDataDisks
func (mr *MockVMSetMockRecorder) GetDataDisks(nodeName, string interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDataDisks", reflect.TypeOf((*MockVMSet)(nil).GetDataDisks), nodeName, string)
}
// GetPowerStatusByNodeName mocks base method
func (m *MockVMSet) GetPowerStatusByNodeName(name string) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPowerStatusByNodeName", name)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPowerStatusByNodeName indicates an expected call of GetPowerStatusByNodeName
func (mr *MockVMSetMockRecorder) GetPowerStatusByNodeName(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPowerStatusByNodeName", reflect.TypeOf((*MockVMSet)(nil).GetPowerStatusByNodeName), name)
}
// GetPrivateIPsByNodeName mocks base method
func (m *MockVMSet) GetPrivateIPsByNodeName(name string) ([]string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPrivateIPsByNodeName", name)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPrivateIPsByNodeName indicates an expected call of GetPrivateIPsByNodeName
func (mr *MockVMSetMockRecorder) GetPrivateIPsByNodeName(name interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPrivateIPsByNodeName", reflect.TypeOf((*MockVMSet)(nil).GetPrivateIPsByNodeName), name)
}

View File

@ -0,0 +1,20 @@
// +build !providerless
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package mockvmsets implements the mock client for VMSet.
package mockvmsets // import "k8s.io/legacy-cloud-providers/azure/mockvmsets"

3
vendor/modules.txt vendored
View File

@ -1870,11 +1870,14 @@ k8s.io/legacy-cloud-providers/azure/clients/interfaceclient
k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient
k8s.io/legacy-cloud-providers/azure/clients/publicipclient k8s.io/legacy-cloud-providers/azure/clients/publicipclient
k8s.io/legacy-cloud-providers/azure/clients/routeclient k8s.io/legacy-cloud-providers/azure/clients/routeclient
k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient
k8s.io/legacy-cloud-providers/azure/clients/routetableclient k8s.io/legacy-cloud-providers/azure/clients/routetableclient
k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient
k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient
k8s.io/legacy-cloud-providers/azure/clients/snapshotclient k8s.io/legacy-cloud-providers/azure/clients/snapshotclient
k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient
k8s.io/legacy-cloud-providers/azure/clients/subnetclient k8s.io/legacy-cloud-providers/azure/clients/subnetclient
k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient
k8s.io/legacy-cloud-providers/azure/clients/vmclient k8s.io/legacy-cloud-providers/azure/clients/vmclient
k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient
k8s.io/legacy-cloud-providers/azure/clients/vmssclient k8s.io/legacy-cloud-providers/azure/clients/vmssclient