2019-09-27 21:51:53 +00:00
|
|
|
// +build !providerless
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2017 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 azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-03-26 21:07:15 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
|
|
|
"k8s.io/client-go/tools/record"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/auth"
|
2020-08-10 17:43:49 +00:00
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/diskclient/mockdiskclient"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient/mockloadbalancerclient"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/publicipclient/mockpublicipclient"
|
2020-03-26 21:07:15 +00:00
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient"
|
2020-08-10 17:43:49 +00:00
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient/mocksecuritygroupclient"
|
2020-03-26 21:07:15 +00:00
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient"
|
2020-08-10 17:43:49 +00:00
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/vmclient/mockvmclient"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient"
|
|
|
|
"k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient"
|
2019-09-27 21:51:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
errPreconditionFailedEtagMismatch = fmt.Errorf("PreconditionFailedEtagMismatch")
|
|
|
|
)
|
|
|
|
|
2020-03-26 21:07:15 +00:00
|
|
|
// GetTestCloud returns a fake azure cloud for unit tests in Azure related CSI drivers
|
|
|
|
func GetTestCloud(ctrl *gomock.Controller) (az *Cloud) {
|
|
|
|
az = &Cloud{
|
|
|
|
Config: Config{
|
|
|
|
AzureAuthConfig: auth.AzureAuthConfig{
|
|
|
|
TenantID: "tenant",
|
|
|
|
SubscriptionID: "subscription",
|
|
|
|
},
|
|
|
|
ResourceGroup: "rg",
|
|
|
|
VnetResourceGroup: "rg",
|
|
|
|
RouteTableResourceGroup: "rg",
|
|
|
|
SecurityGroupResourceGroup: "rg",
|
|
|
|
Location: "westus",
|
|
|
|
VnetName: "vnet",
|
|
|
|
SubnetName: "subnet",
|
|
|
|
SecurityGroupName: "nsg",
|
|
|
|
RouteTableName: "rt",
|
|
|
|
PrimaryAvailabilitySetName: "as",
|
2020-08-10 17:43:49 +00:00
|
|
|
PrimaryScaleSetName: "vmss",
|
2020-03-26 21:07:15 +00:00
|
|
|
MaximumLoadBalancerRuleCount: 250,
|
|
|
|
VMType: vmTypeStandard,
|
|
|
|
},
|
|
|
|
nodeZones: map[string]sets.String{},
|
|
|
|
nodeInformerSynced: func() bool { return true },
|
|
|
|
nodeResourceGroups: map[string]string{},
|
|
|
|
unmanagedNodes: sets.NewString(),
|
|
|
|
routeCIDRs: map[string]string{},
|
|
|
|
eventRecorder: &record.FakeRecorder{},
|
|
|
|
}
|
2020-08-10 17:43:49 +00:00
|
|
|
az.DisksClient = mockdiskclient.NewMockInterface(ctrl)
|
|
|
|
az.InterfacesClient = mockinterfaceclient.NewMockInterface(ctrl)
|
|
|
|
az.LoadBalancerClient = mockloadbalancerclient.NewMockInterface(ctrl)
|
|
|
|
az.PublicIPAddressesClient = mockpublicipclient.NewMockInterface(ctrl)
|
2020-03-26 21:07:15 +00:00
|
|
|
az.RoutesClient = mockrouteclient.NewMockInterface(ctrl)
|
|
|
|
az.RouteTablesClient = mockroutetableclient.NewMockInterface(ctrl)
|
2020-08-10 17:43:49 +00:00
|
|
|
az.SecurityGroupsClient = mocksecuritygroupclient.NewMockInterface(ctrl)
|
2020-03-26 21:07:15 +00:00
|
|
|
az.SubnetsClient = mocksubnetclient.NewMockInterface(ctrl)
|
2020-08-10 17:43:49 +00:00
|
|
|
az.VirtualMachineScaleSetsClient = mockvmssclient.NewMockInterface(ctrl)
|
|
|
|
az.VirtualMachineScaleSetVMsClient = mockvmssvmclient.NewMockInterface(ctrl)
|
|
|
|
az.VirtualMachinesClient = mockvmclient.NewMockInterface(ctrl)
|
2020-10-14 19:03:41 +00:00
|
|
|
az.VMSet = newAvailabilitySet(az)
|
2020-03-26 21:07:15 +00:00
|
|
|
az.vmCache, _ = az.newVMCache()
|
|
|
|
az.lbCache, _ = az.newLBCache()
|
|
|
|
az.nsgCache, _ = az.newNSGCache()
|
|
|
|
az.rtCache, _ = az.newRouteTableCache()
|
|
|
|
|
2020-08-10 17:43:49 +00:00
|
|
|
common := &controllerCommon{cloud: az, resourceGroup: "rg", location: "westus"}
|
2020-03-26 21:07:15 +00:00
|
|
|
az.controllerCommon = common
|
|
|
|
az.ManagedDiskController = &ManagedDiskController{common: common}
|
|
|
|
|
|
|
|
return az
|
2019-09-27 21:51:53 +00:00
|
|
|
}
|