commit
666cbf5089
5 changed files with 37 additions and 23 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
|
@ -252,6 +253,24 @@ func (n NGINXController) OnUpdate(cmap *api.ConfigMap, ingressCfg ingress.Config
|
|||
}, 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
|
||||
// https://play.golang.org/p/TVSyCcdxUh
|
||||
func nextPowerOf2(v int) int {
|
||||
|
|
|
@ -18,7 +18,6 @@ package controller
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -35,7 +34,6 @@ import (
|
|||
unversionedcore "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/healthz"
|
||||
"k8s.io/kubernetes/pkg/util/flowcontrol"
|
||||
"k8s.io/kubernetes/pkg/util/intstr"
|
||||
|
||||
|
@ -78,8 +76,6 @@ var (
|
|||
|
||||
// GenericController holds the boilerplate code required to build an Ingress controlller.
|
||||
type GenericController struct {
|
||||
healthz.HealthzChecker
|
||||
|
||||
cfg *Configuration
|
||||
|
||||
ingController *cache.Controller
|
||||
|
@ -283,24 +279,6 @@ func (ic *GenericController) controllersInSync() bool {
|
|||
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
|
||||
func (ic GenericController) Info() *ingress.BackendInfo {
|
||||
return ic.cfg.Backend.Info()
|
||||
|
|
|
@ -155,7 +155,11 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
|||
|
||||
func registerHandlers(enableProfiling bool, port int, ic *GenericController) {
|
||||
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())
|
||||
|
||||
|
|
|
@ -55,6 +55,14 @@ package ingress
|
|||
// 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 {
|
||||
// Name: "dummy",
|
||||
// Release: "0.0.0",
|
||||
|
|
|
@ -18,6 +18,7 @@ package ingress
|
|||
|
||||
import (
|
||||
"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/authreq"
|
||||
|
@ -40,6 +41,10 @@ var (
|
|||
// Controller holds the methods to handle an Ingress backend
|
||||
// TODO (#18): Make sure this is sufficiently supportive of other backends.
|
||||
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,
|
||||
// and returns a byte array containing any output/errors from the backend and
|
||||
// if a reload was required.
|
||||
|
|
Loading…
Reference in a new issue