diff --git a/controllers/datadogagent/override/container.go b/controllers/datadogagent/override/container.go index 1b5d175c0..abd723598 100644 --- a/controllers/datadogagent/override/container.go +++ b/controllers/datadogagent/override/container.go @@ -126,7 +126,7 @@ func overrideContainer(container *corev1.Container, override *v2alpha1.DatadogAg } if override.LivenessProbe != nil { - container.LivenessProbe = override.LivenessProbe + container.LivenessProbe = overrideLivenessProbe(override.LivenessProbe) } if override.SecurityContext != nil { @@ -217,3 +217,13 @@ func overrideReadinessProbe(readinessProbeOverride *corev1.Probe) *corev1.Probe } return readinessProbeOverride } + +func overrideLivenessProbe(livenessProbeOverride *corev1.Probe) *corev1.Probe { + // Add default httpGet.path and httpGet.port if not present in livenessProbe override + if livenessProbeOverride.HTTPGet == nil { + livenessProbeOverride.HTTPGet = &corev1.HTTPGetAction{ + Path: common.DefaultLivenessProbeHTTPPath, + Port: intstr.IntOrString{IntVal: common.DefaultAgentHealthPort}} + } + return livenessProbeOverride +} diff --git a/controllers/datadogagent/override/container_test.go b/controllers/datadogagent/override/container_test.go index a01859b02..b5db482af 100644 --- a/controllers/datadogagent/override/container_test.go +++ b/controllers/datadogagent/override/container_test.go @@ -274,7 +274,7 @@ func TestContainer(t *testing.T) { }, }, { - name: "override readiness probe", + name: "override readiness probe with default HTTPGet", containerName: commonv1.CoreAgentContainerName, existingManager: func() *fake.PodTemplateManagers { return fake.NewPodTemplateManagers(t, corev1.PodTemplateSpec{ @@ -296,6 +296,11 @@ func TestContainer(t *testing.T) { assertContainerMatch(t, manager.PodTemplateSpec().Spec.Containers, containerName, func(container corev1.Container) bool { return reflect.DeepEqual( &corev1.Probe{ + InitialDelaySeconds: 10, + TimeoutSeconds: 5, + PeriodSeconds: 30, + SuccessThreshold: 1, + FailureThreshold: 5, ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ Path: "/ready", @@ -304,6 +309,50 @@ func TestContainer(t *testing.T) { }, }, }, + }, + container.ReadinessProbe) + }) + }, + }, + { + name: "override readiness probe", + containerName: commonv1.CoreAgentContainerName, + existingManager: func() *fake.PodTemplateManagers { + return fake.NewPodTemplateManagers(t, corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{*agentContainer}, + }, + }) + }, + override: v2alpha1.DatadogAgentGenericContainer{ + ReadinessProbe: &corev1.Probe{ + InitialDelaySeconds: 10, + TimeoutSeconds: 5, + PeriodSeconds: 30, + SuccessThreshold: 1, + FailureThreshold: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/some/path", + Port: intstr.IntOrString{ + IntVal: 1234, + }, + }, + }, + }, + }, + validateManager: func(t *testing.T, manager *fake.PodTemplateManagers, containerName string) { + assertContainerMatch(t, manager.PodTemplateSpec().Spec.Containers, containerName, func(container corev1.Container) bool { + return reflect.DeepEqual( + &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/some/path", + Port: intstr.IntOrString{ + IntVal: 1234, + }, + }, + }, InitialDelaySeconds: 10, TimeoutSeconds: 5, PeriodSeconds: 30, @@ -314,6 +363,47 @@ func TestContainer(t *testing.T) { }) }, }, + { + name: "override liveness probe with default HTTPGet", + containerName: commonv1.CoreAgentContainerName, + existingManager: func() *fake.PodTemplateManagers { + return fake.NewPodTemplateManagers(t, corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{*agentContainer}, + }, + }) + }, + override: v2alpha1.DatadogAgentGenericContainer{ + LivenessProbe: &corev1.Probe{ + InitialDelaySeconds: 10, + TimeoutSeconds: 5, + PeriodSeconds: 30, + SuccessThreshold: 1, + FailureThreshold: 5, + }, + }, + validateManager: func(t *testing.T, manager *fake.PodTemplateManagers, containerName string) { + assertContainerMatch(t, manager.PodTemplateSpec().Spec.Containers, containerName, func(container corev1.Container) bool { + return reflect.DeepEqual( + &corev1.Probe{ + InitialDelaySeconds: 10, + TimeoutSeconds: 5, + PeriodSeconds: 30, + SuccessThreshold: 1, + FailureThreshold: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/live", + Port: intstr.IntOrString{ + IntVal: 5555, + }, + }, + }, + }, + container.LivenessProbe) + }) + }, + }, { name: "override liveness probe", containerName: commonv1.CoreAgentContainerName, @@ -331,6 +421,14 @@ func TestContainer(t *testing.T) { PeriodSeconds: 30, SuccessThreshold: 1, FailureThreshold: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/some/path", + Port: intstr.IntOrString{ + IntVal: 1234, + }, + }, + }, }, }, validateManager: func(t *testing.T, manager *fake.PodTemplateManagers, containerName string) { @@ -342,6 +440,14 @@ func TestContainer(t *testing.T) { PeriodSeconds: 30, SuccessThreshold: 1, FailureThreshold: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/some/path", + Port: intstr.IntOrString{ + IntVal: 1234, + }, + }, + }, }, container.LivenessProbe) })