Merge a009147fae
into ca5f402322
This commit is contained in:
commit
526c806982
4 changed files with 44 additions and 11 deletions
|
@ -48,11 +48,11 @@ import (
|
||||||
type statusModule string
|
type statusModule string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ngxHealthPort = 18080
|
|
||||||
ngxHealthPath = "/healthz"
|
ngxHealthPath = "/healthz"
|
||||||
|
|
||||||
defaultStatusModule statusModule = "default"
|
defaultStatusModule statusModule = "default"
|
||||||
vtsStatusModule statusModule = "vts"
|
vtsStatusModule statusModule = "vts"
|
||||||
|
defaultServerPort = "default-server-port"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -294,6 +294,7 @@ func (n NGINXController) Info() *ingress.BackendInfo {
|
||||||
// ConfigureFlags allow to configure more flags before the parsing of
|
// ConfigureFlags allow to configure more flags before the parsing of
|
||||||
// command line arguments
|
// command line arguments
|
||||||
func (n *NGINXController) ConfigureFlags(flags *pflag.FlagSet) {
|
func (n *NGINXController) ConfigureFlags(flags *pflag.FlagSet) {
|
||||||
|
flags.Int(defaultServerPort, 18080, `Port used to expose the default server in NGINX.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OverrideFlags customize NGINX controller flags
|
// OverrideFlags customize NGINX controller flags
|
||||||
|
@ -311,6 +312,9 @@ func (n *NGINXController) OverrideFlags(flags *pflag.FlagSet) {
|
||||||
|
|
||||||
flags.Set("ingress-class", ic)
|
flags.Set("ingress-class", ic)
|
||||||
n.stats = newStatsCollector(wc, ic, n.binary)
|
n.stats = newStatsCollector(wc, ic, n.binary)
|
||||||
|
|
||||||
|
dlp, _ := flags.GetInt(defaultServerPort)
|
||||||
|
n.DefaultServerPort = dlp
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultIngressClass just return the default ingress class
|
// DefaultIngressClass just return the default ingress class
|
||||||
|
@ -561,7 +565,7 @@ func (n NGINXController) Name() string {
|
||||||
|
|
||||||
// Check returns if the nginx healthz endpoint is returning ok (status code 200)
|
// Check returns if the nginx healthz endpoint is returning ok (status code 200)
|
||||||
func (n NGINXController) Check(_ *http.Request) error {
|
func (n NGINXController) Check(_ *http.Request) error {
|
||||||
res, err := http.Get(fmt.Sprintf("http://localhost:%v%v", ngxHealthPort, ngxHealthPath))
|
res, err := http.Get(fmt.Sprintf("http://localhost:%v%v", n.DefaultServerPort, ngxHealthPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,11 +64,6 @@ const (
|
||||||
rootLocation = "/"
|
rootLocation = "/"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// list of ports that cannot be used by TCP or UDP services
|
|
||||||
reservedPorts = []string{"80", "443", "8181", "18080"}
|
|
||||||
)
|
|
||||||
|
|
||||||
// GenericController holds the boilerplate code required to build an Ingress controlller.
|
// GenericController holds the boilerplate code required to build an Ingress controlller.
|
||||||
type GenericController struct {
|
type GenericController struct {
|
||||||
cfg *Configuration
|
cfg *Configuration
|
||||||
|
@ -113,6 +108,14 @@ type GenericController struct {
|
||||||
runningConfig *ingress.Configuration
|
runningConfig *ingress.Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListenPort contains all the ports used in the ingress controller.
|
||||||
|
type ListenPort struct {
|
||||||
|
HTTP int
|
||||||
|
HTTPS int
|
||||||
|
DefaultBackend int
|
||||||
|
Health int
|
||||||
|
}
|
||||||
|
|
||||||
// Configuration contains all the settings required by an Ingress controller
|
// Configuration contains all the settings required by an Ingress controller
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
Client clientset.Interface
|
Client clientset.Interface
|
||||||
|
@ -140,6 +143,9 @@ type Configuration struct {
|
||||||
|
|
||||||
UpdateStatus bool
|
UpdateStatus bool
|
||||||
ElectionID string
|
ElectionID string
|
||||||
|
|
||||||
|
// Ports contains the configuration of the used ports in the controller
|
||||||
|
Ports *ListenPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// newIngressController creates an Ingress controller
|
// newIngressController creates an Ingress controller
|
||||||
|
@ -453,6 +459,13 @@ func (ic *GenericController) getStreamServices(configmapName string, proto api.P
|
||||||
return []ingress.L4Service{}
|
return []ingress.L4Service{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usedPorts := []string{
|
||||||
|
strconv.Itoa(ic.cfg.Ports.DefaultBackend),
|
||||||
|
strconv.Itoa(ic.cfg.Ports.HTTP),
|
||||||
|
strconv.Itoa(ic.cfg.Ports.HTTPS),
|
||||||
|
strconv.Itoa(ic.cfg.Ports.Health),
|
||||||
|
}
|
||||||
|
|
||||||
var svcs []ingress.L4Service
|
var svcs []ingress.L4Service
|
||||||
// k -> port to expose
|
// k -> port to expose
|
||||||
// v -> <namespace>/<service name>:<port from service to be used>
|
// v -> <namespace>/<service name>:<port from service to be used>
|
||||||
|
@ -463,8 +476,8 @@ func (ic *GenericController) getStreamServices(configmapName string, proto api.P
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// this ports used by the backend
|
// this ports used are already used by the controller
|
||||||
if local_strings.StringInSlice(k, reservedPorts) {
|
if local_strings.StringInSlice(k, usedPorts) {
|
||||||
glog.Warningf("port %v cannot be used for TCP or UDP services. It is reserved for the Ingress controller", k)
|
glog.Warningf("port %v cannot be used for TCP or UDP services. It is reserved for the Ingress controller", k)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,12 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
||||||
|
|
||||||
healthzPort = flags.Int("healthz-port", 10254, "port for healthz endpoint.")
|
healthzPort = flags.Int("healthz-port", 10254, "port for healthz endpoint.")
|
||||||
|
|
||||||
|
httpPort = flags.Int("http-port", 80, "port used to expose HTTP protocol")
|
||||||
|
|
||||||
|
httpsPort = flags.Int("https-port", 443, "port used to expose HTTPS protocol")
|
||||||
|
|
||||||
|
localDefaultBackendPort = flags.Int("local-default-backend-port", 8181, "port used to expose the default backend service")
|
||||||
|
|
||||||
profiling = flags.Bool("profiling", true, `Enable profiling via web interface host:port/debug/pprof/`)
|
profiling = flags.Bool("profiling", true, `Enable profiling via web interface host:port/debug/pprof/`)
|
||||||
|
|
||||||
defSSLCertificate = flags.String("default-ssl-certificate", "", `Name of the secret
|
defSSLCertificate = flags.String("default-ssl-certificate", "", `Name of the secret
|
||||||
|
@ -164,6 +170,12 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
||||||
PublishService: *publishSvc,
|
PublishService: *publishSvc,
|
||||||
Backend: backend,
|
Backend: backend,
|
||||||
ForceNamespaceIsolation: *forceIsolation,
|
ForceNamespaceIsolation: *forceIsolation,
|
||||||
|
Ports: &ListenPort{
|
||||||
|
HTTP: *httpPort,
|
||||||
|
HTTPS: *httpsPort,
|
||||||
|
DefaultBackend: *localDefaultBackendPort,
|
||||||
|
Health: *healthzPort,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ic := newIngressController(config)
|
ic := newIngressController(config)
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
@ -30,8 +31,11 @@ import (
|
||||||
const DeniedKeyName = "Denied"
|
const DeniedKeyName = "Denied"
|
||||||
|
|
||||||
// newDefaultServer return an BackendServer to be use as default server that returns 503.
|
// newDefaultServer return an BackendServer to be use as default server that returns 503.
|
||||||
func newDefaultServer() ingress.Endpoint {
|
func (ic *GenericController) newDefaultServer() ingress.Endpoint {
|
||||||
return ingress.Endpoint{Address: "127.0.0.1", Port: "8181"}
|
return ingress.Endpoint{
|
||||||
|
Address: "127.0.0.1",
|
||||||
|
Port: strconv.Itoa(ic.cfg.Ports.DefaultBackend),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// newUpstream creates an upstream without servers.
|
// newUpstream creates an upstream without servers.
|
||||||
|
|
Loading…
Reference in a new issue