From f83984788c765ea6f8112781d79326fc5842d8cd Mon Sep 17 00:00:00 2001 From: "hesam.hamdarsi" Date: Tue, 7 May 2024 21:05:39 +0200 Subject: [PATCH 01/10] enable readiness Probe for otel operator Signed-off-by: Janario Oliveira --- apis/v1alpha1/convert.go | 23 +++++++++++++++++-- apis/v1alpha1/opentelemetrycollector_types.go | 2 ++ apis/v1beta1/opentelemetrycollector_types.go | 2 ++ internal/manifests/collector/container.go | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/apis/v1alpha1/convert.go b/apis/v1alpha1/convert.go index fb37e1c781..e38a1d6fed 100644 --- a/apis/v1alpha1/convert.go +++ b/apis/v1alpha1/convert.go @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/conversion" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + v1 "k8s.io/api/core/v1" ) var _ conversion.Convertible = &OpenTelemetryCollector{} @@ -129,6 +130,15 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error }, }, LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), + ReadinessProbe: &v1.Probe{ + InitialDelaySeconds: copy.Spec.ReadinessProbe.InitialDelaySeconds, + TimeoutSeconds: copy.Spec.ReadinessProbe.TimeoutSeconds, + PeriodSeconds: copy.Spec.ReadinessProbe.PeriodSeconds, + SuccessThreshold: copy.Spec.ReadinessProbe.SuccessThreshold, + FailureThreshold: copy.Spec.ReadinessProbe.FailureThreshold, + TerminationGracePeriodSeconds: copy.Spec.ReadinessProbe.TerminationGracePeriodSeconds, + ProbeHandler: *copy.Spec.ReadinessProbe.ProbeHandler.DeepCopy(), + }, Observability: v1beta1.ObservabilitySpec{ Metrics: v1beta1.MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, @@ -352,8 +362,17 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err Lifecycle: copy.Spec.Lifecycle, TerminationGracePeriodSeconds: copy.Spec.TerminationGracePeriodSeconds, LivenessProbe: tov1alpha1Probe(copy.Spec.LivenessProbe), - InitContainers: copy.Spec.InitContainers, - AdditionalContainers: copy.Spec.AdditionalContainers, + ReadinessProbe: &v1.Probe{ + InitialDelaySeconds: copy.Spec.ReadinessProbe.InitialDelaySeconds, + TimeoutSeconds: copy.Spec.ReadinessProbe.TimeoutSeconds, + PeriodSeconds: copy.Spec.ReadinessProbe.PeriodSeconds, + SuccessThreshold: copy.Spec.ReadinessProbe.SuccessThreshold, + FailureThreshold: copy.Spec.ReadinessProbe.FailureThreshold, + TerminationGracePeriodSeconds: copy.Spec.ReadinessProbe.TerminationGracePeriodSeconds, + ProbeHandler: *copy.Spec.ReadinessProbe.ProbeHandler.DeepCopy(), + }, + InitContainers: copy.Spec.InitContainers, + AdditionalContainers: copy.Spec.AdditionalContainers, Observability: ObservabilitySpec{ Metrics: MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index a2c5055fd0..f058a2e841 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -236,6 +236,8 @@ type OpenTelemetryCollectorSpec struct { // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional LivenessProbe *Probe `json:"livenessProbe,omitempty"` + // +optional + ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` // InitContainers allows injecting initContainers to the Collector's pod definition. // These init containers can be used to fetch secrets for injection into the // configuration from external sources, run added checks, etc. Any errors during the execution of diff --git a/apis/v1beta1/opentelemetrycollector_types.go b/apis/v1beta1/opentelemetrycollector_types.go index 4421165944..7ad6c6fa94 100644 --- a/apis/v1beta1/opentelemetrycollector_types.go +++ b/apis/v1beta1/opentelemetrycollector_types.go @@ -103,6 +103,8 @@ type OpenTelemetryCollectorSpec struct { // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional LivenessProbe *Probe `json:"livenessProbe,omitempty"` + // +optional + ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` // ObservabilitySpec defines how telemetry data gets handled. // diff --git a/internal/manifests/collector/container.go b/internal/manifests/collector/container.go index d0585ff9d8..3df4040ad8 100644 --- a/internal/manifests/collector/container.go +++ b/internal/manifests/collector/container.go @@ -152,6 +152,8 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme } } + var readinessProbe = otelcol.Spec.ReadinessProbe + envVars = append(envVars, proxy.ReadProxyVarsFromEnv()...) return corev1.Container{ Name: naming.Container(), @@ -165,6 +167,7 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme Resources: otelcol.Spec.Resources, SecurityContext: otelcol.Spec.SecurityContext, LivenessProbe: livenessProbe, + ReadinessProbe: readinessProbe, Lifecycle: otelcol.Spec.Lifecycle, } } From 166338f8f3d196b5e7e585f1ef68dbb917700b79 Mon Sep 17 00:00:00 2001 From: "hesam.hamdarsi" Date: Wed, 8 May 2024 12:55:37 +0200 Subject: [PATCH 02/10] generate CRD and controller changes Signed-off-by: Janario Oliveira --- apis/v1alpha1/zz_generated.deepcopy.go | 5 + apis/v1beta1/zz_generated.deepcopy.go | 5 + ...ntelemetry.io_opentelemetrycollectors.yaml | 127 ++++++++ ...ntelemetry.io_opentelemetrycollectors.yaml | 127 ++++++++ docs/api.md | 295 ++++++++++++++++++ 5 files changed, 559 insertions(+) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 8f47cb64dc..29d845462e 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -911,6 +911,11 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp *out = new(Probe) (*in).DeepCopyInto(*out) } + if in.ReadinessProbe != nil { + in, out := &in.ReadinessProbe, &out.ReadinessProbe + *out = new(v1.Probe) + (*in).DeepCopyInto(*out) + } if in.InitContainers != nil { in, out := &in.InitContainers, &out.InitContainers *out = make([]v1.Container, len(*in)) diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index c5e574127c..14a8855e3d 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -306,6 +306,11 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp *out = new(Probe) (*in).DeepCopyInto(*out) } + if in.ReadinessProbe != nil { + in, out := &in.ReadinessProbe, &out.ReadinessProbe + *out = new(v1.Probe) + (*in).DeepCopyInto(*out) + } out.Observability = in.Observability if in.ConfigMaps != nil { in, out := &in.ConfigMaps, &out.ConfigMaps diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 5688544892..aa4066f338 100644 --- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -2340,6 +2340,133 @@ spec: x-kubernetes-list-type: atomic priorityClassName: type: string + readinessProbe: + description: Probe describes a health check to be performed against + a container to determine whether it is alive or ready to receive + traffic. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside + the container, the working directory for the command is + root ('/') in the container's filesystem. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the probe to be + considered failed after having succeeded. Defaults to 3. Minimum + value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving a GRPC port. + properties: + port: + description: Port number of the gRPC service. Number must + be in the range 1 to 65535. + format: int32 + type: integer + service: + description: Service is the name of the service to place in + the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod + IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows + repeated headers. + items: + description: HTTPHeader describes a custom header to be + used in HTTP probes + properties: + name: + description: The header field name. This will be canonicalized + upon output, so case-variant names will be understood + as the same header. + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. + Number must be in the range 1 to 65535. Name must be an + IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults + to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container has started + before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the probe. Default + to 10 seconds. Minimum value is 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the probe to be + considered successful after having failed. Defaults to 1. Must + be 1 for liveness and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving a TCP port. + properties: + host: + description: 'Optional: Host name to connect to, defaults + to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. + Number must be in the range 1 to 65535. Name must be an + IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod needs to terminate + gracefully upon probe failure. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the probe times out. + Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object replicas: format: int32 type: integer diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 03a1360bfa..17dc3c6e0c 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -2326,6 +2326,133 @@ spec: x-kubernetes-list-type: atomic priorityClassName: type: string + readinessProbe: + description: Probe describes a health check to be performed against + a container to determine whether it is alive or ready to receive + traffic. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside + the container, the working directory for the command is + root ('/') in the container's filesystem. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the probe to be + considered failed after having succeeded. Defaults to 3. Minimum + value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving a GRPC port. + properties: + port: + description: Port number of the gRPC service. Number must + be in the range 1 to 65535. + format: int32 + type: integer + service: + description: Service is the name of the service to place in + the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod + IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows + repeated headers. + items: + description: HTTPHeader describes a custom header to be + used in HTTP probes + properties: + name: + description: The header field name. This will be canonicalized + upon output, so case-variant names will be understood + as the same header. + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. + Number must be in the range 1 to 65535. Name must be an + IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults + to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container has started + before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the probe. Default + to 10 seconds. Minimum value is 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the probe to be + considered successful after having failed. Defaults to 1. Must + be 1 for liveness and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving a TCP port. + properties: + host: + description: 'Optional: Host name to connect to, defaults + to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. + Number must be in the range 1 to 65535. Name must be an + IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod needs to terminate + gracefully upon probe failure. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the probe times out. + Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object replicas: format: int32 type: integer diff --git a/docs/api.md b/docs/api.md index ab95401ad4..beeccbf962 100644 --- a/docs/api.md +++ b/docs/api.md @@ -11358,6 +11358,13 @@ If not specified, the pod priority will be default or zero if there is no default.
false + + readinessProbe + object + + Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
+ + false replicas integer @@ -21110,6 +21117,294 @@ More info: https://kubernetes.io/docs/concepts/services-networking/service/#defi +### OpenTelemetryCollector.spec.readinessProbe +[↩ Parent](#opentelemetrycollectorspec) + + + +Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
execobject + Exec specifies the action to take.
+
false
failureThresholdinteger + Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1.
+
+ Format: int32
+
false
grpcobject + GRPC specifies an action involving a GRPC port.
+
false
httpGetobject + HTTPGet specifies the http request to perform.
+
false
initialDelaySecondsinteger + Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
+
+ Format: int32
+
false
periodSecondsinteger + How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1.
+
+ Format: int32
+
false
successThresholdinteger + Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
+
+ Format: int32
+
false
tcpSocketobject + TCPSocket specifies an action involving a TCP port.
+
false
terminationGracePeriodSecondsinteger + Optional duration in seconds the pod needs to terminate gracefully upon probe failure.
+
+ Format: int64
+
false
timeoutSecondsinteger + Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
+
+ Format: int32
+
false
+ + +### OpenTelemetryCollector.spec.readinessProbe.exec +[↩ Parent](#opentelemetrycollectorspecreadinessprobe) + + + +Exec specifies the action to take. + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
command[]string + Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem.
+
false
+ + +### OpenTelemetryCollector.spec.readinessProbe.grpc +[↩ Parent](#opentelemetrycollectorspecreadinessprobe) + + + +GRPC specifies an action involving a GRPC port. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
portinteger + Port number of the gRPC service. Number must be in the range 1 to 65535.
+
+ Format: int32
+
true
servicestring + Service is the name of the service to place in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).
+
false
+ + +### OpenTelemetryCollector.spec.readinessProbe.httpGet +[↩ Parent](#opentelemetrycollectorspecreadinessprobe) + + + +HTTPGet specifies the http request to perform. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
portint or string + Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
+
true
hoststring + Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead.
+
false
httpHeaders[]object + Custom headers to set in the request. HTTP allows repeated headers.
+
false
pathstring + Path to access on the HTTP server.
+
false
schemestring + Scheme to use for connecting to the host. Defaults to HTTP.
+
false
+ + +### OpenTelemetryCollector.spec.readinessProbe.httpGet.httpHeaders[index] +[↩ Parent](#opentelemetrycollectorspecreadinessprobehttpget) + + + +HTTPHeader describes a custom header to be used in HTTP probes + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.
+
true
valuestring + The header field value
+
true
+ + +### OpenTelemetryCollector.spec.readinessProbe.tcpSocket +[↩ Parent](#opentelemetrycollectorspecreadinessprobe) + + + +TCPSocket specifies an action involving a TCP port. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
portint or string + Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
+
true
hoststring + Optional: Host name to connect to, defaults to the pod IP.
+
false
+ + ### OpenTelemetryCollector.spec.resources [↩ Parent](#opentelemetrycollectorspec) From 270cc6d6e6e408705bfbf1c93221e52ea884f482 Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Thu, 9 May 2024 16:53:19 +0200 Subject: [PATCH 03/10] Adjusted code to be similar to Liveness logic Signed-off-by: Janario Oliveira --- apis/v1alpha1/convert.go | 25 ++----- apis/v1alpha1/convert_test.go | 3 + apis/v1alpha1/opentelemetrycollector_types.go | 6 +- apis/v1beta1/collector_webhook.go | 20 ++++++ apis/v1beta1/collector_webhook_test.go | 66 +++++++++++++++++++ apis/v1beta1/opentelemetrycollector_types.go | 6 +- internal/manifests/collector/container.go | 17 +++-- .../manifests/collector/container_test.go | 27 ++++++++ 8 files changed, 141 insertions(+), 29 deletions(-) diff --git a/apis/v1alpha1/convert.go b/apis/v1alpha1/convert.go index e38a1d6fed..aa67903cb9 100644 --- a/apis/v1alpha1/convert.go +++ b/apis/v1alpha1/convert.go @@ -25,7 +25,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/conversion" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" - v1 "k8s.io/api/core/v1" ) var _ conversion.Convertible = &OpenTelemetryCollector{} @@ -130,15 +129,7 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error }, }, LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), - ReadinessProbe: &v1.Probe{ - InitialDelaySeconds: copy.Spec.ReadinessProbe.InitialDelaySeconds, - TimeoutSeconds: copy.Spec.ReadinessProbe.TimeoutSeconds, - PeriodSeconds: copy.Spec.ReadinessProbe.PeriodSeconds, - SuccessThreshold: copy.Spec.ReadinessProbe.SuccessThreshold, - FailureThreshold: copy.Spec.ReadinessProbe.FailureThreshold, - TerminationGracePeriodSeconds: copy.Spec.ReadinessProbe.TerminationGracePeriodSeconds, - ProbeHandler: *copy.Spec.ReadinessProbe.ProbeHandler.DeepCopy(), - }, + ReadinessProbe: tov1beta1Probe(copy.Spec.ReadinessProbe), Observability: v1beta1.ObservabilitySpec{ Metrics: v1beta1.MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, @@ -362,17 +353,9 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err Lifecycle: copy.Spec.Lifecycle, TerminationGracePeriodSeconds: copy.Spec.TerminationGracePeriodSeconds, LivenessProbe: tov1alpha1Probe(copy.Spec.LivenessProbe), - ReadinessProbe: &v1.Probe{ - InitialDelaySeconds: copy.Spec.ReadinessProbe.InitialDelaySeconds, - TimeoutSeconds: copy.Spec.ReadinessProbe.TimeoutSeconds, - PeriodSeconds: copy.Spec.ReadinessProbe.PeriodSeconds, - SuccessThreshold: copy.Spec.ReadinessProbe.SuccessThreshold, - FailureThreshold: copy.Spec.ReadinessProbe.FailureThreshold, - TerminationGracePeriodSeconds: copy.Spec.ReadinessProbe.TerminationGracePeriodSeconds, - ProbeHandler: *copy.Spec.ReadinessProbe.ProbeHandler.DeepCopy(), - }, - InitContainers: copy.Spec.InitContainers, - AdditionalContainers: copy.Spec.AdditionalContainers, + ReadinessProbe: tov1alpha1Probe(copy.Spec.ReadinessProbe), + InitContainers: copy.Spec.InitContainers, + AdditionalContainers: copy.Spec.AdditionalContainers, Observability: ObservabilitySpec{ Metrics: MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, diff --git a/apis/v1alpha1/convert_test.go b/apis/v1alpha1/convert_test.go index ba8bb063d0..0510fcea60 100644 --- a/apis/v1alpha1/convert_test.go +++ b/apis/v1alpha1/convert_test.go @@ -266,6 +266,9 @@ func Test_tov1beta1AndBack(t *testing.T) { LivenessProbe: &Probe{ PeriodSeconds: &one, }, + ReadinessProbe: &Probe{ + PeriodSeconds: &one, + }, InitContainers: []v1.Container{ { Name: "init", diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index f058a2e841..8ee67cb5de 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -236,8 +236,10 @@ type OpenTelemetryCollectorSpec struct { // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional LivenessProbe *Probe `json:"livenessProbe,omitempty"` + // Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. + // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional - ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` + ReadinessProbe *Probe `json:"readinessProbe,omitempty"` // InitContainers allows injecting initContainers to the Collector's pod definition. // These init containers can be used to fetch secrets for injection into the // configuration from external sources, run added checks, etc. Any errors during the execution of @@ -553,7 +555,7 @@ type ObservabilitySpec struct { Metrics MetricsConfigSpec `json:"metrics,omitempty"` } -// Probe defines the OpenTelemetry's pod probe config. Only Liveness probe is supported currently. +// Probe defines the OpenTelemetry's pod probe config. type Probe struct { // Number of seconds after the container has started before liveness probes are initiated. // Defaults to 0 seconds. Minimum value is 0. diff --git a/apis/v1beta1/collector_webhook.go b/apis/v1beta1/collector_webhook.go index 8780ffa7e3..941c0de3f3 100644 --- a/apis/v1beta1/collector_webhook.go +++ b/apis/v1beta1/collector_webhook.go @@ -309,6 +309,26 @@ func (c CollectorWebhook) validate(ctx context.Context, r *OpenTelemetryCollecto return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe TerminationGracePeriodSeconds configuration is incorrect. TerminationGracePeriodSeconds should be greater than or equal to 1") } } + if r.Spec.ReadinessProbe != nil { + if r.Spec.ReadinessProbe.InitialDelaySeconds != nil && *r.Spec.ReadinessProbe.InitialDelaySeconds < 0 { + return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe InitialDelaySeconds configuration is incorrect. InitialDelaySeconds should be greater than or equal to 0") + } + if r.Spec.ReadinessProbe.PeriodSeconds != nil && *r.Spec.ReadinessProbe.PeriodSeconds < 1 { + return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe PeriodSeconds configuration is incorrect. PeriodSeconds should be greater than or equal to 1") + } + if r.Spec.ReadinessProbe.TimeoutSeconds != nil && *r.Spec.ReadinessProbe.TimeoutSeconds < 1 { + return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe TimeoutSeconds configuration is incorrect. TimeoutSeconds should be greater than or equal to 1") + } + if r.Spec.ReadinessProbe.SuccessThreshold != nil && *r.Spec.ReadinessProbe.SuccessThreshold < 1 { + return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe SuccessThreshold configuration is incorrect. SuccessThreshold should be greater than or equal to 1") + } + if r.Spec.ReadinessProbe.FailureThreshold != nil && *r.Spec.ReadinessProbe.FailureThreshold < 1 { + return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe FailureThreshold configuration is incorrect. FailureThreshold should be greater than or equal to 1") + } + if r.Spec.ReadinessProbe.TerminationGracePeriodSeconds != nil && *r.Spec.ReadinessProbe.TerminationGracePeriodSeconds < 1 { + return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe TerminationGracePeriodSeconds configuration is incorrect. TerminationGracePeriodSeconds should be greater than or equal to 1") + } + } // validate updateStrategy for DaemonSet if r.Spec.Mode != ModeDaemonSet && len(r.Spec.DaemonSetUpdateStrategy.Type) > 0 { diff --git a/apis/v1beta1/collector_webhook_test.go b/apis/v1beta1/collector_webhook_test.go index 99d127b3ef..b3b8ade472 100644 --- a/apis/v1beta1/collector_webhook_test.go +++ b/apis/v1beta1/collector_webhook_test.go @@ -1026,6 +1026,17 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, expectedErr: "the OpenTelemetry Spec LivenessProbe InitialDelaySeconds configuration is incorrect", }, + { + name: "invalid InitialDelaySeconds readiness", + otelcol: OpenTelemetryCollector{ + Spec: OpenTelemetryCollectorSpec{ + ReadinessProbe: &Probe{ + InitialDelaySeconds: &minusOne, + }, + }, + }, + expectedErr: "the OpenTelemetry Spec ReadinessProbe InitialDelaySeconds configuration is incorrect", + }, { name: "invalid PeriodSeconds", otelcol: OpenTelemetryCollector{ @@ -1037,6 +1048,17 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, expectedErr: "the OpenTelemetry Spec LivenessProbe PeriodSeconds configuration is incorrect", }, + { + name: "invalid PeriodSeconds readiness", + otelcol: OpenTelemetryCollector{ + Spec: OpenTelemetryCollectorSpec{ + ReadinessProbe: &Probe{ + PeriodSeconds: &zero, + }, + }, + }, + expectedErr: "the OpenTelemetry Spec ReadinessProbe PeriodSeconds configuration is incorrect", + }, { name: "invalid TimeoutSeconds", otelcol: OpenTelemetryCollector{ @@ -1048,6 +1070,17 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, expectedErr: "the OpenTelemetry Spec LivenessProbe TimeoutSeconds configuration is incorrect", }, + { + name: "invalid TimeoutSeconds readiness", + otelcol: OpenTelemetryCollector{ + Spec: OpenTelemetryCollectorSpec{ + ReadinessProbe: &Probe{ + TimeoutSeconds: &zero, + }, + }, + }, + expectedErr: "the OpenTelemetry Spec ReadinessProbe TimeoutSeconds configuration is incorrect", + }, { name: "invalid SuccessThreshold", otelcol: OpenTelemetryCollector{ @@ -1059,6 +1092,17 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, expectedErr: "the OpenTelemetry Spec LivenessProbe SuccessThreshold configuration is incorrect", }, + { + name: "invalid SuccessThreshold readiness", + otelcol: OpenTelemetryCollector{ + Spec: OpenTelemetryCollectorSpec{ + ReadinessProbe: &Probe{ + SuccessThreshold: &zero, + }, + }, + }, + expectedErr: "the OpenTelemetry Spec ReadinessProbe SuccessThreshold configuration is incorrect", + }, { name: "invalid FailureThreshold", otelcol: OpenTelemetryCollector{ @@ -1070,6 +1114,17 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, expectedErr: "the OpenTelemetry Spec LivenessProbe FailureThreshold configuration is incorrect", }, + { + name: "invalid FailureThreshold readiness", + otelcol: OpenTelemetryCollector{ + Spec: OpenTelemetryCollectorSpec{ + ReadinessProbe: &Probe{ + FailureThreshold: &zero, + }, + }, + }, + expectedErr: "the OpenTelemetry Spec ReadinessProbe FailureThreshold configuration is incorrect", + }, { name: "invalid TerminationGracePeriodSeconds", otelcol: OpenTelemetryCollector{ @@ -1081,6 +1136,17 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, expectedErr: "the OpenTelemetry Spec LivenessProbe TerminationGracePeriodSeconds configuration is incorrect", }, + { + name: "invalid TerminationGracePeriodSeconds readiness", + otelcol: OpenTelemetryCollector{ + Spec: OpenTelemetryCollectorSpec{ + ReadinessProbe: &Probe{ + TerminationGracePeriodSeconds: &zero64, + }, + }, + }, + expectedErr: "the OpenTelemetry Spec ReadinessProbe TerminationGracePeriodSeconds configuration is incorrect", + }, { name: "invalid AdditionalContainers", otelcol: OpenTelemetryCollector{ diff --git a/apis/v1beta1/opentelemetrycollector_types.go b/apis/v1beta1/opentelemetrycollector_types.go index 7ad6c6fa94..141178895f 100644 --- a/apis/v1beta1/opentelemetrycollector_types.go +++ b/apis/v1beta1/opentelemetrycollector_types.go @@ -103,8 +103,10 @@ type OpenTelemetryCollectorSpec struct { // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional LivenessProbe *Probe `json:"livenessProbe,omitempty"` + // Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. + // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional - ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` + ReadinessProbe *Probe `json:"readinessProbe,omitempty"` // ObservabilitySpec defines how telemetry data gets handled. // @@ -208,7 +210,7 @@ type TargetAllocatorEmbedded struct { PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"` } -// Probe defines the OpenTelemetry's pod probe config. Only Liveness probe is supported currently. +// Probe defines the OpenTelemetry's pod probe config. type Probe struct { // Number of seconds after the container has started before liveness probes are initiated. // Defaults to 0 seconds. Minimum value is 0. diff --git a/internal/manifests/collector/container.go b/internal/manifests/collector/container.go index 3df4040ad8..193596f038 100644 --- a/internal/manifests/collector/container.go +++ b/internal/manifests/collector/container.go @@ -140,8 +140,9 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme } var livenessProbe *corev1.Probe + var readinessProbe *corev1.Probe if configFromString, err := adapters.ConfigFromString(configYaml); err == nil { - if probe, err := getLivenessProbe(configFromString, otelcol.Spec.LivenessProbe); err == nil { + if probe, err := getProbe(configFromString, otelcol.Spec.LivenessProbe); err == nil { livenessProbe = probe } else if errors.Is(err, adapters.ErrNoServiceExtensions) { logger.V(4).Info("extensions not configured, skipping liveness probe creation") @@ -150,9 +151,17 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme } else { logger.Error(err, "cannot create liveness probe.") } - } - var readinessProbe = otelcol.Spec.ReadinessProbe + if probe, err := getProbe(configFromString, otelcol.Spec.ReadinessProbe); err == nil { + readinessProbe = probe + } else if errors.Is(err, adapters.ErrNoServiceExtensions) { + logger.V(4).Info("extensions not configured, skipping readiness probe creation") + } else if errors.Is(err, adapters.ErrNoServiceExtensionHealthCheck) { + logger.V(4).Info("healthcheck extension not configured, skipping readiness probe creation") + } else { + logger.Error(err, "cannot create readiness probe.") + } + } envVars = append(envVars, proxy.ReadProxyVarsFromEnv()...) return corev1.Container{ @@ -230,7 +239,7 @@ func portMapToList(portMap map[string]corev1.ContainerPort) []corev1.ContainerPo return ports } -func getLivenessProbe(config map[interface{}]interface{}, probeConfig *v1beta1.Probe) (*corev1.Probe, error) { +func getProbe(config map[interface{}]interface{}, probeConfig *v1beta1.Probe) (*corev1.Probe, error) { probe, err := adapters.ConfigToContainerProbe(config) if err != nil { return nil, err diff --git a/internal/manifests/collector/container_test.go b/internal/manifests/collector/container_test.go index e2cd24639d..5b6be02367 100644 --- a/internal/manifests/collector/container_test.go +++ b/internal/manifests/collector/container_test.go @@ -728,6 +728,14 @@ service: FailureThreshold: &failureThreshold, TerminationGracePeriodSeconds: &terminationGracePeriodSeconds, }, + ReadinessProbe: &v1beta1.Probe{ + InitialDelaySeconds: &initialDelaySeconds, + TimeoutSeconds: &timeoutSeconds, + PeriodSeconds: &periodSeconds, + SuccessThreshold: &successThreshold, + FailureThreshold: &failureThreshold, + TerminationGracePeriodSeconds: &terminationGracePeriodSeconds, + }, }, } cfg := config.New() @@ -736,6 +744,7 @@ service: c := Container(cfg, logger, otelcol, true) // verify + // liveness assert.Equal(t, "/", c.LivenessProbe.HTTPGet.Path) assert.Equal(t, int32(13133), c.LivenessProbe.HTTPGet.Port.IntVal) assert.Equal(t, "", c.LivenessProbe.HTTPGet.Host) @@ -746,6 +755,18 @@ service: assert.Equal(t, successThreshold, c.LivenessProbe.SuccessThreshold) assert.Equal(t, failureThreshold, c.LivenessProbe.FailureThreshold) assert.Equal(t, terminationGracePeriodSeconds, *c.LivenessProbe.TerminationGracePeriodSeconds) + + // rediness + assert.Equal(t, "/", c.ReadinessProbe.HTTPGet.Path) + assert.Equal(t, int32(13133), c.ReadinessProbe.HTTPGet.Port.IntVal) + assert.Equal(t, "", c.ReadinessProbe.HTTPGet.Host) + + assert.Equal(t, initialDelaySeconds, c.ReadinessProbe.InitialDelaySeconds) + assert.Equal(t, timeoutSeconds, c.ReadinessProbe.TimeoutSeconds) + assert.Equal(t, periodSeconds, c.ReadinessProbe.PeriodSeconds) + assert.Equal(t, successThreshold, c.ReadinessProbe.SuccessThreshold) + assert.Equal(t, failureThreshold, c.ReadinessProbe.FailureThreshold) + assert.Equal(t, terminationGracePeriodSeconds, *c.ReadinessProbe.TerminationGracePeriodSeconds) } func TestContainerProbeEmptyConfig(t *testing.T) { @@ -758,6 +779,7 @@ func TestContainerProbeEmptyConfig(t *testing.T) { service: extensions: [health_check]`), LivenessProbe: &v1beta1.Probe{}, + ReadinessProbe: &v1beta1.Probe{}, }, } cfg := config.New() @@ -766,9 +788,14 @@ service: c := Container(cfg, logger, otelcol, true) // verify + // liveness assert.Equal(t, "/", c.LivenessProbe.HTTPGet.Path) assert.Equal(t, int32(13133), c.LivenessProbe.HTTPGet.Port.IntVal) assert.Equal(t, "", c.LivenessProbe.HTTPGet.Host) + // readiness + assert.Equal(t, "/", c.ReadinessProbe.HTTPGet.Path) + assert.Equal(t, int32(13133), c.ReadinessProbe.HTTPGet.Port.IntVal) + assert.Equal(t, "", c.ReadinessProbe.HTTPGet.Host) } func TestContainerProbeNoConfig(t *testing.T) { From 6f19ccb8d8dcc2108f5558916beca0f4353be7bb Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Thu, 9 May 2024 16:53:36 +0200 Subject: [PATCH 04/10] Generated manifests Signed-off-by: Janario Oliveira --- apis/v1alpha1/zz_generated.deepcopy.go | 2 +- apis/v1beta1/zz_generated.deepcopy.go | 2 +- ...ntelemetry.io_opentelemetrycollectors.yaml | 127 ++----- ...ntelemetry.io_opentelemetrycollectors.yaml | 127 ++----- docs/api.md | 347 +++++++----------- 5 files changed, 169 insertions(+), 436 deletions(-) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 29d845462e..e6fd9f18a3 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -913,7 +913,7 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } if in.ReadinessProbe != nil { in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(v1.Probe) + *out = new(Probe) (*in).DeepCopyInto(*out) } if in.InitContainers != nil { diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 14a8855e3d..9690ef897d 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -308,7 +308,7 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } if in.ReadinessProbe != nil { in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(v1.Probe) + *out = new(Probe) (*in).DeepCopyInto(*out) } out.Observability = in.Observability diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml index aa4066f338..fc9472d64f 100644 --- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -2341,129 +2341,23 @@ spec: priorityClassName: type: string readinessProbe: - description: Probe describes a health check to be performed against - a container to determine whether it is alive or ready to receive - traffic. properties: - exec: - description: Exec specifies the action to take. - properties: - command: - description: Command is the command line to execute inside - the container, the working directory for the command is - root ('/') in the container's filesystem. - items: - type: string - type: array - type: object failureThreshold: - description: Minimum consecutive failures for the probe to be - considered failed after having succeeded. Defaults to 3. Minimum - value is 1. format: int32 type: integer - grpc: - description: GRPC specifies an action involving a GRPC port. - properties: - port: - description: Port number of the gRPC service. Number must - be in the range 1 to 65535. - format: int32 - type: integer - service: - description: Service is the name of the service to place in - the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md). - type: string - required: - - port - type: object - httpGet: - description: HTTPGet specifies the http request to perform. - properties: - host: - description: Host name to connect to, defaults to the pod - IP. You probably want to set "Host" in httpHeaders instead. - type: string - httpHeaders: - description: Custom headers to set in the request. HTTP allows - repeated headers. - items: - description: HTTPHeader describes a custom header to be - used in HTTP probes - properties: - name: - description: The header field name. This will be canonicalized - upon output, so case-variant names will be understood - as the same header. - type: string - value: - description: The header field value - type: string - required: - - name - - value - type: object - type: array - path: - description: Path to access on the HTTP server. - type: string - port: - anyOf: - - type: integer - - type: string - description: Name or number of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - scheme: - description: Scheme to use for connecting to the host. Defaults - to HTTP. - type: string - required: - - port - type: object initialDelaySeconds: - description: 'Number of seconds after the container has started - before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer periodSeconds: - description: How often (in seconds) to perform the probe. Default - to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: - description: Minimum consecutive successes for the probe to be - considered successful after having failed. Defaults to 1. Must - be 1 for liveness and startup. Minimum value is 1. format: int32 type: integer - tcpSocket: - description: TCPSocket specifies an action involving a TCP port. - properties: - host: - description: 'Optional: Host name to connect to, defaults - to the pod IP.' - type: string - port: - anyOf: - - type: integer - - type: string - description: Number or name of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - required: - - port - type: object terminationGracePeriodSeconds: - description: Optional duration in seconds the pod needs to terminate - gracefully upon probe failure. format: int64 type: integer timeoutSeconds: - description: 'Number of seconds after which the probe times out. - Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -6781,6 +6675,27 @@ spec: x-kubernetes-list-type: atomic priorityClassName: type: string + readinessProbe: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + successThreshold: + format: int32 + type: integer + terminationGracePeriodSeconds: + format: int64 + type: integer + timeoutSeconds: + format: int32 + type: integer + type: object replicas: format: int32 type: integer diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 17dc3c6e0c..1d30728f3e 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -2327,129 +2327,23 @@ spec: priorityClassName: type: string readinessProbe: - description: Probe describes a health check to be performed against - a container to determine whether it is alive or ready to receive - traffic. properties: - exec: - description: Exec specifies the action to take. - properties: - command: - description: Command is the command line to execute inside - the container, the working directory for the command is - root ('/') in the container's filesystem. - items: - type: string - type: array - type: object failureThreshold: - description: Minimum consecutive failures for the probe to be - considered failed after having succeeded. Defaults to 3. Minimum - value is 1. format: int32 type: integer - grpc: - description: GRPC specifies an action involving a GRPC port. - properties: - port: - description: Port number of the gRPC service. Number must - be in the range 1 to 65535. - format: int32 - type: integer - service: - description: Service is the name of the service to place in - the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md). - type: string - required: - - port - type: object - httpGet: - description: HTTPGet specifies the http request to perform. - properties: - host: - description: Host name to connect to, defaults to the pod - IP. You probably want to set "Host" in httpHeaders instead. - type: string - httpHeaders: - description: Custom headers to set in the request. HTTP allows - repeated headers. - items: - description: HTTPHeader describes a custom header to be - used in HTTP probes - properties: - name: - description: The header field name. This will be canonicalized - upon output, so case-variant names will be understood - as the same header. - type: string - value: - description: The header field value - type: string - required: - - name - - value - type: object - type: array - path: - description: Path to access on the HTTP server. - type: string - port: - anyOf: - - type: integer - - type: string - description: Name or number of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - scheme: - description: Scheme to use for connecting to the host. Defaults - to HTTP. - type: string - required: - - port - type: object initialDelaySeconds: - description: 'Number of seconds after the container has started - before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer periodSeconds: - description: How often (in seconds) to perform the probe. Default - to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: - description: Minimum consecutive successes for the probe to be - considered successful after having failed. Defaults to 1. Must - be 1 for liveness and startup. Minimum value is 1. format: int32 type: integer - tcpSocket: - description: TCPSocket specifies an action involving a TCP port. - properties: - host: - description: 'Optional: Host name to connect to, defaults - to the pod IP.' - type: string - port: - anyOf: - - type: integer - - type: string - description: Number or name of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - required: - - port - type: object terminationGracePeriodSeconds: - description: Optional duration in seconds the pod needs to terminate - gracefully upon probe failure. format: int64 type: integer timeoutSeconds: - description: 'Number of seconds after which the probe times out. - Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -6767,6 +6661,27 @@ spec: x-kubernetes-list-type: atomic priorityClassName: type: string + readinessProbe: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + successThreshold: + format: int32 + type: integer + terminationGracePeriodSeconds: + format: int64 + type: integer + timeoutSeconds: + format: int32 + type: integer + type: object replicas: format: int32 type: integer diff --git a/docs/api.md b/docs/api.md index beeccbf962..9d90fc96de 100644 --- a/docs/api.md +++ b/docs/api.md @@ -11362,7 +11362,8 @@ default.
readinessProbe object - Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
+ Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. +It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
false @@ -21122,7 +21123,8 @@ More info: https://kubernetes.io/docs/concepts/services-networking/service/#defi -Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic. +Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. +It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. @@ -21134,40 +21136,22 @@ Probe describes a health check to be performed against a container to determine - - - - - - - - - - - - - - - @@ -21176,7 +21160,8 @@ Probe describes a health check to be performed against a container to determine @@ -21185,23 +21170,26 @@ Probe describes a health check to be performed against a container to determine - - - - - @@ -21210,196 +21198,12 @@ Probe describes a health check to be performed against a container to determine - - -
execobject - Exec specifies the action to take.
-
false
failureThreshold integer - Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1.
+ Minimum consecutive failures for the probe to be considered failed after having succeeded. +Defaults to 3. Minimum value is 1.

