Example #1
0
// HealthCheck returns the http readiness probe for the endpoint backing the
// given nodePort. If no probe is found it returns a health check with "" as
// the request path, callers are responsible for swapping this out for the
// appropriate default.
func (t *GCETranslator) HealthCheck(port int64) (*compute.HttpHealthCheck, error) {
	sl, err := t.svcLister.List()
	if err != nil {
		return nil, err
	}
	// Find the label and target port of the one service with the given nodePort
	for _, s := range sl.Items {
		for _, p := range s.Spec.Ports {
			if int32(port) == p.NodePort {
				rp, err := t.getHTTPProbe(s, p.TargetPort)
				if err != nil {
					return nil, err
				}
				if rp == nil {
					glog.Infof("No pod in service %v with node port %v has declared a matching readiness probe for health checks.", s.Name, port)
					break
				}
				healthPath := rp.Handler.HTTPGet.Path
				// GCE requires a leading "/" for health check urls.
				if string(healthPath[0]) != "/" {
					healthPath = fmt.Sprintf("/%v", healthPath)
				}
				host := rp.Handler.HTTPGet.Host
				glog.Infof("Found custom health check for Service %v nodeport %v: %v%v", s.Name, port, host, healthPath)
				return &compute.HttpHealthCheck{
					Port:               port,
					RequestPath:        healthPath,
					Host:               host,
					Description:        "kubernetes L7 health check from readiness probe.",
					CheckIntervalSec:   int64(rp.PeriodSeconds),
					TimeoutSec:         int64(rp.TimeoutSeconds),
					HealthyThreshold:   int64(rp.SuccessThreshold),
					UnhealthyThreshold: int64(rp.FailureThreshold),
					// TODO: include headers after updating compute godep.
				}, nil
			}
		}
	}
	return utils.DefaultHealthCheckTemplate(port), nil
}
Example #2
0
// HealthCheck returns the health check for the given port. If a health check
// isn't stored under the DefaultHealthCheck member, it constructs one.
func (h *FakeHealthCheckGetter) HealthCheck(port int64) (*compute.HttpHealthCheck, error) {
	if h.DefaultHealthCheck == nil {
		return utils.DefaultHealthCheckTemplate(port), nil
	}
	return h.DefaultHealthCheck, nil
}