@@ -27,14 +27,13 @@ import (
2727 "slices"
2828 "strings"
2929 "time"
30-
31- networkingv1 "k8s.io/api/networking/v1"
3230)
3331
3432// Validates that a service is accessible and working correctly. The addr parameter is a
35- // "host:port" string representing the service endpoint.
33+ // "host:port" string representing the service endpoint. The defaultHost parameter is the host to
34+ // use if the verifier does not have a host configured.
3635type verifier interface {
37- verify (ctx context.Context , log logger , addr addresses , ingress * networkingv1. Ingress ) error
36+ verify (ctx context.Context , log logger , addr addresses , defaultHost string ) error
3837}
3938
4039type addresses struct {
@@ -49,12 +48,12 @@ type canaryVerifier struct {
4948 runs int
5049}
5150
52- func (v * canaryVerifier ) verify (ctx context.Context , log logger , addr addresses , ingress * networkingv1. Ingress ) error {
51+ func (v * canaryVerifier ) verify (ctx context.Context , log logger , addr addresses , defaultHost string ) error {
5352 successes := 0
5453 for i := 0 ; i < v .runs ; i ++ {
55- err := v .verifier .verify (ctx , log , addr , ingress )
54+ err := v .verifier .verify (ctx , log , addr , defaultHost )
5655 if err == nil {
57- log .Logf ("Canary verifier run %d/%d succeeded" , i + 1 , v .runs )
56+ log .Logf ("Canary verifier run %d/%d for host %q succeeded" , i + 1 , v .runs , defaultHost )
5857 successes ++
5958 }
6059 }
@@ -106,15 +105,13 @@ type headerMatch struct {
106105 patterns []* maybeNegativePattern
107106}
108107
109- func (v * httpRequestVerifier ) verify (ctx context.Context , log logger , addr addresses , ingress * networkingv1.Ingress ) error {
110- // If the Host field is specified in the test case, use that. Otherwise, default to deriving
111- // the (auto-generated) host from the ingress.
108+ func (v * httpRequestVerifier ) verify (ctx context.Context , log logger , addr addresses , defaultHost string ) error {
112109 host := v .host
113- if host == "" && len ( ingress . Spec . Rules ) > 0 && ingress . Spec . Rules [ 0 ]. Host != "" {
114- host = ingress . Spec . Rules [ 0 ]. Host
110+ if host == "" {
111+ host = defaultHost
115112 }
116113 if host == "" {
117- return fmt .Errorf ("no host specified: set HTTPGetVerifier.Host or ensure ingress has a rule with a host " )
114+ return fmt .Errorf ("no host specified: set httpRequestVerifier.host or provide a defaultHost " )
118115 }
119116
120117 scheme := "http"
@@ -221,7 +218,7 @@ func (v *httpRequestVerifier) verify(ctx context.Context, log logger, addr addre
221218 return fmt .Errorf ("reading HTTP body: %w" , err )
222219 }
223220
224- log .Logf ("Got a healthy response: %s" , body )
221+ log .Logf ("Got a healthy response for host %q : %s" , host , body )
225222
226223 if v .bodyRegex != nil && ! v .bodyRegex .MatchString (string (body )) {
227224 return fmt .Errorf ("unexpected HTTP body: does not match %v" , v .bodyRegex )
0 commit comments