Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic fixes for network port ranges #181

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading