Skip to content

Commit

Permalink
Handle HealthCheck for NEG
Browse files Browse the repository at this point in the history
  • Loading branch information
freehan committed Oct 26, 2017
1 parent 1222839 commit eea130b
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 47 deletions.
11 changes: 8 additions & 3 deletions pkg/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ 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)
hc := b.healthChecker.New(sp.Port, sp.Protocol, false)

existingLegacyHC, err := b.healthChecker.GetLegacy(sp.Port)
if err != nil && !utils.IsNotFoundError(err) {
Expand Down Expand Up @@ -482,10 +482,15 @@ func applyProbeSettingsToHC(p *v1.Probe, hc *healthchecks.HealthCheck) {
break
}
}

hc.RequestPath = healthPath
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)
if hc.ForNEG {
// For NEG mode, we can support more aggresive healthcheck interval.
hc.CheckIntervalSec = int64(p.PeriodSeconds)
} else {
// For IG mode, short healthcheck interval may health check flooding problem.
hc.CheckIntervalSec = int64(p.PeriodSeconds) + int64(healthchecks.DefaultHealthCheckInterval.Seconds())
}
}
36 changes: 32 additions & 4 deletions pkg/healthchecks/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package healthchecks

import (
computealpha "google.golang.org/api/compute/v0.alpha"
compute "google.golang.org/api/compute/v1"

"k8s.io/ingress-gce/pkg/utils"
Expand All @@ -26,14 +27,14 @@ import (
func NewFakeHealthCheckProvider() *FakeHealthCheckProvider {
return &FakeHealthCheckProvider{
http: make(map[string]compute.HttpHealthCheck),
generic: make(map[string]compute.HealthCheck),
generic: make(map[string]computealpha.HealthCheck),
}
}

// FakeHealthCheckProvider fakes out health checks.
type FakeHealthCheckProvider struct {
http map[string]compute.HttpHealthCheck
generic map[string]compute.HealthCheck
generic map[string]computealpha.HealthCheck
}

// CreateHttpHealthCheck fakes out http health check creation.
Expand Down Expand Up @@ -77,19 +78,37 @@ func (f *FakeHealthCheckProvider) UpdateHttpHealthCheck(hc *compute.HttpHealthCh
func (f *FakeHealthCheckProvider) CreateHealthCheck(hc *compute.HealthCheck) error {
v := *hc
v.SelfLink = "https://fake.google.com/compute/healthChecks/" + hc.Name
f.generic[hc.Name] = v
alphaHC, _ := toAlphaHealthCheck(hc)
f.generic[hc.Name] = *alphaHC
return nil
}

// CreateHealthCheck fakes out http health check creation.
func (f *FakeHealthCheckProvider) CreateAlphaHealthCheck(hc *computealpha.HealthCheck) error {
v := *hc
v.SelfLink = "https://fake.google.com/compute/healthChecks/" + hc.Name
f.generic[hc.Name] = *hc
return nil
}

// GetHealthCheck fakes out getting a http health check from the cloud.
func (f *FakeHealthCheckProvider) GetHealthCheck(name string) (*compute.HealthCheck, error) {
if hc, found := f.generic[name]; found {
return &hc, nil
v1HC, _ := toV1HealthCheck(&hc)
return v1HC, nil
}

return nil, utils.FakeGoogleAPINotFoundErr()
}

// GetHealthCheck fakes out getting a http health check from the cloud.
func (f *FakeHealthCheckProvider) GetAlphaHealthCheck(name string) (*computealpha.HealthCheck, error) {
if hc, found := f.generic[name]; found {
return &hc, nil
}
return nil, utils.FakeGoogleAPINotFoundErr()
}

// DeleteHealthCheck fakes out deleting a http health check.
func (f *FakeHealthCheckProvider) DeleteHealthCheck(name string) error {
if _, exists := f.generic[name]; !exists {
Expand All @@ -105,6 +124,15 @@ func (f *FakeHealthCheckProvider) UpdateHealthCheck(hc *compute.HealthCheck) err
if _, exists := f.generic[hc.Name]; !exists {
return utils.FakeGoogleAPINotFoundErr()
}
alphaHC, _ := toAlphaHealthCheck(hc)
f.generic[hc.Name] = *alphaHC
return nil
}

func (f *FakeHealthCheckProvider) UpdateAlphaHealthCheck(hc *computealpha.HealthCheck) error {
if _, exists := f.generic[hc.Name]; !exists {
return utils.FakeGoogleAPINotFoundErr()
}

f.generic[hc.Name] = *hc
return nil
Expand Down
Loading

0 comments on commit eea130b

Please sign in to comment.