diff --git a/pkg/manifests/common.go b/pkg/manifests/common.go index 026116ab..36f5499a 100644 --- a/pkg/manifests/common.go +++ b/pkg/manifests/common.go @@ -114,6 +114,16 @@ func withTypicalReadinessProbe(port int, contain *corev1.Container) *corev1.Cont return copy } +func withLivenessProbeMatchingReadinessNewFailureThresh(contain *corev1.Container, failureThresh int32) *corev1.Container { + copy := withLivenessProbeMatchingReadiness(contain) + + if copy != nil && copy.LivenessProbe != nil { + copy.LivenessProbe.FailureThreshold = failureThresh + } + + return copy +} + func withLivenessProbeMatchingReadiness(contain *corev1.Container) *corev1.Container { copy := contain.DeepCopy() copy.LivenessProbe = copy.ReadinessProbe.DeepCopy() diff --git a/pkg/manifests/common_test.go b/pkg/manifests/common_test.go index f0d6fd46..1b369a3c 100644 --- a/pkg/manifests/common_test.go +++ b/pkg/manifests/common_test.go @@ -61,6 +61,98 @@ func TestHasTopLevelLabels(t *testing.T) { } } +func TestWithLivenessProbeMatchingReadinessNewFailureThresh(t *testing.T) { + cases := []struct { + name string + inputContainer *corev1.Container + failureThresh int32 + expected corev1.Container + }{ + { + name: "empty readiness", + inputContainer: &corev1.Container{ + Name: "name", + }, + failureThresh: 2, + expected: corev1.Container{ + Name: "name", + }, + }, + { + name: "new failure thresh", + inputContainer: &corev1.Container{ + Name: "name", + ReadinessProbe: &corev1.Probe{ + FailureThreshold: 2, + }, + }, + failureThresh: 10, + expected: corev1.Container{ + Name: "name", + ReadinessProbe: &corev1.Probe{ + FailureThreshold: 2, + }, + LivenessProbe: &corev1.Probe{ + FailureThreshold: 10, + }, + }, + }, + { + name: "new failure thresh with other fields", + inputContainer: &corev1.Container{ + Name: "name", + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/healthz", + }, + }, + FailureThreshold: 2, + SuccessThreshold: 1, + TimeoutSeconds: 2, + PeriodSeconds: 12, + InitialDelaySeconds: 3, + }, + }, + failureThresh: 200, + expected: corev1.Container{ + Name: "name", + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/healthz", + }, + }, + FailureThreshold: 2, + SuccessThreshold: 1, + TimeoutSeconds: 2, + PeriodSeconds: 12, + InitialDelaySeconds: 3, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/healthz", + }, + }, + FailureThreshold: 200, + SuccessThreshold: 1, + TimeoutSeconds: 2, + PeriodSeconds: 12, + InitialDelaySeconds: 3, + }, + }, + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + got := withLivenessProbeMatchingReadinessNewFailureThresh(c.inputContainer, c.failureThresh) + require.Equal(t, c.expected, *got) + }) + } +} + func TestGetOwnerRefs(t *testing.T) { cases := []struct { Name string diff --git a/pkg/manifests/fixtures/nginx/full-with-replicas.json b/pkg/manifests/fixtures/nginx/full-with-replicas.json index 60fc7587..1538a6ee 100644 --- a/pkg/manifests/fixtures/nginx/full-with-replicas.json +++ b/pkg/manifests/fixtures/nginx/full-with-replicas.json @@ -510,6 +510,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/full-with-target-cpu.json b/pkg/manifests/fixtures/nginx/full-with-target-cpu.json index 266bc6c1..f0ee587a 100644 --- a/pkg/manifests/fixtures/nginx/full-with-target-cpu.json +++ b/pkg/manifests/fixtures/nginx/full-with-target-cpu.json @@ -510,6 +510,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/full.json b/pkg/manifests/fixtures/nginx/full.json index 33fc1055..5da672a9 100644 --- a/pkg/manifests/fixtures/nginx/full.json +++ b/pkg/manifests/fixtures/nginx/full.json @@ -510,6 +510,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/internal-with-ssl-cert.json b/pkg/manifests/fixtures/nginx/internal-with-ssl-cert.json index 63da82a0..1d0a711f 100644 --- a/pkg/manifests/fixtures/nginx/internal-with-ssl-cert.json +++ b/pkg/manifests/fixtures/nginx/internal-with-ssl-cert.json @@ -510,6 +510,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/internal.json b/pkg/manifests/fixtures/nginx/internal.json index 09b80c10..06de325d 100644 --- a/pkg/manifests/fixtures/nginx/internal.json +++ b/pkg/manifests/fixtures/nginx/internal.json @@ -509,6 +509,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/kube-system.json b/pkg/manifests/fixtures/nginx/kube-system.json index fd045ac8..24fce46e 100644 --- a/pkg/manifests/fixtures/nginx/kube-system.json +++ b/pkg/manifests/fixtures/nginx/kube-system.json @@ -497,6 +497,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/no-ownership.json b/pkg/manifests/fixtures/nginx/no-ownership.json index 33fc1055..5da672a9 100644 --- a/pkg/manifests/fixtures/nginx/no-ownership.json +++ b/pkg/manifests/fixtures/nginx/no-ownership.json @@ -510,6 +510,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/fixtures/nginx/optional-features-disabled.json b/pkg/manifests/fixtures/nginx/optional-features-disabled.json index b8bb65f1..8dc15007 100644 --- a/pkg/manifests/fixtures/nginx/optional-features-disabled.json +++ b/pkg/manifests/fixtures/nginx/optional-features-disabled.json @@ -506,6 +506,18 @@ "memory": "127Mi" } }, + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 10254, + "scheme": "HTTP" + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 1, + "periodSeconds": 5, + "successThreshold": 1, + "failureThreshold": 6 + }, "readinessProbe": { "httpGet": { "path": "/healthz", diff --git a/pkg/manifests/nginx.go b/pkg/manifests/nginx.go index 3432074a..b3046e9d 100644 --- a/pkg/manifests/nginx.go +++ b/pkg/manifests/nginx.go @@ -475,7 +475,7 @@ func newNginxIngressControllerDeployment(conf *config.Config, ingressConfig *Ngi }, }, ServiceAccountName: ingressConfig.ResourceName, - Containers: []corev1.Container{*withPodRefEnvVars(withTypicalReadinessProbe(10254, &corev1.Container{ + Containers: []corev1.Container{*withPodRefEnvVars(withLivenessProbeMatchingReadinessNewFailureThresh(withTypicalReadinessProbe(10254, &corev1.Container{ Name: "controller", Image: path.Join(conf.Registry, "/oss/kubernetes/ingress/nginx-ingress-controller:"+controllerImageTag), Args: deploymentArgs, @@ -499,7 +499,7 @@ func newNginxIngressControllerDeployment(conf *config.Config, ingressConfig *Ngi corev1.ResourceMemory: resource.MustParse("127Mi"), }, }, - }))}, + }), 6))}, }), }, },