From bd2533f528153609db8a12a69de7e27263cb99d6 Mon Sep 17 00:00:00 2001 From: darren Date: Sat, 18 Nov 2023 17:50:47 +0800 Subject: [PATCH 1/4] add readiness probe to ta deployment --- .../manifests/targetallocator/container.go | 25 +++++++---- .../targetallocator/container_test.go | 42 +++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/internal/manifests/targetallocator/container.go b/internal/manifests/targetallocator/container.go index 6a6de7e5d8..f0f558c4d9 100644 --- a/internal/manifests/targetallocator/container.go +++ b/internal/manifests/targetallocator/container.go @@ -18,6 +18,7 @@ import ( "github.com/go-logr/logr" "github.com/operator-framework/operator-lib/proxy" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" @@ -69,14 +70,24 @@ 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), + }, + }, + } + 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, + Name: naming.TAContainer(), + Image: image, + Ports: ports, + Env: envVars, + VolumeMounts: volumeMounts, + Resources: otelcol.Spec.TargetAllocator.Resources, + Args: args, + ReadinessProbe: readinessProbe, } } diff --git a/internal/manifests/targetallocator/container_test.go b/internal/manifests/targetallocator/container_test.go index af0ad8478e..6a0576b7ed 100644 --- a/internal/manifests/targetallocator/container_test.go +++ b/internal/manifests/targetallocator/container_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" logf "sigs.k8s.io/controller-runtime/pkg/log" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" @@ -196,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), + }, + }, + }, } // test @@ -278,6 +287,14 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) { Protocol: corev1.ProtocolTCP, }, }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/readyz", + Port: intstr.FromInt(8080), + }, + }, + }, } // test @@ -286,3 +303,28 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) { // verify assert.Equal(t, expected, c) } +func TestReadinessProbe(t *testing.T) { + // prepare + 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) +} From e0f856b80428a165da85a7f6b7e2bc0229c3d6c6 Mon Sep 17 00:00:00 2001 From: darren Date: Sat, 18 Nov 2023 17:54:02 +0800 Subject: [PATCH 2/4] add readiness probe to ta e2e --- tests/e2e/targetallocator-features/00-assert.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/e2e/targetallocator-features/00-assert.yaml b/tests/e2e/targetallocator-features/00-assert.yaml index d53e870704..bc8947a52c 100644 --- a/tests/e2e/targetallocator-features/00-assert.yaml +++ b/tests/e2e/targetallocator-features/00-assert.yaml @@ -70,6 +70,13 @@ spec: volumeMounts: - mountPath: /conf name: ta-internal + ReadinessProbe: + httpGet: + path: /readyz + successThreshold: 1 + failureThreshold: 3 + timeoutSeconds: 1 + periodSeconds: 10 volumes: - configMap: items: From 858f7ecfbe71600077baa3412b861765c1e9282e Mon Sep 17 00:00:00 2001 From: darren Date: Sat, 18 Nov 2023 17:54:02 +0800 Subject: [PATCH 3/4] add readiness probe to ta e2e --- tests/e2e/targetallocator-features/00-assert.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/targetallocator-features/00-assert.yaml b/tests/e2e/targetallocator-features/00-assert.yaml index bc8947a52c..f38dd9e4a6 100644 --- a/tests/e2e/targetallocator-features/00-assert.yaml +++ b/tests/e2e/targetallocator-features/00-assert.yaml @@ -70,7 +70,7 @@ spec: volumeMounts: - mountPath: /conf name: ta-internal - ReadinessProbe: + readinessProbe: httpGet: path: /readyz successThreshold: 1 From b4e35fa82abc983b249283cfbcca1cb231cab4f1 Mon Sep 17 00:00:00 2001 From: Darren Wang Date: Mon, 20 Nov 2023 20:17:43 +0800 Subject: [PATCH 4/4] add chlog --- .chloggen/ta-readiness-probe.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 .chloggen/ta-readiness-probe.yaml diff --git a/.chloggen/ta-readiness-probe.yaml b/.chloggen/ta-readiness-probe.yaml new file mode 100755 index 0000000000..da106345ec --- /dev/null +++ b/.chloggen/ta-readiness-probe.yaml @@ -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: