From 0aba2c1697b31277c051d03012f7ab206b53d08f Mon Sep 17 00:00:00 2001 From: hello2mao Date: Wed, 22 May 2019 19:28:30 +0800 Subject: [PATCH] fix blb exact match issue --- pkg/cloud-provider/cce.go | 8 ++++---- pkg/cloud-provider/cidr_test.go | 4 ++-- pkg/cloud-provider/load_balancer_blb.go | 1 + pkg/cloud-provider/load_balancer_blb_listener.go | 8 ++++---- pkg/cloud-provider/load_balancer_util.go | 2 ++ pkg/cloud-provider/options_test.go | 3 +-- pkg/cloud-provider/routes.go | 6 +++--- pkg/cloud-sdk/blb/loadbalancer.go | 14 ++++++++++---- 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/pkg/cloud-provider/cce.go b/pkg/cloud-provider/cce.go index e358cbe..98663a0 100644 --- a/pkg/cloud-provider/cce.go +++ b/pkg/cloud-provider/cce.go @@ -27,12 +27,12 @@ import ( "k8s.io/api/core/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + v1core "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/controller" - "k8s.io/client-go/kubernetes/scheme" - v1core "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/cloud-provider-baiducloud/pkg/cloud-sdk/bce" "k8s.io/cloud-provider-baiducloud/pkg/cloud-sdk/clientset" @@ -47,8 +47,8 @@ const CceUserAgent = "cce-k8s:" // Baiducloud defines the main struct type Baiducloud struct { CloudConfig - clientSet clientset.Interface - kubeClient kubernetes.Interface + clientSet clientset.Interface + kubeClient kubernetes.Interface eventBroadcaster record.EventBroadcaster eventRecorder record.EventRecorder } diff --git a/pkg/cloud-provider/cidr_test.go b/pkg/cloud-provider/cidr_test.go index 74c6c8e..8cd882d 100644 --- a/pkg/cloud-provider/cidr_test.go +++ b/pkg/cloud-provider/cidr_test.go @@ -22,11 +22,11 @@ func TestVerifyNoOverlap(t *testing.T) { if err != nil { t.Error(err) } - err = VerifyNoOverlap([]*net.IPNet{cceCidr, customRightCidr,}, cidrBlock) + err = VerifyNoOverlap([]*net.IPNet{cceCidr, customRightCidr}, cidrBlock) if err != nil { t.Error(err) } - err = VerifyNoOverlap([]*net.IPNet{cceCidr, customWrongCidr,}, cidrBlock) + err = VerifyNoOverlap([]*net.IPNet{cceCidr, customWrongCidr}, cidrBlock) if err != nil { t.Log(err) } diff --git a/pkg/cloud-provider/load_balancer_blb.go b/pkg/cloud-provider/load_balancer_blb.go index 28c993e..cd0a15f 100644 --- a/pkg/cloud-provider/load_balancer_blb.go +++ b/pkg/cloud-provider/load_balancer_blb.go @@ -69,6 +69,7 @@ func (bc *Baiducloud) ensureBLB(ctx context.Context, clusterName string, service glog.V(3).Infof("[%v %v] EnsureLoadBalancer create blb success, BLB name: %s, BLB id: %s, BLB address: %s.", service.Namespace, service.Name, resp.Name, resp.LoadBalancerId, resp.Address) argsDesc := blb.DescribeLoadBalancersArgs{ LoadBalancerId: resp.LoadBalancerId, + ExactlyMatch: true, } lbs, err := bc.clientSet.Blb().DescribeLoadBalancers(&argsDesc) if err != nil { diff --git a/pkg/cloud-provider/load_balancer_blb_listener.go b/pkg/cloud-provider/load_balancer_blb_listener.go index 32811bd..f95f712 100644 --- a/pkg/cloud-provider/load_balancer_blb_listener.go +++ b/pkg/cloud-provider/load_balancer_blb_listener.go @@ -126,10 +126,10 @@ func (bc *Baiducloud) updateListener(lb *blb.LoadBalancer, pl PortListener) erro switch pl.Protocol { case "UDP": args := blb.UpdateUDPListenerArgs{ - LoadBalancerId: lb.BlbId, - ListenerPort: pl.Port, - BackendPort: int(pl.NodePort), - Scheduler: "RoundRobin", + LoadBalancerId: lb.BlbId, + ListenerPort: pl.Port, + BackendPort: int(pl.NodePort), + Scheduler: "RoundRobin", HealthCheckString: "HealthCheck", } err := bc.clientSet.Blb().UpdateUDPListener(&args) diff --git a/pkg/cloud-provider/load_balancer_util.go b/pkg/cloud-provider/load_balancer_util.go index c39371a..7814ec8 100644 --- a/pkg/cloud-provider/load_balancer_util.go +++ b/pkg/cloud-provider/load_balancer_util.go @@ -70,6 +70,7 @@ func (bc *Baiducloud) getBCELoadBalancer(name string) (lb *blb.LoadBalancer, exi } args := blb.DescribeLoadBalancersArgs{ LoadBalancerName: name, + ExactlyMatch: true, } lbs, err := bc.clientSet.Blb().DescribeLoadBalancers(&args) if err != nil { @@ -89,6 +90,7 @@ func (bc *Baiducloud) getBCELoadBalancerById(id string) (lb *blb.LoadBalancer, e } args := blb.DescribeLoadBalancersArgs{ LoadBalancerId: id, + ExactlyMatch: true, } lbs, err := bc.clientSet.Blb().DescribeLoadBalancers(&args) if err != nil { diff --git a/pkg/cloud-provider/options_test.go b/pkg/cloud-provider/options_test.go index 5178143..9d34b42 100644 --- a/pkg/cloud-provider/options_test.go +++ b/pkg/cloud-provider/options_test.go @@ -12,8 +12,7 @@ func buildService() *api.Service { Name: "foo", Namespace: api.NamespaceDefault, }, - Spec: api.ServiceSpec{ - }, + Spec: api.ServiceSpec{}, } } diff --git a/pkg/cloud-provider/routes.go b/pkg/cloud-provider/routes.go index 393e168..a933f8f 100644 --- a/pkg/cloud-provider/routes.go +++ b/pkg/cloud-provider/routes.go @@ -285,8 +285,8 @@ func (bc *Baiducloud) routeTableConflictDetection(rs []vpc.RouteRule) { glog.V(4).Infof("RouteTable conflict detected, custom routeRule %v may conflict with cce routeRule %v", otherRR[i], cceRR[j]) if bc.eventRecorder != nil { bc.eventRecorder.Eventf(&v1.ObjectReference{ - Kind: "VPC", - Name: "RouteTableConflict", + Kind: "VPC", + Name: "RouteTableConflict", }, v1.EventTypeWarning, "RouteTableConflictDetection", "RouteTable conflict detected, custom routeRule %v may conflict with cce routeRule %v", otherRR[i], cceRR[j]) } } @@ -312,7 +312,7 @@ func (bc *Baiducloud) isConflict(otherRR vpc.RouteRule, cceRR vpc.RouteRule) boo glog.Errorf("otherRR %v net.ParseCIDR failed: %v", otherRR, err) return false } - err = VerifyNoOverlap([]*net.IPNet{cceCidr, otherCidr,}, cidrBlock) + err = VerifyNoOverlap([]*net.IPNet{cceCidr, otherCidr}, cidrBlock) if err != nil { glog.Errorf("VerifyNoOverlap: %v", err) return true diff --git a/pkg/cloud-sdk/blb/loadbalancer.go b/pkg/cloud-sdk/blb/loadbalancer.go index f08126b..8fc2d2a 100644 --- a/pkg/cloud-sdk/blb/loadbalancer.go +++ b/pkg/cloud-sdk/blb/loadbalancer.go @@ -41,6 +41,7 @@ type DescribeLoadBalancersArgs struct { LoadBalancerName string BCCId string Address string + ExactlyMatch bool } // DescribeLoadBalancersResponse is the response of DescribeLoadBalancers @@ -118,11 +119,16 @@ func (c *Client) CreateLoadBalancer(args *CreateLoadBalancerArgs) (*CreateLoadBa func (c *Client) DescribeLoadBalancers(args *DescribeLoadBalancersArgs) ([]LoadBalancer, error) { var params map[string]string if args != nil { + exactlyMatch := "true" + if !args.ExactlyMatch { + exactlyMatch = "false" + } params = map[string]string{ - "blbId": args.LoadBalancerId, - "name": args.LoadBalancerName, - "bccId": args.BCCId, - "address": args.Address, + "blbId": args.LoadBalancerId, + "name": args.LoadBalancerName, + "bccId": args.BCCId, + "address": args.Address, + "exactlyMatch": exactlyMatch, } } req, err := bce.NewRequest("GET", c.GetURL("v1/blb", params), nil)