diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index c5a643c4..d51916c3 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -203,6 +203,7 @@ In addition to the documented values, all services also support the following va | openTelemetry.agent.containerSecurityContext.runAsGroup | int | `101` | | | openTelemetry.agent.containerSecurityContext.runAsUser | int | `100` | | | openTelemetry.agent.hostPorts | object | `{"grpcOtlp":4317,"httpOtlp":4318,"httpZpages":55679}` | Resource requests & limits for the `otel-agent` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) | +| openTelemetry.agent.kind | string | `"DaemonSet"` | The workload kind for the otel-agent. Valid values are `DaemonSet` and `Deployment`. Use `Deployment` in environments where DaemonSets are restricted (e.g. some managed Kubernetes offerings). When set to `Deployment`, the otel-agent DaemonSet is not created and application pods send traces directly to the existing otel-collector Deployment (otel-collector:4317) instead. | | openTelemetry.agent.name | string | `"otel-agent"` | Name used by resources. Does not affect service names or PVCs. | | openTelemetry.agent.resources.limits.cpu | string | `"500m"` | | | openTelemetry.agent.resources.limits.memory | string | `"500Mi"` | | diff --git a/charts/sourcegraph/templates/_helpers.tpl b/charts/sourcegraph/templates/_helpers.tpl index 13d0ed52..01d070d5 100644 --- a/charts/sourcegraph/templates/_helpers.tpl +++ b/charts/sourcegraph/templates/_helpers.tpl @@ -169,6 +169,10 @@ app.kubernetes.io/name: jaeger {{- define "sourcegraph.openTelemetryEnv" -}} {{- if .Values.openTelemetry.enabled -}} +{{- if eq (.Values.openTelemetry.agent.kind | default "DaemonSet") "Deployment" -}} +- name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://otel-collector:4317 +{{- else -}} # OTEL_AGENT_HOST must be defined before OTEL_EXPORTER_OTLP_ENDPOINT to substitute the node IP on which the DaemonSet pod instance runs in the latter variable - name: OTEL_AGENT_HOST valueFrom: @@ -178,6 +182,7 @@ app.kubernetes.io/name: jaeger value: http://$(OTEL_AGENT_HOST):{{ toYaml .Values.openTelemetry.agent.hostPorts.grpcOtlp }} {{- end }} {{- end }} +{{- end }} {{- define "sourcegraph.databaseAuth" -}} {{- $top := index . 0 -}} diff --git a/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml b/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml index b2771396..d93c64b6 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml @@ -1,4 +1,4 @@ -{{- if .Values.openTelemetry.enabled -}} +{{- if and .Values.openTelemetry.enabled (eq (.Values.openTelemetry.agent.kind | default "DaemonSet") "DaemonSet") -}} apiVersion: apps/v1 kind: DaemonSet metadata: diff --git a/charts/sourcegraph/tests/otelAgentKind_test.yaml b/charts/sourcegraph/tests/otelAgentKind_test.yaml new file mode 100644 index 00000000..8954a293 --- /dev/null +++ b/charts/sourcegraph/tests/otelAgentKind_test.yaml @@ -0,0 +1,42 @@ +--- +suite: otelAgentKind +tests: + - it: should render a DaemonSet by default + template: otel-collector/otel-agent.DaemonSet.yaml + asserts: + - isKind: + of: DaemonSet + - it: should render a DaemonSet when kind is DaemonSet + template: otel-collector/otel-agent.DaemonSet.yaml + set: + openTelemetry: + agent: + kind: "DaemonSet" + asserts: + - isKind: + of: DaemonSet + - it: should not render a DaemonSet when kind is Deployment + template: otel-collector/otel-agent.DaemonSet.yaml + set: + openTelemetry: + agent: + kind: "Deployment" + asserts: + - hasDocuments: + count: 0 + - it: should set OTEL_EXPORTER_OTLP_ENDPOINT to otel-collector when kind is Deployment + template: searcher/searcher.StatefulSet.yaml + set: + openTelemetry: + agent: + kind: "Deployment" + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_EXPORTER_OTLP_ENDPOINT + value: "http://otel-collector:4317" + - notContains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_AGENT_HOST diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index cdb59b5f..632d4fdd 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -658,6 +658,11 @@ openTelemetry: agent: # -- Name used by resources. Does not affect service names or PVCs. name: "otel-agent" + # -- The workload kind for the otel-agent. Valid values are `DaemonSet` and `Deployment`. + # Use `Deployment` in environments where DaemonSets are restricted (e.g. some managed Kubernetes offerings). + # When set to `Deployment`, the otel-agent DaemonSet is not created and application pods send + # traces directly to the existing otel-collector Deployment (otel-collector:4317) instead. + kind: "DaemonSet" # -- Resource requests & limits for the `otel-agent` container, # learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) hostPorts: