Skip to content

Commit e4a8ac6

Browse files
committed
review
1 parent d6931ef commit e4a8ac6

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pkg/config/dynamic/http_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ type ServerHealthCheck struct {
230230
func (h *ServerHealthCheck) SetDefaults() {
231231
fr := true
232232
h.FollowRedirects = &fr
233+
h.Mode = "http"
233234
}
234235

235236
// +k8s:deepcopy-gen=true

pkg/healthcheck/healthcheck.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,27 +302,28 @@ func checkHealthHTTP(serverURL *url.URL, backend *BackendConfig) error {
302302
func checkHealthGRPC(serverURL *url.URL, backend *BackendConfig) error {
303303
u, err := serverURL.Parse(backend.Path)
304304
if err != nil {
305-
return fmt.Errorf("failed to parse serverURL: %w", err)
305+
return fmt.Errorf("failed to parse server URL: %w", err)
306306
}
307307

308-
grpcSrvAddr := u.Hostname() + ":" + u.Port()
308+
serverAddr := u.Hostname() + ":" + u.Port()
309309

310310
var opts []grpc.DialOption
311311
for _, insecureScheme := range []string{"http", "h2c", ""} {
312312
if backend.Options.Scheme == insecureScheme {
313313
opts = append(opts, grpc.WithInsecure())
314+
break
314315
}
315316
}
316317

317318
ctx, cancel := context.WithTimeout(context.Background(), backend.Options.Timeout)
318319
defer cancel()
319320

320-
conn, err := grpc.DialContext(ctx, grpcSrvAddr, opts...)
321+
conn, err := grpc.DialContext(ctx, serverAddr, opts...)
321322
if err != nil {
322323
if errors.Is(err, context.DeadlineExceeded) {
323-
return fmt.Errorf("fail to connect to %s within %s: %w", grpcSrvAddr, backend.Options.Timeout, err)
324+
return fmt.Errorf("fail to connect to %s within %s: %w", serverAddr, backend.Options.Timeout, err)
324325
}
325-
return fmt.Errorf("fail to connect to %s: %w", grpcSrvAddr, err)
326+
return fmt.Errorf("fail to connect to %s: %w", serverAddr, err)
326327
}
327328
defer func() { _ = conn.Close() }()
328329

pkg/server/service/service.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,10 @@ func buildHealthCheckOptions(ctx context.Context, lb healthcheck.Balancer, backe
361361
}
362362

363363
mode := "http"
364-
if hc.Mode != "" {
365-
if hc.Mode != "grpc" && hc.Mode != "http" {
366-
logger.Errorf("Illegal health check mode for backend '%s'", backend)
367-
} else {
368-
mode = hc.Mode
369-
}
364+
if hc.Mode != "" && hc.Mode != "grpc" && hc.Mode != "http" {
365+
logger.Errorf("Illegal health check mode for backend '%s'", backend)
366+
} else {
367+
mode = hc.Mode
370368
}
371369

372370
return &healthcheck.Options{

0 commit comments

Comments
 (0)