Skip to content

Commit

Permalink
Add readinessProbe to target allocator deployment for operator (#2374)
Browse files Browse the repository at this point in the history
* add readiness probe to ta deployment

* add readiness probe to ta e2e

* add readiness probe to ta e2e

* add chlog

---------

Co-authored-by: Jacob Aronoff <[email protected]>
  • Loading branch information
changexd and jaronoff97 authored Nov 21, 2023
1 parent fafd7f0 commit 6ba4453
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .chloggen/ta-readiness-probe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: add readiness probe to target allocator deployment generation

# One or more tracking issues related to the change
issues: [2258]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
25 changes: 17 additions & 8 deletions internal/manifests/targetallocator/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
if otelcol.Spec.TargetAllocator.PrometheusCR.Enabled {
args = append(args, "--enable-prometheus-cr-watcher")
}
readinessProbe := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromInt(8080),
},
},
}
livenessProbe := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Expand All @@ -81,13 +89,14 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem

envVars = append(envVars, proxy.ReadProxyVarsFromEnv()...)
return corev1.Container{
Name: naming.TAContainer(),
Image: image,
Ports: ports,
Env: envVars,
VolumeMounts: volumeMounts,
Resources: otelcol.Spec.TargetAllocator.Resources,
Args: args,
LivenessProbe: livenessProbe,
Name: naming.TAContainer(),
Image: image,
Ports: ports,
Env: envVars,
VolumeMounts: volumeMounts,
Resources: otelcol.Spec.TargetAllocator.Resources,
Args: args,
LivenessProbe: livenessProbe,
ReadinessProbe: readinessProbe,
}
}
40 changes: 40 additions & 0 deletions internal/manifests/targetallocator/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ func TestContainerHasEnvVars(t *testing.T) {
Protocol: corev1.ProtocolTCP,
},
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromInt(8080),
},
},
},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Expand Down Expand Up @@ -287,6 +295,14 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) {
Protocol: corev1.ProtocolTCP,
},
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromInt(8080),
},
},
},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Expand All @@ -303,6 +319,30 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) {
// verify
assert.Equal(t, expected, c)
}
func TestReadinessProbe(t *testing.T) {
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
Enabled: true,
},
},
}
cfg := config.New()
expected := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromInt(8080),
},
},
}

// test
c := Container(cfg, logger, otelcol)

// verify
assert.Equal(t, expected, c.ReadinessProbe)
}
func TestLivenessProbe(t *testing.T) {
// prepare
otelcol := v1alpha1.OpenTelemetryCollector{
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/targetallocator-features/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ spec:
volumeMounts:
- mountPath: /conf
name: ta-internal
readinessProbe:
httpGet:
path: /readyz
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 1
periodSeconds: 10
livenessProbe:
httpGet:
path: /livez
Expand Down

0 comments on commit 6ba4453

Please sign in to comment.