Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Add a warning when health checks are overridden
Browse files Browse the repository at this point in the history
Fixes #31

Signed-off-by: Nick Young <ynick@vmware.com>
  • Loading branch information
Nick Young authored and youngnick committed Jan 6, 2020
1 parent 4d72b84 commit 20b0838
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A healthcheck of /healthy2 could not be applied, HTTPProxy only supports a single healthcheck across all services. /healthy is already applied.
28 changes: 28 additions & 0 deletions internal/translator/testdata/health-checks-multiple/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
apiVersion: contour.heptio.com/v1beta1
kind: IngressRoute
metadata:
name: health-check
namespace: default
spec:
virtualhost:
fqdn: health.bar.com
routes:
- match: /
services:
- name: s1-health
port: 80
healthCheck:
path: /healthy
intervalSeconds: 5
timeoutSeconds: 2
unhealthyThresholdCount: 3
healthyThresholdCount: 5
- name: s2-health
port: 80
healthCheck:
path: /healthy2
intervalSeconds: 5
timeoutSeconds: 2
unhealthyThresholdCount: 3
healthyThresholdCount: 5
24 changes: 24 additions & 0 deletions internal/translator/testdata/health-checks-multiple/output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
name: health-check
namespace: default
spec:
routes:
- conditions:
- prefix: /
healthCheckPolicy:
healthyThresholdCount: 5
intervalSeconds: 0
path: /healthy
timeoutSeconds: 2
unhealthyThresholdCount: 3
services:
- name: s1-health
port: 80
- name: s2-health
port: 80
virtualhost:
fqdn: health.bar.com
status: {}
24 changes: 17 additions & 7 deletions internal/translator/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func translateRoute(irRoute irv1beta1.Route, routeLCP string) (hpv1.Route, []str
}

var seenLBStrategy string
var seenHealthCheckPolicy string
for _, irService := range irRoute.Services {

service := hpv1.Service{
Expand All @@ -129,9 +130,9 @@ func translateRoute(irRoute irv1beta1.Route, routeLCP string) (hpv1.Route, []str

if irService.Strategy != "" {
if seenLBStrategy == "" {
seenLBStrategy = irService.Strategy
// Copy the first strategy we encounter into the HP loadbalancerpolicy
// and save that we've seen that one.
seenLBStrategy = irService.Strategy
route.LoadBalancerPolicy = &hpv1.LoadBalancerPolicy{
Strategy: irService.Strategy,
}
Expand All @@ -143,12 +144,21 @@ func translateRoute(irRoute irv1beta1.Route, routeLCP string) (hpv1.Route, []str

}
if irService.HealthCheck != nil {
route.HealthCheckPolicy = &hpv1.HTTPHealthCheckPolicy{
Path: irService.HealthCheck.Path,
Host: irService.HealthCheck.Host,
TimeoutSeconds: irService.HealthCheck.TimeoutSeconds,
UnhealthyThresholdCount: irService.HealthCheck.UnhealthyThresholdCount,
HealthyThresholdCount: irService.HealthCheck.HealthyThresholdCount,
if seenHealthCheckPolicy == "" {
// Copy the first strategy we encounter into the HP loadbalancerpolicy
// and save that we've seen that one.
seenHealthCheckPolicy = irService.HealthCheck.Host + irService.HealthCheck.Path
route.HealthCheckPolicy = &hpv1.HTTPHealthCheckPolicy{
Path: irService.HealthCheck.Path,
Host: irService.HealthCheck.Host,
TimeoutSeconds: irService.HealthCheck.TimeoutSeconds,
UnhealthyThresholdCount: irService.HealthCheck.UnhealthyThresholdCount,
HealthyThresholdCount: irService.HealthCheck.HealthyThresholdCount,
}
} else {
if seenHealthCheckPolicy != irService.HealthCheck.Host+irService.HealthCheck.Path {
warnings = append(warnings, fmt.Sprintf("A healthcheck of %s%s could not be applied, HTTPProxy only supports a single healthcheck across all services. %s is already applied.", irService.HealthCheck.Host, irService.HealthCheck.Path, seenHealthCheckPolicy))
}
}
}
route.Services = append(route.Services, service)
Expand Down

0 comments on commit 20b0838

Please sign in to comment.