Migrate existing health check settings

This commit is contained in:
Nick Sardo 2017-06-14 16:14:15 -07:00
parent e3c7f070eb
commit f65b35f766
4 changed files with 76 additions and 13 deletions

View file

@ -171,13 +171,22 @@ func (b *Backends) Get(port int64) (*compute.BackendService, error) {
func (b *Backends) ensureHealthCheck(sp ServicePort) (string, error) {
hc := b.healthChecker.New(sp.Port, sp.Protocol)
if b.prober != nil {
existingLegacyHC, err := b.healthChecker.GetLegacy(sp.Port)
if err != nil && !utils.IsHTTPErrorCode(err, http.StatusNotFound) {
return "", err
}
if existingLegacyHC != nil {
glog.V(4).Infof("Applying settings of existing health check to newer health check on port %+v", sp)
applyLegacyHCToHC(existingLegacyHC, hc)
} else if b.prober != nil {
probe, err := b.prober.GetProbe(sp)
if err != nil {
return "", err
}
if probe != nil {
glog.V(2).Infof("Applying httpGet settings of readinessProbe to health check on port %+v", sp)
glog.V(4).Infof("Applying httpGet settings of readinessProbe to health check on port %+v", sp)
applyProbeSettingsToHC(probe, hc)
}
}
@ -433,6 +442,16 @@ func (b *Backends) Status(name string) string {
return hs.HealthStatus[0].HealthState
}
func applyLegacyHCToHC(existing *compute.HttpHealthCheck, hc *healthchecks.HealthCheck) {
hc.CheckIntervalSec = existing.CheckIntervalSec
hc.HealthyThreshold = existing.HealthyThreshold
hc.Host = existing.Host
hc.Port = existing.Port
hc.RequestPath = existing.RequestPath
hc.TimeoutSec = existing.TimeoutSec
hc.UnhealthyThreshold = existing.UnhealthyThreshold
}
func applyProbeSettingsToHC(p *api_v1.Probe, hc *healthchecks.HealthCheck) {
healthPath := p.Handler.HTTPGet.Path
// GCE requires a leading "/" for health check urls.