commit
666cbf5089
5 changed files with 37 additions and 23 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
@ -252,6 +253,24 @@ func (n NGINXController) OnUpdate(cmap *api.ConfigMap, ingressCfg ingress.Config
|
||||||
}, n.testTemplate)
|
}, n.testTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the healthcheck name
|
||||||
|
func (n NGINXController) Name() string {
|
||||||
|
return "Ingress Controller"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check returns if the nginx healthz endpoint is returning ok (status code 200)
|
||||||
|
func (n NGINXController) Check(_ *http.Request) error {
|
||||||
|
res, err := http.Get("http://127.0.0.1:18080/healthz")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
return fmt.Errorf("Ingress controller is not healthy")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||||
// https://play.golang.org/p/TVSyCcdxUh
|
// https://play.golang.org/p/TVSyCcdxUh
|
||||||
func nextPowerOf2(v int) int {
|
func nextPowerOf2(v int) int {
|
||||||
|
|
|
@ -18,7 +18,6 @@ package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -35,7 +34,6 @@ import (
|
||||||
unversionedcore "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
unversionedcore "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
||||||
"k8s.io/kubernetes/pkg/client/record"
|
"k8s.io/kubernetes/pkg/client/record"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
"k8s.io/kubernetes/pkg/healthz"
|
|
||||||
"k8s.io/kubernetes/pkg/util/flowcontrol"
|
"k8s.io/kubernetes/pkg/util/flowcontrol"
|
||||||
"k8s.io/kubernetes/pkg/util/intstr"
|
"k8s.io/kubernetes/pkg/util/intstr"
|
||||||
|
|
||||||
|
@ -78,8 +76,6 @@ var (
|
||||||
|
|
||||||
// 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 {
|
||||||
healthz.HealthzChecker
|
|
||||||
|
|
||||||
cfg *Configuration
|
cfg *Configuration
|
||||||
|
|
||||||
ingController *cache.Controller
|
ingController *cache.Controller
|
||||||
|
@ -283,24 +279,6 @@ func (ic *GenericController) controllersInSync() bool {
|
||||||
ic.mapController.HasSynced()
|
ic.mapController.HasSynced()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the healthcheck name
|
|
||||||
func (ic GenericController) Name() string {
|
|
||||||
return "Ingress Controller"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check returns if the nginx healthz endpoint is returning ok (status code 200)
|
|
||||||
func (ic GenericController) Check(_ *http.Request) error {
|
|
||||||
res, err := http.Get("http://127.0.0.1:18080/healthz")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer res.Body.Close()
|
|
||||||
if res.StatusCode != 200 {
|
|
||||||
return fmt.Errorf("Ingress controller is not healthy")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info returns information about the backend
|
// Info returns information about the backend
|
||||||
func (ic GenericController) Info() *ingress.BackendInfo {
|
func (ic GenericController) Info() *ingress.BackendInfo {
|
||||||
return ic.cfg.Backend.Info()
|
return ic.cfg.Backend.Info()
|
||||||
|
|
|
@ -155,7 +155,11 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
||||||
|
|
||||||
func registerHandlers(enableProfiling bool, port int, ic *GenericController) {
|
func registerHandlers(enableProfiling bool, port int, ic *GenericController) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
healthz.InstallHandler(mux, ic)
|
// expose health check endpoint (/healthz)
|
||||||
|
healthz.InstallHandler(mux,
|
||||||
|
healthz.PingHealthz,
|
||||||
|
ic.cfg.Backend,
|
||||||
|
)
|
||||||
|
|
||||||
mux.Handle("/metrics", prometheus.Handler())
|
mux.Handle("/metrics", prometheus.Handler())
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,14 @@ package ingress
|
||||||
// return ingress.NewStandardDefaults()
|
// return ingress.NewStandardDefaults()
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
// func (n DummyController) Name() string {
|
||||||
|
// return "dummy Controller"
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// func (n DummyController) Check(_ *http.Request) error {
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
//
|
||||||
// func (dc DummyController) Info() *BackendInfo {
|
// func (dc DummyController) Info() *BackendInfo {
|
||||||
// Name: "dummy",
|
// Name: "dummy",
|
||||||
// Release: "0.0.0",
|
// Release: "0.0.0",
|
||||||
|
|
|
@ -18,6 +18,7 @@ package ingress
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/healthz"
|
||||||
|
|
||||||
"k8s.io/ingress/core/pkg/ingress/annotations/auth"
|
"k8s.io/ingress/core/pkg/ingress/annotations/auth"
|
||||||
"k8s.io/ingress/core/pkg/ingress/annotations/authreq"
|
"k8s.io/ingress/core/pkg/ingress/annotations/authreq"
|
||||||
|
@ -40,6 +41,10 @@ var (
|
||||||
// Controller holds the methods to handle an Ingress backend
|
// Controller holds the methods to handle an Ingress backend
|
||||||
// TODO (#18): Make sure this is sufficiently supportive of other backends.
|
// TODO (#18): Make sure this is sufficiently supportive of other backends.
|
||||||
type Controller interface {
|
type Controller interface {
|
||||||
|
// HealthzChecker returns is a named healthz check that returns the ingress
|
||||||
|
// controller status
|
||||||
|
healthz.HealthzChecker
|
||||||
|
|
||||||
// Reload takes a byte array representing the new loadbalancer configuration,
|
// Reload takes a byte array representing the new loadbalancer configuration,
|
||||||
// and returns a byte array containing any output/errors from the backend and
|
// and returns a byte array containing any output/errors from the backend and
|
||||||
// if a reload was required.
|
// if a reload was required.
|
||||||
|
|
Loading…
Reference in a new issue