Skip to content

Commit c239141

Browse files
fix/opentelemetry: Skip the unused otel-agent ConfigMap and ServiceAccount when openTelemetry.agent.kind is Deployment (#1041)
## Context - #863 added `openTelemetry.agent.kind: Deployment`, which skips the `otel-agent` DaemonSet, so application pods send traces straight to `otel-collector:4317` - The `otel-agent` DaemonSet is the only pod that mounts the `otel-agent` ConfigMap and uses the `otel-agent` ServiceAccount ## Problem - With `kind: Deployment`, the chart still renders the `otel-agent` ConfigMap, which nothing uses - Found rendering a customer's override with `kind: Deployment` and #1038's label values: the orphan ConfigMap was the only object of 49 without their per-component label, since they set no `openTelemetry.agent.labels` for an agent they don't run - With `openTelemetry.agent.serviceAccount.create: true`, the `otel-agent` ServiceAccount renders regardless of `kind` and `openTelemetry.enabled`, so it is also unused when no DaemonSet renders ## Solution - Render the `otel-agent` ConfigMap and ServiceAccount under the same condition as the DaemonSet: `openTelemetry.enabled` and `openTelemetry.agent.kind` of `DaemonSet`, the default. The ServiceAccount still also needs `serviceAccount.create` - On upgrade, Helm deletes the unused objects from releases that set `kind: Deployment`. Renders with the default `kind: DaemonSet` do not change ## Testing - Four new tests in `otelAgentKind_test.yaml`: the ConfigMap and ServiceAccount each render by default, and not with `kind: Deployment`. The two `kind: Deployment` tests fail on `main` and pass here; `helm unittest` (317 tests, 120 snapshots) and `helm lint` pass - `helm template` renders byte-identical output on `main` and this branch with the default values, and with `openTelemetry.agent.serviceAccount.create: true` - With `serviceAccount.create: true`, the ServiceAccount renders on `main` with `kind: Deployment` or `openTelemetry.enabled: false`, and not here - The customer override with `kind: Deployment` renders 49 objects on `main`, including the `otel-agent` ConfigMap, and 48 here, without it - Not deployed on a cluster ## Amp threads - https://ampcode.com/threads/T-01a21663-f060-7148-8fdc-8eed219fa092 ## Changelog The `otel-agent` ConfigMap and ServiceAccount are no longer rendered when `openTelemetry.agent.kind` is `Deployment` Co-authored-by: Amp <amp@ampcode.com>
1 parent 484fdc1 commit c239141

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎charts/sourcegraph/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Use `**BREAKING**:` to denote a breaking change
1414
- The `otel-collector` Service now has the `app: otel-collector` label, like every other Service and the `otel-collector` pods. Prometheus copies Service labels to the metrics it scrapes, so `otel-collector` metrics also gain `app="otel-collector"`.
1515
- Fixed `otel-collector` serving its own metrics on `127.0.0.1` only when `openTelemetry.gateway.config.traces.exporters` is set, so Prometheus could not scrape them. The configuration the chart renders for those exporters now serves them on all interfaces, port 8888, like the image's `jaeger.yaml`. With the `app: otel-collector` label above, the failed scrape would fire the `otel-collector` "pods available" critical alert. The default configuration, the image's `logging.yaml`, gets the same fix in the `otel-collector` image.
1616
- Removed the `sourcegraph-resource-requires: no-cluster-admin` label from the `node-exporter` Service, the last object in this chart that set it. It came from the manifests of the old `kubectl apply` install, which used it to split an install between cluster admins and other users, and nothing selects on it. With it, `sourcegraph-resource-requires` set in `sourcegraph.serviceLabels` or `nodeExporter.serviceLabels` rendered the key twice on that Service, which Kustomize and `kubeconform -strict` reject. To keep the label, set it in one of these values. `node-exporter` metrics lose the `sourcegraph_resource_requires` label, which no bundled dashboard or alert queries.
17+
- The `otel-agent` ConfigMap and ServiceAccount are no longer rendered when `openTelemetry.agent.kind` is `Deployment` or `openTelemetry.enabled` is false, like the `otel-agent` DaemonSet, the only pod that uses them. On upgrade, Helm deletes them from releases that set `kind: Deployment`. Renders with the default `kind: DaemonSet` do not change.
1718
- The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply.
1819
- Added `sourcegraph.selectorLabelsOverride`, `<serviceName>.extraSelectorLabels`, and `storageLabels` on `gitserver`, `grafana`, `indexedSearch`, and `searcher`, so the chart can render the selectors and volume claim templates of workloads created outside it, such as with Kustomize, and a Helm release can take them over without deleting them. All default to empty, so existing releases render the same selectors. Never change them on an installed release: Kubernetes does not allow changing these fields. See [Adopting existing workloads](README.md#adopting-existing-workloads).
1920
- Fixed `frontend.command` and `migrator.command` rendering a list as a single element, e.g. `["sh", "-c", "<script>"]` became `[sh -c <script>]`, so the container failed to start. Both are now rendered as YAML lists and documented in `values.yaml`. A string holding a YAML list, the only form that worked before, still renders unchanged.

‎charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{ if .Values.openTelemetry.enabled -}}
1+
{{ if and .Values.openTelemetry.enabled (eq (.Values.openTelemetry.agent.kind | default "DaemonSet") "DaemonSet") -}}
22
# Config for the agent pods running as a DaemonSet, which forward data to the gateway pod
33
apiVersion: v1
44
kind: ConfigMap

‎charts/sourcegraph/templates/otel-collector/otel-agent.ServiceAccount.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.openTelemetry.agent.serviceAccount.create -}}
1+
{{- if and .Values.openTelemetry.enabled .Values.openTelemetry.agent.serviceAccount.create (eq (.Values.openTelemetry.agent.kind | default "DaemonSet") "DaemonSet") -}}
22
apiVersion: v1
33
kind: ServiceAccount
44
metadata:

