From 7c665c8e2d2dbf4980362711b8749034210ff1a4 Mon Sep 17 00:00:00 2001 From: Lorcan McVeigh Date: Mon, 1 Mar 2021 13:39:57 +0000 Subject: [PATCH] Fix bug in TS health check --- .../k8s.nginx.org_transportservers.yaml | 2 +- .../crds/k8s.nginx.org_transportservers.yaml | 2 +- .../crds/k8s.nginx.org_transportservers.yaml | 2 +- internal/configs/transportserver.go | 8 +++---- internal/configs/transportserver_test.go | 21 +++++++++++++++++++ pkg/apis/configuration/v1alpha1/types.go | 2 +- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/deployments/common/crds-v1beta1/k8s.nginx.org_transportservers.yaml b/deployments/common/crds-v1beta1/k8s.nginx.org_transportservers.yaml index cb003c4282..431b220e40 100644 --- a/deployments/common/crds-v1beta1/k8s.nginx.org_transportservers.yaml +++ b/deployments/common/crds-v1beta1/k8s.nginx.org_transportservers.yaml @@ -87,7 +87,7 @@ spec: type: boolean fails: type: integer - intervals: + interval: type: string jitter: type: string diff --git a/deployments/common/crds/k8s.nginx.org_transportservers.yaml b/deployments/common/crds/k8s.nginx.org_transportservers.yaml index f4e276ad8e..92165b2cc4 100644 --- a/deployments/common/crds/k8s.nginx.org_transportservers.yaml +++ b/deployments/common/crds/k8s.nginx.org_transportservers.yaml @@ -88,7 +88,7 @@ spec: type: boolean fails: type: integer - intervals: + interval: type: string jitter: type: string diff --git a/deployments/helm-chart/crds/k8s.nginx.org_transportservers.yaml b/deployments/helm-chart/crds/k8s.nginx.org_transportservers.yaml index f4e276ad8e..92165b2cc4 100644 --- a/deployments/helm-chart/crds/k8s.nginx.org_transportservers.yaml +++ b/deployments/helm-chart/crds/k8s.nginx.org_transportservers.yaml @@ -88,7 +88,7 @@ spec: type: boolean fails: type: integer - intervals: + interval: type: string jitter: type: string diff --git a/internal/configs/transportserver.go b/internal/configs/transportserver.go index 51b742b6d9..5896543030 100644 --- a/internal/configs/transportserver.go +++ b/internal/configs/transportserver.go @@ -128,9 +128,9 @@ func generateTransportServerHealthCheck(upstreamHealthCheckName string, upstream hc = generateTransportServerHealthCheckWithDefaults(u) hc.Enabled = u.HealthCheck.Enabled - hc.Interval = generateTime(u.HealthCheck.Interval) - hc.Jitter = generateTime(u.HealthCheck.Jitter) - hc.Timeout = generateTime(u.HealthCheck.Timeout) + hc.Interval = generateTime(u.HealthCheck.Interval, hc.Interval) + hc.Jitter = generateTime(u.HealthCheck.Jitter, hc.Jitter) + hc.Timeout = generateTime(u.HealthCheck.Timeout, hc.Timeout) if u.HealthCheck.Fails > 0 { hc.Fails = u.HealthCheck.Fails @@ -152,7 +152,7 @@ func generateTransportServerHealthCheckWithDefaults(up conf_v1alpha1.Upstream) * return &version2.StreamHealthCheck{ Enabled: false, Timeout: "5s", - Jitter: "0", + Jitter: "0s", Port: up.Port, Interval: "5s", Passes: 1, diff --git a/internal/configs/transportserver_test.go b/internal/configs/transportserver_test.go index 76eacfe026..fa65ccdf53 100644 --- a/internal/configs/transportserver_test.go +++ b/internal/configs/transportserver_test.go @@ -449,6 +449,27 @@ func TestGenerateTransportServerHealthChecks(t *testing.T) { }, msg: "valid 2 health checks", }, + { + upstreams: []conf_v1alpha1.Upstream{ + { + Name: "dns-tcp", + Port: 90, + HealthCheck: &conf_v1alpha1.HealthCheck{ + Enabled: true, + }, + }, + }, + expected: &version2.StreamHealthCheck{ + Enabled: true, + Timeout: "5s", + Jitter: "0s", + Port: 90, + Interval: "5s", + Passes: 1, + Fails: 1, + }, + msg: "return default values for health check", + }, } for _, test := range tests { diff --git a/pkg/apis/configuration/v1alpha1/types.go b/pkg/apis/configuration/v1alpha1/types.go index a70d77f66f..68a3f4494c 100644 --- a/pkg/apis/configuration/v1alpha1/types.go +++ b/pkg/apis/configuration/v1alpha1/types.go @@ -91,7 +91,7 @@ type HealthCheck struct { Timeout string `json:"timeout"` Jitter string `json:"jitter"` Port int `json:"port"` - Interval string `json:"intervals"` + Interval string `json:"interval"` Passes int `json:"passes"` Fails int `json:"fails"` }