mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #81054 from nilo19/t-qini-cross_rg_lb
Support cross resource group load balancer.
This commit is contained in:
commit
8527c74e40
@ -163,6 +163,13 @@ type Config struct {
|
|||||||
|
|
||||||
// The cloud configure type for Azure cloud provider. Supported values are file, secret and merge.
|
// The cloud configure type for Azure cloud provider. Supported values are file, secret and merge.
|
||||||
CloudConfigType cloudConfigType `json:"cloudConfigType,omitempty" yaml:"cloudConfigType,omitempty"`
|
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)
|
var _ cloudprovider.Interface = (*Cloud)(nil)
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network"
|
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network"
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
"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/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
@ -232,7 +232,8 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
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)
|
klog.V(10).Infof("LoadBalancerClient.CreateOrUpdate(%s): end", *lb.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if isSuccessHTTPResponse(resp) {
|
if isSuccessHTTPResponse(resp) {
|
||||||
@ -259,7 +260,8 @@ func (az *Cloud) createOrUpdateLBWithRetry(service *v1.Service, lb network.LoadB
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
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)
|
klog.V(10).Infof("LoadBalancerClient.CreateOrUpdate(%s): end", *lb.Name)
|
||||||
done, retryError := az.processHTTPRetryResponse(service, "CreateOrUpdateLoadBalancer", resp, err)
|
done, retryError := az.processHTTPRetryResponse(service, "CreateOrUpdateLoadBalancer", resp, err)
|
||||||
if done && err == nil {
|
if done && err == nil {
|
||||||
@ -282,10 +284,11 @@ func (az *Cloud) ListLB(service *v1.Service) ([]network.LoadBalancer, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
allLBs, err := az.LoadBalancerClient.List(ctx, az.ResourceGroup)
|
rgName := az.getLoadBalancerResourceGroup()
|
||||||
|
allLBs, err := az.LoadBalancerClient.List(ctx, rgName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
az.Event(service, v1.EventTypeWarning, "ListLoadBalancers", err.Error())
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("LoadBalancerClient.List(%v) success", az.ResourceGroup)
|
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()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
allLBs, retryErr = az.LoadBalancerClient.List(ctx, az.ResourceGroup)
|
rgName := az.getLoadBalancerResourceGroup()
|
||||||
|
allLBs, retryErr = az.LoadBalancerClient.List(ctx, rgName)
|
||||||
if retryErr != nil {
|
if retryErr != nil {
|
||||||
az.Event(service, v1.EventTypeWarning, "ListLoadBalancers", retryErr.Error())
|
az.Event(service, v1.EventTypeWarning, "ListLoadBalancers", retryErr.Error())
|
||||||
klog.Errorf("LoadBalancerClient.List(%v) - backoff: failure, will retry,err=%v",
|
klog.Errorf("LoadBalancerClient.List(%v) - backoff: failure, will retry,err=%v",
|
||||||
az.ResourceGroup,
|
rgName,
|
||||||
retryErr)
|
retryErr)
|
||||||
return false, retryErr
|
return false, retryErr
|
||||||
}
|
}
|
||||||
@ -450,7 +454,8 @@ func (az *Cloud) DeleteLB(service *v1.Service, lbName string) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
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 err == nil {
|
||||||
if isSuccessHTTPResponse(resp) {
|
if isSuccessHTTPResponse(resp) {
|
||||||
// Invalidate the cache right after updating
|
// Invalidate the cache right after updating
|
||||||
@ -471,7 +476,8 @@ func (az *Cloud) deleteLBWithRetry(service *v1.Service, lbName string) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
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)
|
done, err := az.processHTTPRetryResponse(service, "DeleteLoadBalancer", resp, err)
|
||||||
if done && err == nil {
|
if done && err == nil {
|
||||||
// Invalidate the cache right after deleting
|
// Invalidate the cache right after deleting
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
cloudprovider "k8s.io/cloud-provider"
|
cloudprovider "k8s.io/cloud-provider"
|
||||||
servicehelpers "k8s.io/cloud-provider/service/helpers"
|
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.
|
// GetLoadBalancerName returns the LoadBalancer name.
|
||||||
func (az *Cloud) GetLoadBalancerName(ctx context.Context, clusterName string, service *v1.Service) string {
|
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)
|
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.
|
// getServiceLoadBalancer gets the loadbalancer for the service if it already exists.
|
||||||
// If wantLb is TRUE then -it selects a new load balancer.
|
// 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
|
// In case the selected load balancer does not exist it returns network.LoadBalancer struct
|
||||||
|
@ -127,6 +127,9 @@ func (az *Cloud) mapLoadBalancerNameToVMSet(lbName string, clusterName string) (
|
|||||||
// So we'd have a separate name for internal load balancer.
|
// So we'd have a separate name for internal load balancer.
|
||||||
// This would be the name for Azure LoadBalancer resource.
|
// This would be the name for Azure LoadBalancer resource.
|
||||||
func (az *Cloud) getAzureLoadBalancerName(clusterName string, vmSetName string, isInternal bool) string {
|
func (az *Cloud) getAzureLoadBalancerName(clusterName string, vmSetName string, isInternal bool) string {
|
||||||
|
if az.LoadBalancerName != "" {
|
||||||
|
clusterName = az.LoadBalancerName
|
||||||
|
}
|
||||||
lbNamePrefix := vmSetName
|
lbNamePrefix := vmSetName
|
||||||
if strings.EqualFold(vmSetName, az.vmSet.GetPrimaryVMSetName()) || az.useStandardLoadBalancer() {
|
if strings.EqualFold(vmSetName, az.vmSet.GetPrimaryVMSetName()) || az.useStandardLoadBalancer() {
|
||||||
lbNamePrefix = clusterName
|
lbNamePrefix = clusterName
|
||||||
|
@ -233,7 +233,7 @@ func (az *Cloud) newLBCache() (*timedCache, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
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)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
|
Loading…
Reference in New Issue
Block a user