‎charts/sourcegraph/tests/otelAgentKind_test.yaml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ tests:
2424
asserts:
2525
- hasDocuments:
2626
count: 0
27+
- it: should render the otel-agent ConfigMap by default, for the DaemonSet to mount
28+
template: otel-collector/otel-agent.ConfigMap.yaml
29+
asserts:
30+
- containsDocument:
31+
kind: ConfigMap
32+
apiVersion: v1
33+
name: otel-agent
34+
- it: should not render the otel-agent ConfigMap when kind is Deployment, since no pod mounts it
35+
template: otel-collector/otel-agent.ConfigMap.yaml
36+
set:
37+
openTelemetry:
38+
agent:
39+
kind: "Deployment"
40+
asserts:
41+
- hasDocuments:
42+
count: 0
2743
- it: should set OTEL_EXPORTER_OTLP_ENDPOINT to otel-collector when kind is Deployment
2844
template: searcher/searcher.StatefulSet.yaml
2945
set:
@@ -40,3 +56,26 @@ tests:
4056
path: spec.template.spec.containers[0].env
4157
content:
4258
name: OTEL_AGENT_HOST
59+
- it: should render the otel-agent ServiceAccount when serviceAccount.create is set
60+
template: otel-collector/otel-agent.ServiceAccount.yaml
61+
set:
62+
openTelemetry:
63+
agent:
64+
serviceAccount:
65+
create: true
66+
asserts:
67+
- containsDocument:
68+
kind: ServiceAccount
69+
apiVersion: v1
70+
name: otel-agent
71+
- it: should not render the otel-agent ServiceAccount when kind is Deployment, since no pod uses it
72+
template: otel-collector/otel-agent.ServiceAccount.yaml
73+
set:
74+
openTelemetry:
75+
agent:
76+
kind: "Deployment"
77+
serviceAccount:
78+
create: true
79+
asserts:
80+
- hasDocuments:
81+
count: 0

0 commit comments

Comments
 (0)