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

Support UDP LB Service #49

Merged
merged 7 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions pkg/cloud-provider/cce.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,6 @@ type CloudConfig struct {
Debug bool `json:"Debug"`
}

// ServiceAnnotation contains annotations from service
type ServiceAnnotation struct {
LoadBalancerId string
LoadBalancerInternalVpc string
LoadBalancerAllocateVip string
ElasticIPName string
ElasticIPPaymentTiming string
ElasticIPBillingMethod string
ElasticIPBandwidthInMbps int
ElasticIPReservationLength int
}

// NodeAnnotation contains annotations from node
type NodeAnnotation struct {
VpcId string
VpcRouteTableId string
VpcRouteRuleId string
CCMVersion string
}

// CCMVersion is the version of CCM
var CCMVersion string

Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud-provider/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ func (bc *Baiducloud) validateService(service *v1.Service) error {
return fmt.Errorf("requested load balancer with no ports")
}
for _, port := range service.Spec.Ports {
if port.Protocol != v1.ProtocolTCP {
return fmt.Errorf("only TCP LoadBalancer is supported for Baidu CCE")
if port.Protocol != v1.ProtocolTCP && port.Protocol != v1.ProtocolUDP {
return fmt.Errorf("only TCP,UDP LoadBalancer is supported for Baidu CCE")
}
}
return nil
Expand Down
92 changes: 92 additions & 0 deletions pkg/cloud-provider/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,20 @@ const (
ServiceAnnotationLoadBalancerId = ServiceAnnotationLoadBalancerPrefix + "id"
// ServiceAnnotationLoadBalancerInternalVpc is the annotation of LoadBalancerInternalVpc
ServiceAnnotationLoadBalancerInternalVpc = ServiceAnnotationLoadBalancerPrefix + "internal-vpc"
// ServiceAnnotationLoadBalancerAllocateVip is the annotation which indicates BLB with a VIP
ServiceAnnotationLoadBalancerAllocateVip = ServiceAnnotationLoadBalancerPrefix + "allocate-vip"
// ServiceAnnotationLoadBalancerScheduler is the annotation of load balancer which can be "RoundRobin"/"LeastConnection"/"Hash"
ServiceAnnotationLoadBalancerScheduler = ServiceAnnotationLoadBalancerPrefix + "scheduler"
// ServiceAnnotationLoadBalancerHealthCheckTimeoutInSecond is the annotation of health check timeout, default 3s, [1, 60]
ServiceAnnotationLoadBalancerHealthCheckTimeoutInSecond = ServiceAnnotationLoadBalancerPrefix + "health-check-timeout-in-second"
// ServiceAnnotationLoadBalancerHealthCheckInterval is the annotation of health check interval, default 3s, [1, 10]
ServiceAnnotationLoadBalancerHealthCheckInterval = ServiceAnnotationLoadBalancerPrefix + "health-check-interval"
// ServiceAnnotationLoadBalancerUnhealthyThreshold is the annotation of unhealthy threshold, default 3, [2, 5]
ServiceAnnotationLoadBalancerUnhealthyThreshold = ServiceAnnotationLoadBalancerPrefix + "unhealthy-threshold"
// ServiceAnnotationLoadBalancerHealthyThreshold is the annotation of healthy threshold, default 3, [2, 5]
ServiceAnnotationLoadBalancerHealthyThreshold = ServiceAnnotationLoadBalancerPrefix + "healthy-threshold"
// ServiceAnnotationLoadBalancerHealthCheckString is the annotation of health check string
ServiceAnnotationLoadBalancerHealthCheckString = ServiceAnnotationLoadBalancerPrefix + "health-check-string"

// ServiceAnnotationElasticIPPrefix is the annotation prefix of ElasticIP
ServiceAnnotationElasticIPPrefix = "service.beta.kubernetes.io/cce-elastic-ip-"
Expand Down Expand Up @@ -60,6 +73,35 @@ const (
NodeAnnotationCCMVersion = NodeAnnotationPrefix + "ccm-version"
)

// ServiceAnnotation contains annotations from service
type ServiceAnnotation struct {
/* BLB */
LoadBalancerId string
LoadBalancerInternalVpc string
LoadBalancerAllocateVip string
LoadBalancerScheduler string
LoadBalancerHealthCheckTimeoutInSecond int
LoadBalancerHealthCheckInterval int
LoadBalancerUnhealthyThreshold int
LoadBalancerHealthyThreshold int
LoadBalancerHealthCheckString string

/* EIP */
ElasticIPName string
ElasticIPPaymentTiming string
ElasticIPBillingMethod string
ElasticIPBandwidthInMbps int
ElasticIPReservationLength int
}

// NodeAnnotation contains annotations from node
type NodeAnnotation struct {
VpcId string
VpcRouteTableId string
VpcRouteRuleId string
CCMVersion string
}

// ExtractServiceAnnotation extract annotations from service
func ExtractServiceAnnotation(service *v1.Service) *ServiceAnnotation {
glog.V(4).Infof("start to ExtractServiceAnnotation: %v", service.Annotations)
Expand All @@ -84,6 +126,56 @@ func ExtractServiceAnnotation(service *v1.Service) *ServiceAnnotation {
result.LoadBalancerAllocateVip = loadBalancerAllocateVip
}

loadBalancerScheduler, ok := annotation[ServiceAnnotationLoadBalancerScheduler]
if ok {
result.LoadBalancerScheduler = loadBalancerScheduler
}

loadBalancerHealthCheckTimeoutInSecond, exist := annotation[ServiceAnnotationLoadBalancerHealthCheckTimeoutInSecond]
if exist {
i, err := strconv.Atoi(loadBalancerHealthCheckTimeoutInSecond)
if err != nil {
glog.V(4).Infof("ServiceAnnotationLoadBalancerHealthCheckTimeoutInSecond must be int")
} else {
result.LoadBalancerHealthCheckTimeoutInSecond = i
}
}

loadBalancerHealthCheckInterval, exist := annotation[ServiceAnnotationLoadBalancerHealthCheckInterval]
if exist {
i, err := strconv.Atoi(loadBalancerHealthCheckInterval)
if err != nil {
glog.V(4).Infof("ServiceAnnotationLoadBalancerHealthCheckInterval must be int")
} else {
result.LoadBalancerHealthCheckInterval = i
}
}

loadBalancerUnhealthyThreshold, exist := annotation[ServiceAnnotationLoadBalancerUnhealthyThreshold]
if exist {
i, err := strconv.Atoi(loadBalancerUnhealthyThreshold)
if err != nil {
glog.V(4).Infof("ServiceAnnotationLoadBalancerUnhealthyThreshold must be int")
} else {
result.LoadBalancerUnhealthyThreshold = i
}
}

loadBalancerHealthyThreshold, exist := annotation[ServiceAnnotationLoadBalancerHealthyThreshold]
if exist {
i, err := strconv.Atoi(loadBalancerHealthyThreshold)
if err != nil {
glog.V(4).Infof("ServiceAnnotationLoadBalancerHealthyThreshold must be int")
} else {
result.LoadBalancerHealthyThreshold = i
}
}

loadBalancerHealthCheckString, exist := annotation[ServiceAnnotationLoadBalancerHealthCheckString]
if exist {
result.LoadBalancerHealthCheckString = loadBalancerHealthCheckString
}

elasticIPName, exist := annotation[ServiceAnnotationElasticIPName]
if exist {
result.ElasticIPName = elasticIPName
Expand Down