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 #27 from hello2mao/blb-vip
Browse files Browse the repository at this point in the history
support blb allocate vip
  • Loading branch information
hello2mao authored Jan 17, 2019
2 parents d62e0eb + 319d6e7 commit 634f214
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
17 changes: 11 additions & 6 deletions pkg/cloud-provider/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
type AnnotationRequest struct {
LoadBalancerId string
LoadBalancerInternalVpc string
LoadBalancerAllocateVip string
}

// GetLoadBalancer returns whether the specified load balancer exists, and
Expand Down Expand Up @@ -96,11 +97,16 @@ func (bc *BCECloud) EnsureLoadBalancer(ctx context.Context, clusterName string,
if err != nil {
return nil, fmt.Errorf("Can't get VPC info for BLB: %v\n", err)
}
allocateVip := false
if request.LoadBalancerAllocateVip == "true" {
allocateVip = true
}
args := blb.CreateLoadBalancerArgs{
Name: bc.ClusterID + "/" + getServiceName(service),
VpcID: vpcId,
SubnetID: subnetId,
Desc: "auto generated by cce:" + bc.ClusterID,
Name: bc.ClusterID + "/" + getServiceName(service),
VpcID: vpcId,
SubnetID: subnetId,
Desc: "auto generated by cce:" + bc.ClusterID,
AllocateVip: allocateVip,
}
resp, err := bc.clientSet.Blb().CreateLoadBalancer(&args)
if err != nil {
Expand Down Expand Up @@ -383,7 +389,6 @@ func (bc *BCECloud) WorkAround(service *v1.Service) {
glog.V(2).Infof("WorkAround for old version, lb: %v", lb)
}


func (bc *BCECloud) getBCELoadBalancer(name string) (lb *blb.LoadBalancer, exists bool, err error) {
args := blb.DescribeLoadBalancersArgs{
LoadBalancerName: name,
Expand All @@ -407,7 +412,7 @@ func (bc *BCECloud) getBCELoadBalancerById(id string) (lb *blb.LoadBalancer, exi
}
lbs, err := bc.clientSet.Blb().DescribeLoadBalancers(&args)
if err != nil {
glog.V(2).Infof("getBCELoadBalancer blb %s not exists: %v", args.LoadBalancerId ,err)
glog.V(2).Infof("getBCELoadBalancer blb %s not exists: %v", args.LoadBalancerId, err)
return &blb.LoadBalancer{}, false, err
}
if len(lbs) != 1 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/cloud-provider/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
ServiceAnnotationLoadBalancerPrefix = "service.beta.kubernetes.io/cce-load-balancer-"
ServiceAnnotationLoadBalancerId = ServiceAnnotationLoadBalancerPrefix + "id"
ServiceAnnotationLoadBalancerInternalVpc = ServiceAnnotationLoadBalancerPrefix + "internal-vpc"
ServiceAnnotationLoadBalancerAllocateVip = ServiceAnnotationLoadBalancerPrefix + "allocate-vip"
)

func ExtractAnnotationRequest(service *v1.Service) (*AnnotationRequest, *AnnotationRequest) {
Expand All @@ -47,5 +48,11 @@ func ExtractAnnotationRequest(service *v1.Service) (*AnnotationRequest, *Annotat
request.LoadBalancerInternalVpc = loadBalancerInternalVpc
}

loadBalancerAllocateVip, ok := annotation[ServiceAnnotationLoadBalancerAllocateVip]
if ok {
defaulted.LoadBalancerAllocateVip = loadBalancerAllocateVip
request.LoadBalancerAllocateVip = loadBalancerAllocateVip
}

return defaulted, request
}
9 changes: 5 additions & 4 deletions pkg/sdk/blb/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ type DescribeLoadBalancersResponse struct {

// CreateLoadBalancerArgs create blb args
type CreateLoadBalancerArgs struct {
Desc string `json:"desc,omitempty"`
Name string `json:"name,omitempty"`
VpcID string `json:"vpcId,omitempty"`
SubnetID string `json:"subnetId,omitempty"`
Desc string `json:"desc,omitempty"`
Name string `json:"name,omitempty"`
VpcID string `json:"vpcId,omitempty"`
SubnetID string `json:"subnetId,omitempty"`
AllocateVip bool `json:"allocateVip,omitempty"`
}

type CreateLoadBalancerResponse struct {
Expand Down

0 comments on commit 634f214

Please sign in to comment.