Skip to content

Commit 51aad5b

Browse files
authored
Semantic fixes for network port ranges (openkruise#181)
Signed-off-by: ChrisLiu <[email protected]>
1 parent 6bba287 commit 51aad5b

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

cloudprovider/alibabacloud/nlb.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func (n *NlbPlugin) allocate(lbIds []string, num int, nsName string) (string, []
369369
// find lb with adequate ports
370370
for _, slbId := range lbIds {
371371
sum := 0
372-
for i := n.minPort; i < n.maxPort; i++ {
372+
for i := n.minPort; i <= n.maxPort; i++ {
373373
if !n.cache[slbId][i] {
374374
sum++
375375
}
@@ -388,8 +388,8 @@ func (n *NlbPlugin) allocate(lbIds []string, num int, nsName string) (string, []
388388
var port int32
389389
if n.cache[lbId] == nil {
390390
// init cache for new lb
391-
n.cache[lbId] = make(portAllocated, n.maxPort-n.minPort)
392-
for i := n.minPort; i < n.maxPort; i++ {
391+
n.cache[lbId] = make(portAllocated, n.maxPort-n.minPort+1)
392+
for i := n.minPort; i <= n.maxPort; i++ {
393393
n.cache[lbId][i] = false
394394
}
395395
// block ports

cloudprovider/alibabacloud/slb.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func initLbCache(svcList []corev1.Service, minPort, maxPort int32, blockPorts []
127127
if lbId != "" && svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
128128
// init cache for that lb
129129
if newCache[lbId] == nil {
130-
newCache[lbId] = make(portAllocated, maxPort-minPort)
131-
for i := minPort; i < maxPort; i++ {
130+
newCache[lbId] = make(portAllocated, maxPort-minPort+1)
131+
for i := minPort; i <= maxPort; i++ {
132132
newCache[lbId][i] = false
133133
}
134134
}
@@ -327,7 +327,7 @@ func (s *SlbPlugin) allocate(lbIds []string, num int, nsName string) (string, []
327327
// find lb with adequate ports
328328
for _, slbId := range lbIds {
329329
sum := 0
330-
for i := s.minPort; i < s.maxPort; i++ {
330+
for i := s.minPort; i <= s.maxPort; i++ {
331331
if !s.cache[slbId][i] {
332332
sum++
333333
}
@@ -346,8 +346,8 @@ func (s *SlbPlugin) allocate(lbIds []string, num int, nsName string) (string, []
346346
var port int32
347347
if s.cache[lbId] == nil {
348348
// init cache for new lb
349-
s.cache[lbId] = make(portAllocated, s.maxPort-s.minPort)
350-
for i := s.minPort; i < s.maxPort; i++ {
349+
s.cache[lbId] = make(portAllocated, s.maxPort-s.minPort+1)
350+
for i := s.minPort; i <= s.maxPort; i++ {
351351
s.cache[lbId][i] = false
352352
}
353353
// block ports

cloudprovider/options/alibabacloud_options.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func (o AlibabaCloudOptions) Valid() bool {
2222
// SLB valid
2323
slbOptions := o.SLBOptions
2424
for _, blockPort := range slbOptions.BlockPorts {
25-
if blockPort >= slbOptions.MaxPort || blockPort < slbOptions.MinPort {
25+
if blockPort >= slbOptions.MaxPort || blockPort <= slbOptions.MinPort {
2626
return false
2727
}
2828
}
29-
if int(slbOptions.MaxPort-slbOptions.MinPort)-len(slbOptions.BlockPorts) != 200 {
29+
if int(slbOptions.MaxPort-slbOptions.MinPort)-len(slbOptions.BlockPorts) >= 200 {
3030
return false
3131
}
3232
if slbOptions.MinPort <= 0 {
@@ -35,11 +35,11 @@ func (o AlibabaCloudOptions) Valid() bool {
3535
// NLB valid
3636
nlbOptions := o.NLBOptions
3737
for _, blockPort := range nlbOptions.BlockPorts {
38-
if blockPort >= nlbOptions.MaxPort || blockPort < nlbOptions.MinPort {
38+
if blockPort >= nlbOptions.MaxPort || blockPort <= nlbOptions.MinPort {
3939
return false
4040
}
4141
}
42-
if int(nlbOptions.MaxPort-nlbOptions.MinPort)-len(nlbOptions.BlockPorts) != 500 {
42+
if int(nlbOptions.MaxPort-nlbOptions.MinPort)-len(nlbOptions.BlockPorts) >= 500 {
4343
return false
4444
}
4545
if nlbOptions.MinPort <= 0 {

config/manager/config.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ min_port = 8000
77
[alibabacloud]
88
enable = true
99
[alibabacloud.slb]
10-
max_port = 701
10+
max_port = 700
1111
min_port = 500
1212
block_ports = [593]
1313
[alibabacloud.nlb]
14-
max_port = 1503
14+
max_port = 1502
1515
min_port = 1000
1616
block_ports = [1025, 1434, 1068]
1717

0 commit comments

Comments
 (0)