Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #79 from hello2mao/blb-exact-match-issue
Browse files Browse the repository at this point in the history
fix blb exact match issue
  • Loading branch information
hello2mao authored May 22, 2019
2 parents 39d4fa7 + 0aba2c1 commit 8269f40
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
8 changes: 4 additions & 4 deletions pkg/cloud-provider/cce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud-provider/cidr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cloud-provider/load_balancer_blb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloud-provider/load_balancer_blb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloud-provider/load_balancer_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cloud-provider/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ func buildService() *api.Service {
Name: "foo",
Namespace: api.NamespaceDefault,
},
Spec: api.ServiceSpec{
},
Spec: api.ServiceSpec{},
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/cloud-provider/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Expand All @@ -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
Expand Down
14 changes: 10 additions & 4 deletions pkg/cloud-sdk/blb/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type DescribeLoadBalancersArgs struct {
LoadBalancerName string
BCCId string
Address string
ExactlyMatch bool
}

// DescribeLoadBalancersResponse is the response of DescribeLoadBalancers
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8269f40

Please sign in to comment.