Skip to content

Commit

Permalink
Semantic fixes for network port ranges (#181)
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisLiu <chrisliu1995@163.com>
  • Loading branch information
chrisliu1995 authored Nov 6, 2024
1 parent 6bba287 commit 51aad5b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cloudprovider/alibabacloud/nlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cloudprovider/alibabacloud/slb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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++
}
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cloudprovider/options/alibabacloud_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions config/manager/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 51aad5b

Please sign in to comment.