From 488dd077b0bd45de39fc6407a24738b19c6571f3 Mon Sep 17 00:00:00 2001 From: Itamar Ostricher Date: Fri, 16 Jun 2017 15:48:21 +0300 Subject: [PATCH] Implement support for GCE health check with HTTP Host Header in GLBC --- controllers/gce/backends/backends.go | 10 +++++++++- controllers/gce/controller/utils.go | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/controllers/gce/backends/backends.go b/controllers/gce/backends/backends.go index a14749749..486cfabfc 100644 --- a/controllers/gce/backends/backends.go +++ b/controllers/gce/backends/backends.go @@ -458,9 +458,17 @@ func applyProbeSettingsToHC(p *api_v1.Probe, hc *healthchecks.HealthCheck) { if !strings.HasPrefix(healthPath, "/") { healthPath = "/" + healthPath } + // Extract host from HTTP headers + host := p.Handler.HTTPGet.Host + for _, header := range p.Handler.HTTPGet.HTTPHeaders { + if header.Name == "Host" { + host = header.Value + break + } + } hc.RequestPath = healthPath - hc.Host = p.Handler.HTTPGet.Host + hc.Host = host hc.Description = "Kubernetes L7 health check generated with readiness probe settings." hc.CheckIntervalSec = int64(p.PeriodSeconds) + int64(healthchecks.DefaultHealthCheckInterval.Seconds()) hc.TimeoutSec = int64(p.TimeoutSeconds) diff --git a/controllers/gce/controller/utils.go b/controllers/gce/controller/utils.go index fab840b59..c8d02b8d2 100644 --- a/controllers/gce/controller/utils.go +++ b/controllers/gce/controller/utils.go @@ -592,10 +592,11 @@ func (t *GCETranslator) getHTTPProbe(svc api_v1.Service, targetPort intstr.IntOr // isSimpleHTTPProbe returns true if the given Probe is: // - an HTTPGet probe, as opposed to a tcp or exec probe -// - has no special host or headers fields +// - has no special host or headers fields, except for possibly an HTTP Host header func isSimpleHTTPProbe(probe *api_v1.Probe) bool { return (probe != nil && probe.Handler.HTTPGet != nil && probe.Handler.HTTPGet.Host == "" && - len(probe.Handler.HTTPGet.HTTPHeaders) == 0) + (len(probe.Handler.HTTPGet.HTTPHeaders) == 0 || + (len(probe.Handler.HTTPGet.HTTPHeaders) == 1 && probe.Handler.HTTPGet.HTTPHeaders[0].Name == "Host"))) } // GetProbe returns a probe that's used for the given nodeport