From ca91c4b36b0af84848500213eea0597f1fde5ed0 Mon Sep 17 00:00:00 2001 From: ChrisLiu Date: Tue, 5 Nov 2024 18:36:25 +0800 Subject: [PATCH] Semantic fixes for network port ranges Signed-off-by: ChrisLiu --- cloudprovider/alibabacloud/nlb.go | 6 +++--- cloudprovider/alibabacloud/slb.go | 10 +++++----- cloudprovider/options/alibabacloud_options.go | 8 ++++---- config/manager/config.toml | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cloudprovider/alibabacloud/nlb.go b/cloudprovider/alibabacloud/nlb.go index 3a0e95e..8bd9927 100644 --- a/cloudprovider/alibabacloud/nlb.go +++ b/cloudprovider/alibabacloud/nlb.go @@ -369,7 +369,7 @@ func (n *NlbPlugin) allocate(lbIds []string, num int, nsName string) (string, [] // find lb with adequate ports for _, slbId := range lbIds { sum := 0 - for i := n.minPort; i < n.maxPort; i++ { + for i := n.minPort; i <= n.maxPort; i++ { if !n.cache[slbId][i] { sum++ } @@ -388,8 +388,8 @@ func (n *NlbPlugin) allocate(lbIds []string, num int, nsName string) (string, [] var port int32 if n.cache[lbId] == nil { // init cache for new lb - n.cache[lbId] = make(portAllocated, n.maxPort-n.minPort) - for i := n.minPort; i < n.maxPort; i++ { + n.cache[lbId] = make(portAllocated, n.maxPort-n.minPort+1) + for i := n.minPort; i <= n.maxPort; i++ { n.cache[lbId][i] = false } // block ports diff --git a/cloudprovider/alibabacloud/slb.go b/cloudprovider/alibabacloud/slb.go index 43876dd..1ebf71f 100644 --- a/cloudprovider/alibabacloud/slb.go +++ b/cloudprovider/alibabacloud/slb.go @@ -127,8 +127,8 @@ func initLbCache(svcList []corev1.Service, minPort, maxPort int32, blockPorts [] if lbId != "" && svc.Spec.Type == corev1.ServiceTypeLoadBalancer { // init cache for that lb if newCache[lbId] == nil { - newCache[lbId] = make(portAllocated, maxPort-minPort) - for i := minPort; i < maxPort; i++ { + newCache[lbId] = make(portAllocated, maxPort-minPort+1) + for i := minPort; i <= maxPort; i++ { newCache[lbId][i] = false } } @@ -327,7 +327,7 @@ func (s *SlbPlugin) allocate(lbIds []string, num int, nsName string) (string, [] // find lb with adequate ports for _, slbId := range lbIds { sum := 0 - for i := s.minPort; i < s.maxPort; i++ { + for i := s.minPort; i <= s.maxPort; i++ { if !s.cache[slbId][i] { sum++ } @@ -346,8 +346,8 @@ func (s *SlbPlugin) allocate(lbIds []string, num int, nsName string) (string, [] var port int32 if s.cache[lbId] == nil { // init cache for new lb - s.cache[lbId] = make(portAllocated, s.maxPort-s.minPort) - for i := s.minPort; i < s.maxPort; i++ { + s.cache[lbId] = make(portAllocated, s.maxPort-s.minPort+1) + for i := s.minPort; i <= s.maxPort; i++ { s.cache[lbId][i] = false } // block ports diff --git a/cloudprovider/options/alibabacloud_options.go b/cloudprovider/options/alibabacloud_options.go index 6c043ea..cd0a24a 100644 --- a/cloudprovider/options/alibabacloud_options.go +++ b/cloudprovider/options/alibabacloud_options.go @@ -22,11 +22,11 @@ func (o AlibabaCloudOptions) Valid() bool { // SLB valid slbOptions := o.SLBOptions for _, blockPort := range slbOptions.BlockPorts { - if blockPort >= slbOptions.MaxPort || blockPort < slbOptions.MinPort { + if blockPort >= slbOptions.MaxPort || blockPort <= slbOptions.MinPort { return false } } - if int(slbOptions.MaxPort-slbOptions.MinPort)-len(slbOptions.BlockPorts) != 200 { + if int(slbOptions.MaxPort-slbOptions.MinPort)-len(slbOptions.BlockPorts) >= 200 { return false } if slbOptions.MinPort <= 0 { @@ -35,11 +35,11 @@ func (o AlibabaCloudOptions) Valid() bool { // NLB valid nlbOptions := o.NLBOptions for _, blockPort := range nlbOptions.BlockPorts { - if blockPort >= nlbOptions.MaxPort || blockPort < nlbOptions.MinPort { + if blockPort >= nlbOptions.MaxPort || blockPort <= nlbOptions.MinPort { return false } } - if int(nlbOptions.MaxPort-nlbOptions.MinPort)-len(nlbOptions.BlockPorts) != 500 { + if int(nlbOptions.MaxPort-nlbOptions.MinPort)-len(nlbOptions.BlockPorts) >= 500 { return false } if nlbOptions.MinPort <= 0 { diff --git a/config/manager/config.toml b/config/manager/config.toml index 3091f6c..c493839 100644 --- a/config/manager/config.toml +++ b/config/manager/config.toml @@ -7,11 +7,11 @@ min_port = 8000 [alibabacloud] enable = true [alibabacloud.slb] -max_port = 701 +max_port = 700 min_port = 500 block_ports = [593] [alibabacloud.nlb] -max_port = 1503 +max_port = 1502 min_port = 1000 block_ports = [1025, 1434, 1068]