Skip to content

Commit

Permalink
Fix port collision checks for TCP and UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Nov 5, 2017
1 parent 311d286 commit e2b74db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/kubelet/util/sliceutils"

"k8s.io/ingress-nginx/pkg/ingress"
"k8s.io/ingress-nginx/pkg/ingress/annotations/class"
Expand All @@ -56,9 +55,6 @@ const (
)

var (
// list of ports that cannot be used by TCP or UDP services
reservedPorts = []string{"80", "443", "8181", "18080"}

cloner *conversion.Cloner
)

Expand Down Expand Up @@ -260,8 +256,16 @@ func (n *NGINXController) getStreamServices(configmapName string, proto apiv1.Pr
continue
}

// this ports used by the backend
if sliceutils.StringInSlice(k, reservedPorts) {
rp := []int{
n.cfg.ListenPorts.HTTP,
n.cfg.ListenPorts.HTTPS,
n.cfg.ListenPorts.SSLProxy,
n.cfg.ListenPorts.Status,
n.cfg.ListenPorts.Health,
n.cfg.ListenPorts.Default,
}

if intInSlice(externalPort, rp) {
glog.Warningf("port %v cannot be used for TCP or UDP services. It is reserved for the Ingress controller", k)
continue
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/ingress/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ func sysctlFSFileMax() int {
}
return int(rLimit.Max)
}

func intInSlice(i int, list []int) bool {
for _, v := range list {
if v == i {
return true
}
}
return false
}

0 comments on commit e2b74db

Please sign in to comment.