Skip to content

Commit

Permalink
enhance: add AllocateLoadBalancerNodePorts in clb plugin (openkruise#141
Browse files Browse the repository at this point in the history
)

Co-authored-by: 李志朋 <[email protected]>
  • Loading branch information
lizhipeng629 and 李志朋 authored Apr 26, 2024
1 parent d67e058 commit ffccbc5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 28 deletions.
3 changes: 0 additions & 3 deletions cloudprovider/options/volcenginecloud_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ type CLBOptions struct {

func (v VolcengineOptions) Valid() bool {
clbOptions := v.CLBOptions
if clbOptions.MaxPort-clbOptions.MinPort > 200 {
return false
}

if clbOptions.MaxPort > 65535 {
return false
Expand Down
8 changes: 8 additions & 0 deletions cloudprovider/volcengine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ min_port = 500
- Value:`port1/protocol1`,`port2/protocol2`,... The protocol names must be in uppercase letters.
- Configurable:Y

#### AllocateLoadBalancerNodePorts
- Meaning:Whether the generated service is assigned nodeport, this can be set to false only in clb passthrough mode
- Value:false / true
- Configurable:Y

#### Fixed
- Meaning:whether the mapping relationship is fixed. If the mapping relationship is fixed, the mapping relationship remains unchanged even if the pod is deleted and recreated.
- Value:false / true
Expand Down Expand Up @@ -63,6 +68,9 @@ spec:
#If there are multiple ports, the format is as follows: {port1}/{protocol1},{port2}/{protocol2}...
#If the protocol is not filled in, the default is TCP
value: 80/TCP
- name: AllocateLoadBalancerNodePorts
# Whether the generated service is assigned nodeport.
value: "true"
- name: Fixed
#Fill in here whether a fixed IP is required [optional] ; Default is false
value: "false"
Expand Down
8 changes: 8 additions & 0 deletions cloudprovider/volcengine/README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ min_port = 500
- 填写格式:false / true
- 是否支持变更:是

#### AllocateLoadBalancerNodePorts
- 含义:生成的service是否分配nodeport, 仅在clb的直通模式(passthrough)下,才能设置为false
- 填写格式:true/false
- 是否支持变更:是

#### AllowNotReadyContainers
- 含义:在容器原地升级时允许不断流的对应容器名称,可填写多个
- 填写格式:{containerName_0},{containerName_1},... 例如:sidecar
Expand Down Expand Up @@ -64,6 +69,9 @@ spec:
#If there are multiple ports, the format is as follows: {port1}/{protocol1},{port2}/{protocol2}...
#If the protocol is not filled in, the default is TCP
value: 80/TCP
- name: AllocateLoadBalancerNodePorts
# Whether the generated service is assigned nodeport.
value: "true"
- name: Fixed
#Fill in here whether a fixed IP is required [optional] ; Default is false
value: "false"
Expand Down
61 changes: 36 additions & 25 deletions cloudprovider/volcengine/clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ import (
)

const (
ClbNetwork = "Volcengine-CLB"
AliasCLB = "CLB-Network"
ClbIdLabelKey = "service.beta.kubernetes.io/volcengine-loadbalancer-id"
ClbIdsConfigName = "ClbIds"
PortProtocolsConfigName = "PortProtocols"
FixedConfigName = "Fixed"
ClbAnnotations = "Annotations"
ClbConfigHashKey = "game.kruise.io/network-config-hash"
ClbIdAnnotationKey = "service.beta.kubernetes.io/volcengine-loadbalancer-id"
ClbAddressTypeKey = "service.beta.kubernetes.io/volcengine-loadbalancer-address-type"
ClbAddressTypePublic = "PUBLIC"
ClbSchedulerKey = "service.beta.kubernetes.io/volcengine-loadbalancer-scheduler"
ClbSchedulerWRR = "wrr"
SvcSelectorKey = "statefulset.kubernetes.io/pod-name"
ClbNetwork = "Volcengine-CLB"
AliasCLB = "CLB-Network"
ClbIdLabelKey = "service.beta.kubernetes.io/volcengine-loadbalancer-id"
ClbIdsConfigName = "ClbIds"
PortProtocolsConfigName = "PortProtocols"
FixedConfigName = "Fixed"
AllocateLoadBalancerNodePorts = "AllocateLoadBalancerNodePorts"
ClbAnnotations = "Annotations"
ClbConfigHashKey = "game.kruise.io/network-config-hash"
ClbIdAnnotationKey = "service.beta.kubernetes.io/volcengine-loadbalancer-id"
ClbAddressTypeKey = "service.beta.kubernetes.io/volcengine-loadbalancer-address-type"
ClbAddressTypePublic = "PUBLIC"
ClbSchedulerKey = "service.beta.kubernetes.io/volcengine-loadbalancer-scheduler"
ClbSchedulerWRR = "wrr"
SvcSelectorKey = "statefulset.kubernetes.io/pod-name"
)

type portAllocated map[int32]bool
Expand All @@ -66,11 +67,12 @@ type ClbPlugin struct {
}

type clbConfig struct {
lbIds []string
targetPorts []int
protocols []corev1.Protocol
isFixed bool
annotations map[string]string
lbIds []string
targetPorts []int
protocols []corev1.Protocol
isFixed bool
annotations map[string]string
allocateLoadBalancerNodePorts bool
}

func (c *ClbPlugin) Name() string {
Expand Down Expand Up @@ -353,6 +355,7 @@ func parseLbConfig(conf []gamekruiseiov1alpha1.NetworkConfParams) *clbConfig {
ports := make([]int, 0)
protocols := make([]corev1.Protocol, 0)
isFixed := false
allocateLoadBalancerNodePorts := true
annotations := map[string]string{}
for _, c := range conf {
switch c.Name {
Expand Down Expand Up @@ -382,6 +385,12 @@ func parseLbConfig(conf []gamekruiseiov1alpha1.NetworkConfParams) *clbConfig {
continue
}
isFixed = v
case AllocateLoadBalancerNodePorts:
v, err := strconv.ParseBool(c.Value)
if err != nil {
continue
}
allocateLoadBalancerNodePorts = v
case ClbAnnotations:
for _, anno := range strings.Split(c.Value, ",") {
annoKV := strings.Split(anno, ":")
Expand All @@ -394,11 +403,12 @@ func parseLbConfig(conf []gamekruiseiov1alpha1.NetworkConfParams) *clbConfig {
}
}
return &clbConfig{
lbIds: lbIds,
protocols: protocols,
targetPorts: ports,
isFixed: isFixed,
annotations: annotations,
lbIds: lbIds,
protocols: protocols,
targetPorts: ports,
isFixed: isFixed,
annotations: annotations,
allocateLoadBalancerNodePorts: allocateLoadBalancerNodePorts,
}
}

Expand Down Expand Up @@ -455,7 +465,8 @@ func (c *ClbPlugin) consSvc(config *clbConfig, pod *corev1.Pod, client client.Cl
Selector: map[string]string{
SvcSelectorKey: pod.GetName(),
},
Ports: svcPorts,
Ports: svcPorts,
AllocateLoadBalancerNodePorts: pointer.Bool(config.allocateLoadBalancerNodePorts),
},
}
return svc
Expand Down
3 changes: 3 additions & 0 deletions cloudprovider/volcengine/clb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ func TestClbPlugin_consSvc(t *testing.T) {
"service.beta.kubernetes.io/volcengine-loadbalancer-scheduler": "wrr",
"service.beta.kubernetes.io/volcengine-loadbalancer-pass-through": "true",
},
allocateLoadBalancerNodePorts: true,
},
pod: &corev1.Pod{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -301,6 +302,7 @@ func TestClbPlugin_consSvc(t *testing.T) {
"service.beta.kubernetes.io/volcengine-loadbalancer-scheduler": "wrr",
"service.beta.kubernetes.io/volcengine-loadbalancer-pass-through": "true",
},
allocateLoadBalancerNodePorts: true,
}),
"service.beta.kubernetes.io/volcengine-loadbalancer-health-check-flag": "on",
"service.beta.kubernetes.io/volcengine-loadbalancer-healthy-threshold": "3",
Expand Down Expand Up @@ -332,6 +334,7 @@ func TestClbPlugin_consSvc(t *testing.T) {
},
},
},
AllocateLoadBalancerNodePorts: pointer.BoolPtr(true),
},
},
},
Expand Down

0 comments on commit ffccbc5

Please sign in to comment.