Skip to content

Commit

Permalink
apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
fanny-jiang committed Dec 27, 2023
1 parent 3d478c0 commit b9fe6f9
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 2 deletions.
12 changes: 11 additions & 1 deletion controllers/datadogagent/override/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
108 changes: 107 additions & 1 deletion controllers/datadogagent/override/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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)
})
Expand Down

0 comments on commit b9fe6f9

Please sign in to comment.