From 6566e044a187360d7a5b0bfe6aa42cd7927832d2 Mon Sep 17 00:00:00 2001 From: Giancarlo Rubio Date: Tue, 4 Apr 2017 10:16:51 +0200 Subject: [PATCH] Add abilitiy to specify health check path --- README.md | 1 + pkg/acme/acme.go | 2 +- pkg/kubelego/kubelego.go | 10 ++++++++++ pkg/kubelego/type.go | 1 + pkg/kubelego_const/consts.go | 2 +- pkg/kubelego_const/interfaces.go | 1 + pkg/mocks/mocks.go | 10 ++++++++++ 7 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 12499e85..6d514893 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Please note: | `LEGO_SERVICE_NAME_NGINX` | n | `kube-lego-nginx` | Service name for NGINX ingress | | `LEGO_SERVICE_NAME_GCE` | n | `kube-lego-gce` | Service name for GCE ingress | | `LEGO_SUPPORTED_INGRESS_CLASS` | n | `nginx,gce` | Specify the supported ingress class | +| `LEGO_HEALTH_CHECK_PATH` | n | `/healthz` | Specify the health check path | | `LEGO_INGRESS_NAME_NGINX` | n | `kube-lego-nginx` | Ingress name which contains the routing for HTTP verification for nginx ingress | | `LEGO_PORT` | n | `8080` | Port where this daemon is listening for verifcation calls (HTTP method)| | `LEGO_CHECK_INTERVAL` | n | `8h` | Interval for periodically certificate checks (to find expired certs)| diff --git a/pkg/acme/acme.go b/pkg/acme/acme.go index 9bdf8452..aacc086c 100644 --- a/pkg/acme/acme.go +++ b/pkg/acme/acme.go @@ -48,7 +48,7 @@ func (a *Acme) Mux() *http.ServeMux { } }) - mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc(a.kubelego.LegoHealthCheckPath(), func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) fmt.Fprint(w, "ok") diff --git a/pkg/kubelego/kubelego.go b/pkg/kubelego/kubelego.go index 2f2880d9..00e569f9 100644 --- a/pkg/kubelego/kubelego.go +++ b/pkg/kubelego/kubelego.go @@ -157,6 +157,9 @@ func (kl *KubeLego) LegoEmail() string { return kl.legoEmail } +func (kl *KubeLego) LegoHealthCheckPath() string { + return kl.legoHealthCheckPath +} func (kl *KubeLego) LegoNamespace() string { return kl.legoNamespace } @@ -340,5 +343,12 @@ func (kl *KubeLego) paramsLego() error { } else { kl.legoWatchNamespace = watchNamespace } + + kl.legoHealthCheckPath = os.Getenv("LEGO_HEALTH_CHECK_PATH") + if len(kl.legoHealthCheckPath) == 0 { + kl.legoHealthCheckPath = kubelego.LegoHealthCheckPath + } + + return nil } diff --git a/pkg/kubelego/type.go b/pkg/kubelego/type.go index 921c8315..10782256 100644 --- a/pkg/kubelego/type.go +++ b/pkg/kubelego/type.go @@ -25,6 +25,7 @@ type KubeLego struct { legoServiceNameGce string legoSupportedIngressClass []string legoHTTPPort intstr.IntOrString + legoHealthCheckPath string legoCheckInterval time.Duration legoMinimumValidity time.Duration legoDefaultIngressClass string diff --git a/pkg/kubelego_const/consts.go b/pkg/kubelego_const/consts.go index cda17214..b2fb9c30 100644 --- a/pkg/kubelego_const/consts.go +++ b/pkg/kubelego_const/consts.go @@ -10,7 +10,7 @@ const AcmeRegistrationUrl = "acme-registration-url" const AcmePrivateKey = k8sApi.TLSPrivateKeyKey const AcmeHttpChallengePath = "/.well-known/acme-challenge" const AcmeHttpSelfTest = "/.well-known/acme-challenge/_selftest" - +const LegoHealthCheckPath = "/healthz" const TLSCertKey = k8sApi.TLSCertKey const TLSPrivateKeyKey = k8sApi.TLSPrivateKeyKey const TLSCaKey = "ca.crt" diff --git a/pkg/kubelego_const/interfaces.go b/pkg/kubelego_const/interfaces.go index ae4980ef..5f64c45e 100644 --- a/pkg/kubelego_const/interfaces.go +++ b/pkg/kubelego_const/interfaces.go @@ -28,6 +28,7 @@ type KubeLego interface { LegoCheckInterval() time.Duration LegoMinimumValidity() time.Duration LegoPodIP() net.IP + LegoHealthCheckPath() string IngressProvider(string) (IngressProvider, error) Version() string AcmeUser() (map[string][]byte, error) diff --git a/pkg/mocks/mocks.go b/pkg/mocks/mocks.go index 5e3b21ee..27ed69b7 100644 --- a/pkg/mocks/mocks.go +++ b/pkg/mocks/mocks.go @@ -76,6 +76,16 @@ func (_mr *_MockKubeLegoRecorder) LegoHTTPPort() *gomock.Call { return _mr.mock.ctrl.RecordCall(_mr.mock, "LegoHTTPPort") } +func (_m *MockKubeLego) LegoHealthCheckPath() string { + ret := _m.ctrl.Call(_m, "LegoHealthCheckPath") + ret0, _ := ret[0].(string) + return ret0 +} + +func (_mr *_MockKubeLegoRecorder) LegoHealthCheckPath() *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "LegoHealthCheckPath") +} + func (_m *MockKubeLego) LegoEmail() string { ret := _m.ctrl.Call(_m, "LegoEmail") ret0, _ := ret[0].(string)