Format: int32
false
grpcobject - GRPC specifies an action involving a GRPC port.
-
false
httpGetobject - HTTPGet specifies the http request to perform.
-
false
initialDelaySeconds integer - Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
+ Number of seconds after the container has started before liveness probes are initiated. +Defaults to 0 seconds. Minimum value is 0. +More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

Format: int32
periodSeconds integer - How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1.
+ How often (in seconds) to perform the probe. +Default to 10 seconds. Minimum value is 1.

Format: int32
successThreshold integer - Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
+ Minimum consecutive successes for the probe to be considered successful after having failed. +Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.

Format: int32
false
tcpSocketobject - TCPSocket specifies an action involving a TCP port.
-
false
terminationGracePeriodSeconds integer - Optional duration in seconds the pod needs to terminate gracefully upon probe failure.
+ Optional duration in seconds the pod needs to terminate gracefully upon probe failure. +The grace period is the duration in seconds after the processes running in the pod are sent +a termination signal and the time when the processes are forcibly halted with a kill signal. +Set this value longer than the expected cleanup time for your process. +If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this +value overrides the value provided by the pod spec. +Value must be non-negative integer. The value zero indicates stop immediately via +the kill signal (no opportunity to shut down). +This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate. +Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.

Format: int64
timeoutSeconds integer - Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
-
- Format: int32
-
false
- - -### OpenTelemetryCollector.spec.readinessProbe.exec -[↩ Parent](#opentelemetrycollectorspecreadinessprobe) - - - -Exec specifies the action to take. - - - - - - - - - - - - - - - - -
NameTypeDescriptionRequired
command[]string - Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem.
-
false
- - -### OpenTelemetryCollector.spec.readinessProbe.grpc -[↩ Parent](#opentelemetrycollectorspecreadinessprobe) - - - -GRPC specifies an action involving a GRPC port. - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescriptionRequired
portinteger - Port number of the gRPC service. Number must be in the range 1 to 65535.
+ Number of seconds after which the probe times out. +Defaults to 1 second. Minimum value is 1. +More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

