diff --git a/pkg/cloud-provider/load_balancer.go b/pkg/cloud-provider/load_balancer.go index df32beb..0788a64 100644 --- a/pkg/cloud-provider/load_balancer.go +++ b/pkg/cloud-provider/load_balancer.go @@ -36,6 +36,7 @@ import ( type AnnotationRequest struct { LoadBalancerId string LoadBalancerInternalVpc string + LoadBalancerAllocateVip string } // GetLoadBalancer returns whether the specified load balancer exists, and @@ -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 { @@ -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, @@ -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 { diff --git a/pkg/cloud-provider/options.go b/pkg/cloud-provider/options.go index 9e0a2c9..48f86d4 100644 --- a/pkg/cloud-provider/options.go +++ b/pkg/cloud-provider/options.go @@ -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) { @@ -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 } diff --git a/pkg/sdk/blb/loadbalancer.go b/pkg/sdk/blb/loadbalancer.go index acb32dc..94c0ae3 100644 --- a/pkg/sdk/blb/loadbalancer.go +++ b/pkg/sdk/blb/loadbalancer.go @@ -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 {