Skip to content

Commit

Permalink
internal/e2e: adds test for clusters with healthcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Amarnath <[email protected]>
  • Loading branch information
vaamarnath committed Mar 9, 2019
1 parent d1c6e91 commit 800c112
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions internal/e2e/cds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoy_cluster "github.com/envoyproxy/go-control-plane/envoy/api/v2/cluster"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
"github.com/gogo/protobuf/types"
ingressroutev1 "github.com/heptio/contour/apis/contour/v1beta1"
"github.com/heptio/contour/internal/envoy"
Expand Down Expand Up @@ -712,6 +713,55 @@ func TestClusterLoadBalancerStrategyPerRoute(t *testing.T) {
}, streamCDS(t, cc))
}

func TestClusterWithHealthChecks(t *testing.T) {
rh, cc, done := setup(t)
defer done()

rh.OnAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "kuard",
Namespace: "default",
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{{
Protocol: "TCP",
Port: 80,
TargetPort: intstr.FromInt(8080),
}},
},
})

rh.OnAdd(&ingressroutev1.IngressRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: ingressroutev1.IngressRouteSpec{
VirtualHost: &ingressroutev1.VirtualHost{Fqdn: "www.example.com"},
Routes: []ingressroutev1.Route{{
Match: "/a",
Services: []ingressroutev1.Service{{
Name: "kuard",
Port: 80,
Weight: 90,
HealthCheck: &ingressroutev1.HealthCheck{
Path: "/healthz",
},
}},
}},
},
})

assertEqual(t, &v2.DiscoveryResponse{
VersionInfo: "0",
Resources: []types.Any{
any(t, clusterWithHealthCheck("default/kuard/80/bc862a33ca", "default/kuard", "default_kuard_80", "/healthz", true)),
},
TypeUrl: clusterType,
Nonce: "0",
}, streamCDS(t, cc))
}

func serviceWithAnnotations(ns, name string, annotations map[string]string, ports ...v1.ServicePort) *v1.Service {
return &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -750,3 +800,27 @@ func cluster(name, servicename, statName string) *v2.Cluster {
CommonLbConfig: envoy.ClusterCommonLBConfig(),
}
}

func clusterWithHealthCheck(name, servicename, statName, healthCheckPath string, drainConnOnHostRemoval bool) *v2.Cluster {
c := cluster(name, servicename, statName)
timeout := 2 * time.Second
interval := 10 * time.Second
unhealthyThreshold := types.UInt32Value{Value: 3}
healthyThreshold := types.UInt32Value{Value: 2}
c.HealthChecks = []*core.HealthCheck{
{
Timeout: &timeout,
Interval: &interval,
UnhealthyThreshold: &unhealthyThreshold,
HealthyThreshold: &healthyThreshold,
HealthChecker: &core.HealthCheck_HttpHealthCheck_{
HttpHealthCheck: &core.HealthCheck_HttpHealthCheck{
Host: "contour-envoy-healthcheck",
Path: healthCheckPath,
},
},
},
}
c.DrainConnectionsOnHostRemoval = drainConnOnHostRemoval
return c
}

0 comments on commit 800c112

Please sign in to comment.