opentelemetry-operator icon indicating copy to clipboard operation
opentelemetry-operator copied to clipboard

Add serviceName Field to OpenTelemetryCollector CRD for StatefulSet Deployments

Open vignesh-codes opened this issue 6 months ago • 7 comments

Description: Add support for custom service names in StatefulSet headless services

This PR fixes the handling of service names for StatefulSet mode in the OpenTelemetry Collector operator:

  • Adds ability to specify custom service names via spec.serviceName field for sts
  • When running in StatefulSet mode and no service name is specified, defaults to <name>-headless
  • Maintains existing behavior for non-StatefulSet modes
  • Ensures TLS secret names follow the service naming pattern

Link to tracking Issue(s): 4029

Testing: Added new test cases in statefulset_test.go for statefulset creation with custom and default service names:

  • Test default headless service name generation for StatefulSet mode
  • Test custom service name handling for sts

Documentation:

vignesh-codes avatar May 27 '25 19:05 vignesh-codes

Could you please add assert here https://github.com/open-telemetry/opentelemetry-operator/blob/6d2f18b0ac0303aff2b904c2de76296cea60fbf9/tests/e2e/smoke-statefulset/00-assert.yaml

pavolloffay avatar May 28 '25 10:05 pavolloffay

Could you please add assert here https://github.com/open-telemetry/opentelemetry-operator/blob/6d2f18b0ac0303aff2b904c2de76296cea60fbf9/tests/e2e/smoke-statefulset/00-assert.yaml

@pavolloffay I have added them

vignesh-codes avatar May 28 '25 18:05 vignesh-codes

@pavolloffay @iblancasa requesting for workflow approvals and reviews

vignesh-codes avatar Jun 02 '25 06:06 vignesh-codes

@vignesh-codes running make update should fix the CI failure.

swiatekm avatar Jun 02 '25 10:06 swiatekm

I imagined this feature working a bit differently. Rather than letting the user rename the Service (which in and out of itself isn't that useful), it should let them provide the name of a Service they created themselves. This how setting serviceAccount currently works, but we can always create the headless Service regardless. @open-telemetry/operator-approvers what do you think we should do here?

I don't have any complaints about the fix setting the default as the headless Service, so maybe we can make that a separate PR?

Cool! i made the make update command and pushed the commit. Let me know

vignesh-codes avatar Jun 03 '25 00:06 vignesh-codes

this is my current working config from the collector helm chart

  nameOverride: "dev-opentelemetry-backend-collector"
  fullnameOverride: "dev-opentelemetry-backend-collector-headless"

here is how the collector chart currently functions https://github.com/open-telemetry/opentelemetry-helm-charts/blob/09a02cb2dc1fe2c0e7e0ee51c2fe9c6a95ddc807/charts/opentelemetry-collector/templates/statefulset.yaml#L16

It'd be nice for a similar option with the OpenTelemetryCollector CR when mode: statefulset

rewt avatar Jun 12 '25 22:06 rewt

this is my current working config from the collector helm chart

  nameOverride: "dev-opentelemetry-backend-collector"
  fullnameOverride: "dev-opentelemetry-backend-collector-headless"

here is how the collector chart currently functions https://github.com/open-telemetry/opentelemetry-helm-charts/blob/09a02cb2dc1fe2c0e7e0ee51c2fe9c6a95ddc807/charts/opentelemetry-collector/templates/statefulset.yaml#L16

It'd be nice for a similar option with the OpenTelemetryCollector CR when mode: statefulset

That's already how it functions. The Service name is based on the OpenTelemetryCollector's metadata.name.

swiatekm avatar Jun 13 '25 09:06 swiatekm

@vignesh-codes looks good to me now! Could you resolve the lint failure? Then we should be good to merge.

swiatekm avatar Jun 18 '25 10:06 swiatekm

@iblancasa Waiting for your review and approval. Thanks

vignesh-codes avatar Jul 01 '25 18:07 vignesh-codes