enhance: add AllocateLoadBalancerNodePorts in clb plugin (#141)

Co-authored-by: 李志朋 <lizhipeng.629@bytedance.com>
This commit is contained in:
lizhipeng629 2024-04-26 11:24:00 +08:00 committed by GitHub
parent d67e058e0f
commit ffccbc5023
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 55 additions and 28 deletions

View File

@ -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

View File

@ -24,6 +24,11 @@ min_port = 500
- Value`port1/protocol1`,`port2/protocol2`,... The protocol names must be in uppercase letters.
- ConfigurableY
#### AllocateLoadBalancerNodePorts
- MeaningWhether the generated service is assigned nodeport, this can be set to false only in clb passthrough mode
- Valuefalse / true
- ConfigurableY
#### Fixed
- Meaningwhether the mapping relationship is fixed. If the mapping relationship is fixed, the mapping relationship remains unchanged even if the pod is deleted and recreated.
- Valuefalse / true
@ -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"

View File

@ -29,6 +29,11 @@ min_port = 500
- 填写格式false / true
- 是否支持变更:是
#### AllocateLoadBalancerNodePorts
- 含义生成的service是否分配nodeport, 仅在clb的直通模式passthrough才能设置为false
- 填写格式true/false
- 是否支持变更:是
#### AllowNotReadyContainers
- 含义:在容器原地升级时允许不断流的对应容器名称,可填写多个
- 填写格式:{containerName_0},{containerName_1},... 例如sidecar
@ -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"

View File

@ -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
@ -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 {
@ -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 {
@ -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, ":")
@ -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,
}
}
@ -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

View File

@ -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{
@ -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",
@ -332,6 +334,7 @@ func TestClbPlugin_consSvc(t *testing.T) {
},
},
},
AllocateLoadBalancerNodePorts: pointer.BoolPtr(true),
},
},
},