Skip to content

Commit

Permalink
Fix HTTP/TCP/UDP port limits
Browse files Browse the repository at this point in the history
  • Loading branch information
jspdown committed Jul 1, 2020
1 parent e32cc85 commit 78cfc85
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/maesh/maesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ func maeshCommand(config *cmd.MaeshConfiguration) error {
WatchNamespaces: config.WatchNamespaces,
IgnoreNamespaces: config.IgnoreNamespaces,
MinHTTPPort: minHTTPPort,
MaxHTTPPort: minHTTPPort + config.LimitHTTPPort,
MaxHTTPPort: minHTTPPort + config.LimitHTTPPort - 1,
MinTCPPort: minTCPPort,
MaxTCPPort: minTCPPort + config.LimitTCPPort,
MaxTCPPort: minTCPPort + config.LimitTCPPort - 1,
MinUDPPort: minUDPPort,
MaxUDPPort: minUDPPort + config.LimitUDPPort,
MaxUDPPort: minUDPPort + config.LimitUDPPort - 1,
}, apiServer, log)

var wg sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/portmapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (p *PortMapping) Find(namespace, name string, port int32) (int32, bool) {
// Add adds a new mapping between the given service port and the first port available in the range defined
// within minPort and maxPort. If there's no port left, an error will be returned.
func (p *PortMapping) Add(namespace, name string, port int32) (int32, error) {
for i := p.minPort; i < p.maxPort+1; i++ {
for i := p.minPort; i <= p.maxPort; i++ {
// Skip until an available port is found
if _, exists := p.table[i]; exists {
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *ShadowServiceManager) removeUnusedPortMappings(shadowSvc, svc *corev1.S

func (s *ShadowServiceManager) removeServicePortMapping(namespace, name string, svcPort corev1.ServicePort) {
// Nothing to do here as there is no port table for HTTP ports.
if svcPort.TargetPort.IntVal < s.maxHTTPPort {
if svcPort.TargetPort.IntVal <= s.maxHTTPPort {
return
}

Expand Down Expand Up @@ -239,7 +239,7 @@ func (s *ShadowServiceManager) getTargetPort(trafficType string, portID int, nam

// getHTTPPort returns the HTTP port associated with the given portID.
func (s *ShadowServiceManager) getHTTPPort(portID int) (int32, error) {
if s.minHTTPPort+int32(portID) >= s.maxHTTPPort {
if s.minHTTPPort+int32(portID) > s.maxHTTPPort {
return 0, errors.New("unable to find an available HTTP port")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func TestShadowServiceManager_getHTTPPort(t *testing.T) {
}{
{
desc: "should return an error if no HTTP port mapping is available",
portID: 2,
portID: 3,
expectedErr: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func (p *Provider) buildBlockAllRouters(cfg *dynamic.Configuration, svc *topolog

func (p Provider) buildHTTPEntrypoint(portID int) (string, error) {
port := p.config.MinHTTPPort + int32(portID)
if port >= p.config.MaxHTTPPort {
if port > p.config.MaxHTTPPort {
return "", errors.New("too many HTTP entrypoints")
}

Expand Down

0 comments on commit 78cfc85

Please sign in to comment.