diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 932b501c20a..0ef4e6d8367 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -163,6 +163,13 @@ type Config struct { // The cloud configure type for Azure cloud provider. Supported values are file, secret and merge. CloudConfigType cloudConfigType `json:"cloudConfigType,omitempty" yaml:"cloudConfigType,omitempty"` + + // LoadBalancerName determines the specific name of the load balancer user want to use, working with + // LoadBalancerResourceGroup + LoadBalancerName string `json:"loadBalancerName,omitempty" yaml:"loadBalancerName,omitempty"` + // LoadBalancerResourceGroup determines the specific resource group of the load balancer user want to use, working + // with LoadBalancerName + LoadBalancerResourceGroup string `json:"loadBalancerResourceGroup,omitempty" yaml:"loadBalancerResourceGroup,omitempty"` } var _ cloudprovider.Interface = (*Cloud)(nil) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_backoff.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_backoff.go index 6a584b723b6..ec4e49c7810 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_backoff.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_backoff.go @@ -25,7 +25,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network" "github.com/Azure/go-autorest/autorest/to" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" @@ -232,7 +232,8 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer) ctx, cancel := getContextWithCancel() defer cancel() - resp, err := az.LoadBalancerClient.CreateOrUpdate(ctx, az.ResourceGroup, *lb.Name, lb, to.String(lb.Etag)) + rgName := az.getLoadBalancerResourceGroup() + resp, err := az.LoadBalancerClient.CreateOrUpdate(ctx, rgName, *lb.Name, lb, to.String(lb.Etag)) klog.V(10).Infof("LoadBalancerClient.CreateOrUpdate(%s): end", *lb.Name) if err == nil { if isSuccessHTTPResponse(resp) { @@ -259,7 +260,8 @@ func (az *Cloud) createOrUpdateLBWithRetry(service *v1.Service, lb network.LoadB ctx, cancel := getContextWithCancel() defer cancel() - resp, err := az.LoadBalancerClient.CreateOrUpdate(ctx, az.ResourceGroup, *lb.Name, lb, to.String(lb.Etag)) + rgName := az.getLoadBalancerResourceGroup() + resp, err := az.LoadBalancerClient.CreateOrUpdate(ctx, rgName, *lb.Name, lb, to.String(lb.Etag)) klog.V(10).Infof("LoadBalancerClient.CreateOrUpdate(%s): end", *lb.Name) done, retryError := az.processHTTPRetryResponse(service, "CreateOrUpdateLoadBalancer", resp, err) if done && err == nil { @@ -282,10 +284,11 @@ func (az *Cloud) ListLB(service *v1.Service) ([]network.LoadBalancer, error) { ctx, cancel := getContextWithCancel() defer cancel() - allLBs, err := az.LoadBalancerClient.List(ctx, az.ResourceGroup) + rgName := az.getLoadBalancerResourceGroup() + allLBs, err := az.LoadBalancerClient.List(ctx, rgName) if err != nil { az.Event(service, v1.EventTypeWarning, "ListLoadBalancers", err.Error()) - klog.Errorf("LoadBalancerClient.List(%v) failure with err=%v", az.ResourceGroup, err) + klog.Errorf("LoadBalancerClient.List(%v) failure with err=%v", rgName, err) return nil, err } klog.V(2).Infof("LoadBalancerClient.List(%v) success", az.ResourceGroup) @@ -304,11 +307,12 @@ func (az *Cloud) listLBWithRetry(service *v1.Service) ([]network.LoadBalancer, e ctx, cancel := getContextWithCancel() defer cancel() - allLBs, retryErr = az.LoadBalancerClient.List(ctx, az.ResourceGroup) + rgName := az.getLoadBalancerResourceGroup() + allLBs, retryErr = az.LoadBalancerClient.List(ctx, rgName) if retryErr != nil { az.Event(service, v1.EventTypeWarning, "ListLoadBalancers", retryErr.Error()) klog.Errorf("LoadBalancerClient.List(%v) - backoff: failure, will retry,err=%v", - az.ResourceGroup, + rgName, retryErr) return false, retryErr } @@ -450,7 +454,8 @@ func (az *Cloud) DeleteLB(service *v1.Service, lbName string) error { ctx, cancel := getContextWithCancel() defer cancel() - resp, err := az.LoadBalancerClient.Delete(ctx, az.ResourceGroup, lbName) + rgName := az.getLoadBalancerResourceGroup() + resp, err := az.LoadBalancerClient.Delete(ctx, rgName, lbName) if err == nil { if isSuccessHTTPResponse(resp) { // Invalidate the cache right after updating @@ -471,7 +476,8 @@ func (az *Cloud) deleteLBWithRetry(service *v1.Service, lbName string) error { ctx, cancel := getContextWithCancel() defer cancel() - resp, err := az.LoadBalancerClient.Delete(ctx, az.ResourceGroup, lbName) + rgName := az.getLoadBalancerResourceGroup() + resp, err := az.LoadBalancerClient.Delete(ctx, rgName, lbName) done, err := az.processHTTPRetryResponse(service, "DeleteLoadBalancer", resp, err) if done && err == nil { // Invalidate the cache right after deleting diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go index b91d4ffc28c..c5481326fb3 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go @@ -24,7 +24,7 @@ import ( "strconv" "strings" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" cloudprovider "k8s.io/cloud-provider" servicehelpers "k8s.io/cloud-provider/service/helpers" @@ -219,10 +219,17 @@ func (az *Cloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName stri // GetLoadBalancerName returns the LoadBalancer name. func (az *Cloud) GetLoadBalancerName(ctx context.Context, clusterName string, service *v1.Service) string { - // TODO: replace DefaultLoadBalancerName to generate more meaningful loadbalancer names. return cloudprovider.DefaultLoadBalancerName(service) } +func (az *Cloud) getLoadBalancerResourceGroup() string { + if az.LoadBalancerResourceGroup != "" { + return az.LoadBalancerResourceGroup + } + + return az.ResourceGroup +} + // getServiceLoadBalancer gets the loadbalancer for the service if it already exists. // If wantLb is TRUE then -it selects a new load balancer. // In case the selected load balancer does not exist it returns network.LoadBalancer struct diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go index 4feeca22077..0170074ea0f 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go @@ -127,6 +127,9 @@ func (az *Cloud) mapLoadBalancerNameToVMSet(lbName string, clusterName string) ( // So we'd have a separate name for internal load balancer. // This would be the name for Azure LoadBalancer resource. func (az *Cloud) getAzureLoadBalancerName(clusterName string, vmSetName string, isInternal bool) string { + if az.LoadBalancerName != "" { + clusterName = az.LoadBalancerName + } lbNamePrefix := vmSetName if strings.EqualFold(vmSetName, az.vmSet.GetPrimaryVMSetName()) || az.useStandardLoadBalancer() { lbNamePrefix = clusterName diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go index 37f6477c430..33974a44afd 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go @@ -233,7 +233,7 @@ func (az *Cloud) newLBCache() (*timedCache, error) { ctx, cancel := getContextWithCancel() defer cancel() - lb, err := az.LoadBalancerClient.Get(ctx, az.ResourceGroup, key, "") + lb, err := az.LoadBalancerClient.Get(ctx, az.getLoadBalancerResourceGroup(), key, "") exists, message, realErr := checkResourceExistsFromError(err) if realErr != nil { return nil, realErr