Format: int32
true
servicestring - Service is the name of the service to place in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).
-
false
- - -### OpenTelemetryCollector.spec.readinessProbe.httpGet -[↩ Parent](#opentelemetrycollectorspecreadinessprobe) - - - -HTTPGet specifies the http request to perform. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescriptionRequired
portint or string - Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
-
true
hoststring - Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead.
-
false
httpHeaders[]object - Custom headers to set in the request. HTTP allows repeated headers.
-
false
pathstring - Path to access on the HTTP server.
-
false
schemestring - Scheme to use for connecting to the host. Defaults to HTTP.
-
false
- - -### OpenTelemetryCollector.spec.readinessProbe.httpGet.httpHeaders[index] -[↩ Parent](#opentelemetrycollectorspecreadinessprobehttpget) - - - -HTTPHeader describes a custom header to be used in HTTP probes - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescriptionRequired
namestring - The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.
-
true
valuestring - The header field value
-
true
- - -### OpenTelemetryCollector.spec.readinessProbe.tcpSocket -[↩ Parent](#opentelemetrycollectorspecreadinessprobe) - - - -TCPSocket specifies an action involving a TCP port. - - - - - - - - - - - - - - - - - - -
NameTypeDescriptionRequired
portint or string - Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
-
true
hoststring - Optional: Host name to connect to, defaults to the pod IP.
-
false
@@ -30345,6 +30149,14 @@ If not specified, the pod priority will be default or zero if there is no default.
false + + readinessProbe + object + + Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. +It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
+ + false replicas integer @@ -40338,6 +40150,97 @@ More info: https://kubernetes.io/docs/concepts/services-networking/service/#defi +### OpenTelemetryCollector.spec.readinessProbe +[↩ Parent](#opentelemetrycollectorspec-1) + + + +Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. +It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
failureThresholdinteger + Minimum consecutive failures for the probe to be considered failed after having succeeded. +Defaults to 3. Minimum value is 1.
+
+ Format: int32
+
false
initialDelaySecondsinteger + Number of seconds after the container has started before liveness probes are initiated. +Defaults to 0 seconds. Minimum value is 0. +More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
+
+ Format: int32
+
false
periodSecondsinteger + How often (in seconds) to perform the probe. +Default to 10 seconds. Minimum value is 1.
+
+ Format: int32
+
false
successThresholdinteger + Minimum consecutive successes for the probe to be considered successful after having failed. +Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
+
+ Format: int32
+
false
terminationGracePeriodSecondsinteger + Optional duration in seconds the pod needs to terminate gracefully upon probe failure. +The grace period is the duration in seconds after the processes running in the pod are sent +a termination signal and the time when the processes are forcibly halted with a kill signal. +Set this value longer than the expected cleanup time for your process. +If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this +value overrides the value provided by the pod spec. +Value must be non-negative integer. The value zero indicates stop immediately via +the kill signal (no opportunity to shut down). +This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate. +Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.
+
+ Format: int64
+
false
timeoutSecondsinteger + Number of seconds after which the probe times out. +Defaults to 1 second. Minimum value is 1. +More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
+
+ Format: int32
+
false
+ + ### OpenTelemetryCollector.spec.resources [↩ Parent](#opentelemetrycollectorspec-1) From 88fcb7268e4f27af00e491bcc976b4ccdfbed115 Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Fri, 10 May 2024 10:10:53 +0200 Subject: [PATCH 05/10] Add changelog Signed-off-by: Janario Oliveira --- .chloggen/collector-readiness-support.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .chloggen/collector-readiness-support.yaml diff --git a/.chloggen/collector-readiness-support.yaml b/.chloggen/collector-readiness-support.yaml new file mode 100644 index 0000000000..e27a8d00d6 --- /dev/null +++ b/.chloggen/collector-readiness-support.yaml @@ -0,0 +1,17 @@ +# 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. collector, target allocator, auto-instrumentation, opamp, github action) +component: collector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add support for readinessProbe on OpenTelemetryCollector CRD. + +# One or more tracking issues related to the change +issues: [2943] + +# (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: | + Add support for readinessProbe on `OpenTelemetryCollector` and its default similar to the already supported livenessProbe. From dbeb0ce2dbe03a30496dca748b8f0f3f71decc85 Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Fri, 10 May 2024 10:26:18 +0200 Subject: [PATCH 06/10] Fix lint Signed-off-by: Janario Oliveira --- apis/v1alpha1/convert.go | 2 +- internal/manifests/collector/container_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apis/v1alpha1/convert.go b/apis/v1alpha1/convert.go index aa67903cb9..5fe838e6ac 100644 --- a/apis/v1alpha1/convert.go +++ b/apis/v1alpha1/convert.go @@ -128,7 +128,7 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error Termination: v1beta1.TLSRouteTerminationType(copy.Spec.Ingress.Route.Termination), }, }, - LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), + LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), ReadinessProbe: tov1beta1Probe(copy.Spec.ReadinessProbe), Observability: v1beta1.ObservabilitySpec{ Metrics: v1beta1.MetricsConfigSpec{ diff --git a/internal/manifests/collector/container_test.go b/internal/manifests/collector/container_test.go index 5b6be02367..597e98c1e7 100644 --- a/internal/manifests/collector/container_test.go +++ b/internal/manifests/collector/container_test.go @@ -778,7 +778,7 @@ func TestContainerProbeEmptyConfig(t *testing.T) { health_check: service: extensions: [health_check]`), - LivenessProbe: &v1beta1.Probe{}, + LivenessProbe: &v1beta1.Probe{}, ReadinessProbe: &v1beta1.Probe{}, }, } From 9835ddd49ea798f7cc8705db7e2af43700e49e46 Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Fri, 10 May 2024 19:39:24 +0200 Subject: [PATCH 07/10] Removed readinessProbe from alpha CRD Signed-off-by: Janario Oliveira --- apis/v1alpha1/convert.go | 2 -- apis/v1alpha1/convert_test.go | 3 --- apis/v1alpha1/opentelemetrycollector_types.go | 6 +----- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/apis/v1alpha1/convert.go b/apis/v1alpha1/convert.go index 5fe838e6ac..c597df2cdb 100644 --- a/apis/v1alpha1/convert.go +++ b/apis/v1alpha1/convert.go @@ -129,7 +129,6 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error }, }, LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), - ReadinessProbe: tov1beta1Probe(copy.Spec.ReadinessProbe), Observability: v1beta1.ObservabilitySpec{ Metrics: v1beta1.MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, @@ -353,7 +352,6 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err Lifecycle: copy.Spec.Lifecycle, TerminationGracePeriodSeconds: copy.Spec.TerminationGracePeriodSeconds, LivenessProbe: tov1alpha1Probe(copy.Spec.LivenessProbe), - ReadinessProbe: tov1alpha1Probe(copy.Spec.ReadinessProbe), InitContainers: copy.Spec.InitContainers, AdditionalContainers: copy.Spec.AdditionalContainers, Observability: ObservabilitySpec{ diff --git a/apis/v1alpha1/convert_test.go b/apis/v1alpha1/convert_test.go index 0510fcea60..ba8bb063d0 100644 --- a/apis/v1alpha1/convert_test.go +++ b/apis/v1alpha1/convert_test.go @@ -266,9 +266,6 @@ func Test_tov1beta1AndBack(t *testing.T) { LivenessProbe: &Probe{ PeriodSeconds: &one, }, - ReadinessProbe: &Probe{ - PeriodSeconds: &one, - }, InitContainers: []v1.Container{ { Name: "init", diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index 8ee67cb5de..a2c5055fd0 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -236,10 +236,6 @@ type OpenTelemetryCollectorSpec struct { // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. // +optional LivenessProbe *Probe `json:"livenessProbe,omitempty"` - // Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. - // It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. - // +optional - ReadinessProbe *Probe `json:"readinessProbe,omitempty"` // InitContainers allows injecting initContainers to the Collector's pod definition. // These init containers can be used to fetch secrets for injection into the // configuration from external sources, run added checks, etc. Any errors during the execution of @@ -555,7 +551,7 @@ type ObservabilitySpec struct { Metrics MetricsConfigSpec `json:"metrics,omitempty"` } -// Probe defines the OpenTelemetry's pod probe config. +// Probe defines the OpenTelemetry's pod probe config. Only Liveness probe is supported currently. type Probe struct { // Number of seconds after the container has started before liveness probes are initiated. // Defaults to 0 seconds. Minimum value is 0. From 03008af29c629edf87e4f5c3104fe5f9d3ed0e6c Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Fri, 10 May 2024 19:39:35 +0200 Subject: [PATCH 08/10] Generated manifests Signed-off-by: Janario Oliveira --- apis/v1alpha1/zz_generated.deepcopy.go | 5 - ...ntelemetry.io_opentelemetrycollectors.yaml | 21 ---- ...ntelemetry.io_opentelemetrycollectors.yaml | 21 ---- docs/api.md | 101 +----------------- 4 files changed, 1 insertion(+), 147 deletions(-) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index e6fd9f18a3..8f47cb64dc 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -911,11 +911,6 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp *out = new(Probe) (*in).DeepCopyInto(*out) } - if in.ReadinessProbe != nil { - in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(Probe) - (*in).DeepCopyInto(*out) - } if in.InitContainers != nil { in, out := &in.InitContainers, &out.InitContainers *out = make([]v1.Container, len(*in)) diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml index fc9472d64f..092ca2428e 100644 --- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -2340,27 +2340,6 @@ spec: x-kubernetes-list-type: atomic priorityClassName: type: string - readinessProbe: - properties: - failureThreshold: - format: int32 - type: integer - initialDelaySeconds: - format: int32 - type: integer - periodSeconds: - format: int32 - type: integer - successThreshold: - format: int32 - type: integer - terminationGracePeriodSeconds: - format: int64 - type: integer - timeoutSeconds: - format: int32 - type: integer - type: object replicas: format: int32 type: integer diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 1d30728f3e..ad8c35a81b 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -2326,27 +2326,6 @@ spec: x-kubernetes-list-type: atomic priorityClassName: type: string - readinessProbe: - properties: - failureThreshold: - format: int32 - type: integer - initialDelaySeconds: - format: int32 - type: integer - periodSeconds: - format: int32 - type: integer - successThreshold: - format: int32 - type: integer - terminationGracePeriodSeconds: - format: int64 - type: integer - timeoutSeconds: - format: int32 - type: integer - type: object replicas: format: int32 type: integer diff --git a/docs/api.md b/docs/api.md index 9d90fc96de..c374b1d622 100644 --- a/docs/api.md +++ b/docs/api.md @@ -11358,14 +11358,6 @@ If not specified, the pod priority will be default or zero if there is no default.
false - - readinessProbe - object - - Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. -It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
- - false replicas integer @@ -21118,97 +21110,6 @@ More info: https://kubernetes.io/docs/concepts/services-networking/service/#defi -### OpenTelemetryCollector.spec.readinessProbe -[↩ Parent](#opentelemetrycollectorspec) - - - -Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. -It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescriptionRequired
failureThresholdinteger - Minimum consecutive failures for the probe to be considered failed after having succeeded. -Defaults to 3. Minimum value is 1.
-
- Format: int32
-
false
initialDelaySecondsinteger - Number of seconds after the container has started before liveness probes are initiated. -Defaults to 0 seconds. Minimum value is 0. -More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
-
- Format: int32
-
false
periodSecondsinteger - How often (in seconds) to perform the probe. -Default to 10 seconds. Minimum value is 1.
-
- Format: int32
-
false
successThresholdinteger - Minimum consecutive successes for the probe to be considered successful after having failed. -Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
-
- Format: int32
-
false
terminationGracePeriodSecondsinteger - Optional duration in seconds the pod needs to terminate gracefully upon probe failure. -The grace period is the duration in seconds after the processes running in the pod are sent -a termination signal and the time when the processes are forcibly halted with a kill signal. -Set this value longer than the expected cleanup time for your process. -If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this -value overrides the value provided by the pod spec. -Value must be non-negative integer. The value zero indicates stop immediately via -the kill signal (no opportunity to shut down). -This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate. -Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.
-
- Format: int64
-
false
timeoutSecondsinteger - Number of seconds after which the probe times out. -Defaults to 1 second. Minimum value is 1. -More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
-
- Format: int32
-
false
- - ### OpenTelemetryCollector.spec.resources [↩ Parent](#opentelemetrycollectorspec) @@ -30150,7 +30051,7 @@ default.
false - readinessProbe + readinessProbe object Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector. From 800bf85c53610dcc1065fc26a08993d9af497388 Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Fri, 10 May 2024 19:41:12 +0200 Subject: [PATCH 09/10] Fix lint Signed-off-by: Janario Oliveira --- apis/v1alpha1/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1alpha1/convert.go b/apis/v1alpha1/convert.go index c597df2cdb..fb37e1c781 100644 --- a/apis/v1alpha1/convert.go +++ b/apis/v1alpha1/convert.go @@ -128,7 +128,7 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error Termination: v1beta1.TLSRouteTerminationType(copy.Spec.Ingress.Route.Termination), }, }, - LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), + LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), Observability: v1beta1.ObservabilitySpec{ Metrics: v1beta1.MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, From 7c61f89fc7e8df3576f77bc4398d0fa99f03a057 Mon Sep 17 00:00:00 2001 From: Janario Oliveira Date: Mon, 13 May 2024 13:25:33 +0200 Subject: [PATCH 10/10] Centralized probe validation Signed-off-by: Janario Oliveira --- apis/v1beta1/collector_webhook.go | 69 ++++++++++++++----------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/apis/v1beta1/collector_webhook.go b/apis/v1beta1/collector_webhook.go index 941c0de3f3..41951f18b8 100644 --- a/apis/v1beta1/collector_webhook.go +++ b/apis/v1beta1/collector_webhook.go @@ -289,45 +289,14 @@ func (c CollectorWebhook) validate(ctx context.Context, r *OpenTelemetryCollecto return warnings, fmt.Errorf("a valid Ingress hostname has to be defined for subdomain ruleType") } - if r.Spec.LivenessProbe != nil { - if r.Spec.LivenessProbe.InitialDelaySeconds != nil && *r.Spec.LivenessProbe.InitialDelaySeconds < 0 { - return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe InitialDelaySeconds configuration is incorrect. InitialDelaySeconds should be greater than or equal to 0") - } - if r.Spec.LivenessProbe.PeriodSeconds != nil && *r.Spec.LivenessProbe.PeriodSeconds < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe PeriodSeconds configuration is incorrect. PeriodSeconds should be greater than or equal to 1") - } - if r.Spec.LivenessProbe.TimeoutSeconds != nil && *r.Spec.LivenessProbe.TimeoutSeconds < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe TimeoutSeconds configuration is incorrect. TimeoutSeconds should be greater than or equal to 1") - } - if r.Spec.LivenessProbe.SuccessThreshold != nil && *r.Spec.LivenessProbe.SuccessThreshold < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe SuccessThreshold configuration is incorrect. SuccessThreshold should be greater than or equal to 1") - } - if r.Spec.LivenessProbe.FailureThreshold != nil && *r.Spec.LivenessProbe.FailureThreshold < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe FailureThreshold configuration is incorrect. FailureThreshold should be greater than or equal to 1") - } - if r.Spec.LivenessProbe.TerminationGracePeriodSeconds != nil && *r.Spec.LivenessProbe.TerminationGracePeriodSeconds < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec LivenessProbe TerminationGracePeriodSeconds configuration is incorrect. TerminationGracePeriodSeconds should be greater than or equal to 1") - } + // validate probes Liveness/Readiness + err := validateProbe("LivenessProbe", r.Spec.LivenessProbe) + if err != nil { + return warnings, err } - if r.Spec.ReadinessProbe != nil { - if r.Spec.ReadinessProbe.InitialDelaySeconds != nil && *r.Spec.ReadinessProbe.InitialDelaySeconds < 0 { - return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe InitialDelaySeconds configuration is incorrect. InitialDelaySeconds should be greater than or equal to 0") - } - if r.Spec.ReadinessProbe.PeriodSeconds != nil && *r.Spec.ReadinessProbe.PeriodSeconds < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe PeriodSeconds configuration is incorrect. PeriodSeconds should be greater than or equal to 1") - } - if r.Spec.ReadinessProbe.TimeoutSeconds != nil && *r.Spec.ReadinessProbe.TimeoutSeconds < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe TimeoutSeconds configuration is incorrect. TimeoutSeconds should be greater than or equal to 1") - } - if r.Spec.ReadinessProbe.SuccessThreshold != nil && *r.Spec.ReadinessProbe.SuccessThreshold < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe SuccessThreshold configuration is incorrect. SuccessThreshold should be greater than or equal to 1") - } - if r.Spec.ReadinessProbe.FailureThreshold != nil && *r.Spec.ReadinessProbe.FailureThreshold < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe FailureThreshold configuration is incorrect. FailureThreshold should be greater than or equal to 1") - } - if r.Spec.ReadinessProbe.TerminationGracePeriodSeconds != nil && *r.Spec.ReadinessProbe.TerminationGracePeriodSeconds < 1 { - return warnings, fmt.Errorf("the OpenTelemetry Spec ReadinessProbe TerminationGracePeriodSeconds configuration is incorrect. TerminationGracePeriodSeconds should be greater than or equal to 1") - } + err = validateProbe("ReadinessProbe", r.Spec.ReadinessProbe) + if err != nil { + return warnings, err } // validate updateStrategy for DaemonSet @@ -385,6 +354,30 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r * return nil, nil } +func validateProbe(probeName string, probe *Probe) error { + if probe != nil { + if probe.InitialDelaySeconds != nil && *probe.InitialDelaySeconds < 0 { + return fmt.Errorf("the OpenTelemetry Spec %s InitialDelaySeconds configuration is incorrect. InitialDelaySeconds should be greater than or equal to 0", probeName) + } + if probe.PeriodSeconds != nil && *probe.PeriodSeconds < 1 { + return fmt.Errorf("the OpenTelemetry Spec %s PeriodSeconds configuration is incorrect. PeriodSeconds should be greater than or equal to 1", probeName) + } + if probe.TimeoutSeconds != nil && *probe.TimeoutSeconds < 1 { + return fmt.Errorf("the OpenTelemetry Spec %s TimeoutSeconds configuration is incorrect. TimeoutSeconds should be greater than or equal to 1", probeName) + } + if probe.SuccessThreshold != nil && *probe.SuccessThreshold < 1 { + return fmt.Errorf("the OpenTelemetry Spec %s SuccessThreshold configuration is incorrect. SuccessThreshold should be greater than or equal to 1", probeName) + } + if probe.FailureThreshold != nil && *probe.FailureThreshold < 1 { + return fmt.Errorf("the OpenTelemetry Spec %s FailureThreshold configuration is incorrect. FailureThreshold should be greater than or equal to 1", probeName) + } + if probe.TerminationGracePeriodSeconds != nil && *probe.TerminationGracePeriodSeconds < 1 { + return fmt.Errorf("the OpenTelemetry Spec %s TerminationGracePeriodSeconds configuration is incorrect. TerminationGracePeriodSeconds should be greater than or equal to 1", probeName) + } + } + return nil +} + func checkAutoscalerSpec(autoscaler *AutoscalerSpec) error { if autoscaler.Behavior != nil { if autoscaler.Behavior.ScaleDown != nil && autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds != nil &&