Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide default probe handler httpGet values if not configured in override #998

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion controllers/datadogagent/override/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// Container use to override a corev1.Container with a 2alpha1.DatadogAgentGenericContainer.
Expand Down Expand Up @@ -121,7 +122,7 @@ func overrideContainer(container *corev1.Container, override *v2alpha1.DatadogAg
}

if override.ReadinessProbe != nil {
container.ReadinessProbe = override.ReadinessProbe
container.ReadinessProbe = overrideReadinessProbe(override.ReadinessProbe)
}

if override.LivenessProbe != nil {
Expand Down Expand Up @@ -206,3 +207,13 @@ func overrideAppArmorProfile(containerName commonv1.AgentContainerName, manager
manager.Annotation().AddAnnotation(annotation, *override.AppArmorProfileName)
}
}

func overrideReadinessProbe(readinessProbeOverride *corev1.Probe) *corev1.Probe {
// Add default httpGet.path and httpGet.port if not present in readinessProbe override
if readinessProbeOverride.HTTPGet == nil {
readinessProbeOverride.HTTPGet = &corev1.HTTPGetAction{
Path: common.DefaultReadinessProbeHTTPPath,
Port: intstr.IntOrString{IntVal: common.DefaultAgentHealthPort}}
}
return readinessProbeOverride
}
9 changes: 9 additions & 0 deletions controllers/datadogagent/override/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/DataDog/datadog-operator/apis/datadoghq/common"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
"reflect"
"testing"

Expand Down Expand Up @@ -295,6 +296,14 @@ func TestContainer(t *testing.T) {
assertContainerMatch(t, manager.PodTemplateSpec().Spec.Containers, containerName, func(container corev1.Container) bool {
return reflect.DeepEqual(
&corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/ready",
Port: intstr.IntOrString{
IntVal: 5555,
},
},
},
InitialDelaySeconds: 10,
TimeoutSeconds: 5,
PeriodSeconds: 30,
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
github.com/openshift/api v3.9.0+incompatible
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,6 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDDLDLFresAeYs=
github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/outcaste-io/ristretto v0.2.1 h1:KCItuNIGJZcursqHr3ghO7fc5ddZLEHspL9UR0cQM64=
Expand Down
Loading