diff --git a/cloudprovider/options/volcenginecloud_options.go b/cloudprovider/options/volcenginecloud_options.go index 210e5d92..6581584e 100644 --- a/cloudprovider/options/volcenginecloud_options.go +++ b/cloudprovider/options/volcenginecloud_options.go @@ -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 diff --git a/cloudprovider/volcengine/README.md b/cloudprovider/volcengine/README.md index b7c79a26..9fbd6973 100644 --- a/cloudprovider/volcengine/README.md +++ b/cloudprovider/volcengine/README.md @@ -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 @@ -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" diff --git a/cloudprovider/volcengine/README.zh_CN.md b/cloudprovider/volcengine/README.zh_CN.md index baeafcc7..9b8f99ff 100644 --- a/cloudprovider/volcengine/README.zh_CN.md +++ b/cloudprovider/volcengine/README.zh_CN.md @@ -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" diff --git a/cloudprovider/volcengine/clb.go b/cloudprovider/volcengine/clb.go index 0d8eeda1..80b785f1 100644 --- a/cloudprovider/volcengine/clb.go +++ b/cloudprovider/volcengine/clb.go @@ -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 diff --git a/cloudprovider/volcengine/clb_test.go b/cloudprovider/volcengine/clb_test.go index ed58d3f0..aaa39321 100644 --- a/cloudprovider/volcengine/clb_test.go +++ b/cloudprovider/volcengine/clb_test.go @@ -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), }, }, },