Skip to content

Commit a233e77

Browse files
michaellzcdaxmc99
andauthored
sourcegraph: add service account support for otel (#248)
Co-authored-by: Dax McDonald <[email protected]>
1 parent 8a781ff commit a233e77

11 files changed

+375
-8
lines changed

charts/sourcegraph/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,16 @@ In addition to the documented values, all services also support the following va
195195
| openTelemetry.agent.resources.limits.memory | string | `"500Mi"` | |
196196
| openTelemetry.agent.resources.requests.cpu | string | `"100m"` | |
197197
| openTelemetry.agent.resources.requests.memory | string | `"100Mi"` | |
198+
| openTelemetry.agent.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-agent` |
199+
| openTelemetry.agent.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
198200
| openTelemetry.enabled | bool | `true` | |
199201
| openTelemetry.gateway.config.traces.exporters | object | `{}` | Define where traces should be exported to. Read how to configure different backends in the [OpenTelemetry documentation](https://opentelemetry.io/docs/collector/configuration/#exporters) |
200202
| openTelemetry.gateway.config.traces.exportersTlsSecretName | string | `""` | Define the name of a preexisting secret containing TLS certificates for exporters, which will be mounted under "/tls". Read more about TLS configuration of exporters in the [OpenTelemetry Collector documentation](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md) |
201203
| openTelemetry.gateway.config.traces.processors | object | `{}` | Define trace processors. Read how to configure sampling in the [OpenTelemetry documentation](https://docs.sourcegraph.com/admin/observability/opentelemetry#sampling-traces) |
202204
| openTelemetry.gateway.name | string | `"otel-collector"` | Name used by resources. Does not affect service names or PVCs. |
203205
| openTelemetry.gateway.resources | object | `{"limits":{"cpu":"3","memory":"3Gi"},"requests":{"cpu":"1","memory":"1Gi"}}` | Resource requests & limits for the `otel-collector` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
206+
| openTelemetry.gateway.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-collector` |
207+
| openTelemetry.gateway.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
204208
| openTelemetry.image.defaultTag | string | `"4.4.2@sha256:f0723c96c973258ad3123ddc479261bb8f5827bbac1d091b6a683fde55334413"` | Docker image tag for the `otel-collector` image |
205209
| openTelemetry.image.name | string | `"opentelemetry-collector"` | Docker image name for the `otel-collector` image |
206210
| pgsql.additionalConfig | string | `""` | Additional PostgreSQL configuration. This will override or extend our default configuration. Notes: This is expecting a multiline string. Learn more from our [recommended PostgreSQL configuration](https://docs.sourcegraph.com/admin/config/postgres-conf) and [PostgreSQL documentation](https://www.postgresql.org/docs/12/config-setting.html) |

charts/sourcegraph/templates/_helpers.tpl

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,56 @@ app.kubernetes.io/instance: {{ .Release.Name }}
3737

3838
{{/*
3939
Create the name of the service account to use
40+
41+
When calling these partial functions,
42+
43+
For top-level services, pass in the top-level values:
44+
45+
{{ include "sourcegraph.serviceAccountName" (list . "frontend") }}
46+
47+
frontend:
48+
serivceAccount:
49+
create: false
50+
51+
For nested services, pass in the nested values:
52+
53+
{{ include "sourcegraph.serviceAccountName" (list .Values.openTelemetry "gateway") }}
54+
55+
openTelemetry:
56+
gateway:
57+
serviceAccount:
58+
create: false
4059
*/}}
4160
{{- define "sourcegraph.serviceAccountName" -}}
4261
{{- $top := index . 0 }}
62+
{{- if hasKey $top "Values" -}}
63+
{{- $top = index $top "Values" -}}
64+
{{- end -}}
4365
{{- $service := index . 1 }}
44-
{{- $defaultServiceAccountName := (index $top.Values $service "name") }}
45-
{{- default $defaultServiceAccountName (index $top.Values $service "serviceAccount" "name") }}
46-
{{- end }}
66+
{{- $defaultServiceAccountName := (index $top $service "name") }}
67+
{{- default $defaultServiceAccountName (index $top $service "serviceAccount" "name") }}
68+
{{- end -}}
4769

4870
{{- define "sourcegraph.renderServiceAccountName" -}}
4971
{{- $top := index . 0 }}
72+
{{- if hasKey $top "Values" -}}
73+
{{- $top = index $top "Values" -}}
74+
{{- end -}}
5075
{{- $service := index . 1 }}
51-
{{- if or (index $top.Values $service "serviceAccount" "create") (index $top.Values $service "serviceAccount" "name") }}
76+
{{- if or (index $top $service "serviceAccount" "create") (index $top $service "serviceAccount" "name") }}
5277
serviceAccountName: {{ include "sourcegraph.serviceAccountName" (list $top $service) }}
53-
{{- end }}
54-
{{- end }}
78+
{{- end -}}
79+
{{- end -}}
5580

5681
{{- define "sourcegraph.serviceAccountAnnotations" -}}
5782
{{- $top := index . 0 }}
83+
{{- if hasKey $top "Values" -}}
84+
{{- $top = index $top "Values" -}}
85+
{{- end -}}
5886
{{- $service := index . 1 }}
59-
{{- with (index $top.Values $service "serviceAccount" "annotations") }}
87+
{{- with (index $top $service "serviceAccount" "annotations") }}
6088
annotations:
61-
{{- . | toYaml | trim | nindent 4 }}
89+
{{- . | toYaml | trim | nindent 2 }}
6290
{{- end }}
6391
{{- end }}
6492

charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ spec:
8787
imagePullSecrets:
8888
{{- toYaml . | nindent 8 }}
8989
{{- end }}
90+
{{- include "sourcegraph.renderServiceAccountName" (list .Values.openTelemetry "agent") | trim | nindent 6 }}
9091
volumes:
9192
- name: config
9293
configMap:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- if .Values.openTelemetry.agent.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
labels:
6+
category: rbac
7+
deploy: sourcegraph
8+
app.kubernetes.io/component: otel-collector
9+
{{- include "sourcegraph.serviceAccountAnnotations" (list .Values.openTelemetry "agent") | trim | nindent 2 -}}
10+
name: {{ include "sourcegraph.serviceAccountName" (list .Values.openTelemetry "agent") }}
11+
{{- end }}

charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ spec:
104104
imagePullSecrets:
105105
{{- toYaml . | nindent 8 }}
106106
{{- end }}
107+
{{- include "sourcegraph.renderServiceAccountName" (list .Values.openTelemetry "gateway") | trim | nindent 6 }}
107108
volumes:
108109
{{- if .Values.openTelemetry.gateway.config.traces.exporters }}
109110
- name: config
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- if .Values.openTelemetry.gateway.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
labels:
6+
category: rbac
7+
deploy: sourcegraph
8+
app.kubernetes.io/component: otel-collector
9+
{{- include "sourcegraph.serviceAccountAnnotations" (list .Values.openTelemetry "gateway") | trim | nindent 2 -}}
10+
name: {{ include "sourcegraph.serviceAccountName" (list .Values.openTelemetry "gateway") }}
11+
{{- end }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
should render service account annotations when cadvisor.serviceAccount.annotations is defined:
2+
1: |
3+
apiVersion: v1
4+
kind: ServiceAccount
5+
metadata:
6+
annotations:
7+
iam.gke.io/gcp-service-account: sourcegraph@sourcegraph.iam.gserviceaccount.com
8+
labels:
9+
app: cadvisor
10+
app.kubernetes.io/component: cadvisor
11+
category: rbac
12+
deploy: sourcegraph
13+
name: cadvisor
14+
should render service account annotations when frontend.serviceAccount.annotations is defined:
15+
1: |
16+
apiVersion: v1
17+
kind: ServiceAccount
18+
metadata:
19+
annotations:
20+
iam.gke.io/gcp-service-account: sourcegraph@sourcegraph.iam.gserviceaccount.com
21+
labels:
22+
app.kubernetes.io/component: frontend
23+
category: rbac
24+
deploy: sourcegraph
25+
name: sourcegraph-frontend
26+
should render service account annotations when prometheus.serviceAccount.annotations is defined:
27+
1: |
28+
apiVersion: v1
29+
kind: ServiceAccount
30+
metadata:
31+
annotations:
32+
iam.gke.io/gcp-service-account: sourcegraph@sourcegraph.iam.gserviceaccount.com
33+
labels:
34+
app.kubernetes.io/component: prometheus
35+
category: rbac
36+
deploy: sourcegraph
37+
name: prometheus
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
should render service account when frontend.serviceAccount.create=true:
2+
1: |
3+
apiVersion: v1
4+
kind: ServiceAccount
5+
metadata:
6+
labels:
7+
app.kubernetes.io/component: frontend
8+
category: rbac
9+
deploy: sourcegraph
10+
name: sourcegraph-frontend
11+
should render service account when openTelemetry.agent.serviceAccount.create is true:
12+
1: |
13+
apiVersion: v1
14+
kind: ServiceAccount
15+
metadata:
16+
labels:
17+
app.kubernetes.io/component: otel-collector
18+
category: rbac
19+
deploy: sourcegraph
20+
name: otel-agent
21+
should render service account when openTelemetry.gateway.serviceAccount.create is true:
22+
1: |
23+
apiVersion: v1
24+
kind: ServiceAccount
25+
metadata:
26+
labels:
27+
app.kubernetes.io/component: otel-collector
28+
category: rbac
29+
deploy: sourcegraph
30+
name: otel-collector
31+
should should reference service account when openTelemetry.agent.serviceAccount.create is true:
32+
1: |
33+
apiVersion: apps/v1
34+
kind: DaemonSet
35+
metadata:
36+
annotations:
37+
description: Forwards telemetry data to the OpenTelemetry Collector Deployment.
38+
labels:
39+
app.kubernetes.io/component: otel-collector
40+
app.kubernetes.io/instance: sourcegraph
41+
app.kubernetes.io/managed-by: Helm
42+
app.kubernetes.io/name: sourcegraph
43+
app.kubernetes.io/version: 4.4.2
44+
deploy: sourcegraph
45+
helm.sh/chart: sourcegraph-4.4.2
46+
name: otel-agent
47+
spec:
48+
minReadySeconds: 5
49+
selector:
50+
matchLabels:
51+
app: otel-agent
52+
app.kubernetes.io/instance: sourcegraph
53+
app.kubernetes.io/name: sourcegraph
54+
template:
55+
metadata:
56+
annotations:
57+
kubectl.kubernetes.io/default-container: otel-agent
58+
labels:
59+
app: otel-agent
60+
app.kubernetes.io/instance: sourcegraph
61+
app.kubernetes.io/name: sourcegraph
62+
deploy: sourcegraph
63+
spec:
64+
affinity: null
65+
containers:
66+
- command:
67+
- /bin/otelcol-sourcegraph
68+
- --config=/etc/otel-agent/config.yaml
69+
env: null
70+
image: index.docker.io/sourcegraph/opentelemetry-collector:4.4.2@sha256:f0723c96c973258ad3123ddc479261bb8f5827bbac1d091b6a683fde55334413
71+
imagePullPolicy: IfNotPresent
72+
livenessProbe:
73+
httpGet:
74+
path: /
75+
port: 13133
76+
name: otel-agent
77+
ports:
78+
- containerPort: 55679
79+
hostPort: 55679
80+
name: zpages
81+
- containerPort: 4317
82+
hostPort: 4317
83+
name: otlp-grpc
84+
- containerPort: 4318
85+
hostPort: 4318
86+
name: otlp-http
87+
readinessProbe:
88+
httpGet:
89+
path: /
90+
port: 13133
91+
resources:
92+
limits:
93+
cpu: 500m
94+
memory: 500Mi
95+
requests:
96+
cpu: 100m
97+
memory: 100Mi
98+
terminationMessagePolicy: FallbackToLogsOnError
99+
volumeMounts:
100+
- mountPath: /etc/otel-agent
101+
name: config
102+
nodeSelector: null
103+
serviceAccountName: otel-agent
104+
terminationGracePeriodSeconds: 120
105+
tolerations: null
106+
volumes:
107+
- configMap:
108+
items:
109+
- key: config.yaml
110+
path: config.yaml
111+
name: otel-agent
112+
name: config
113+
should should reference service account when openTelemetry.gateway.serviceAccount.create is true:
114+
1: |
115+
apiVersion: apps/v1
116+
kind: Deployment
117+
metadata:
118+
annotations:
119+
description: Receives, processes, and exports telemetry data.
120+
labels:
121+
app.kubernetes.io/component: otel-collector
122+
app.kubernetes.io/instance: sourcegraph
123+
app.kubernetes.io/managed-by: Helm
124+
app.kubernetes.io/name: sourcegraph
125+
app.kubernetes.io/version: 4.4.2
126+
deploy: sourcegraph
127+
helm.sh/chart: sourcegraph-4.4.2
128+
name: otel-collector
129+
spec:
130+
minReadySeconds: 5
131+
progressDeadlineSeconds: 120
132+
replicas: 1
133+
selector:
134+
matchLabels:
135+
app: otel-collector
136+
app.kubernetes.io/instance: sourcegraph
137+
app.kubernetes.io/name: sourcegraph
138+
template:
139+
metadata:
140+
annotations:
141+
kubectl.kubernetes.io/default-container: otel-collector
142+
labels:
143+
app: otel-collector
144+
app.kubernetes.io/instance: sourcegraph
145+
app.kubernetes.io/name: sourcegraph
146+
deploy: sourcegraph
147+
spec:
148+
affinity: null
149+
containers:
150+
- command:
151+
- /bin/otelcol-sourcegraph
152+
- --config=/etc/otel-collector/configs/logging.yaml
153+
env: null
154+
image: index.docker.io/sourcegraph/opentelemetry-collector:4.4.2@sha256:f0723c96c973258ad3123ddc479261bb8f5827bbac1d091b6a683fde55334413
155+
imagePullPolicy: IfNotPresent
156+
livenessProbe:
157+
httpGet:
158+
path: /
159+
port: 13133
160+
name: otel-collector
161+
ports:
162+
- containerPort: 55679
163+
name: zpages
164+
- containerPort: 4317
165+
name: otlp-grpc
166+
- containerPort: 4318
167+
name: otlp-http
168+
- containerPort: 8888
169+
name: metrics
170+
readinessProbe:
171+
httpGet:
172+
path: /
173+
port: 13133
174+
resources:
175+
limits:
176+
cpu: "3"
177+
memory: 3Gi
178+
requests:
179+
cpu: "1"
180+
memory: 1Gi
181+
terminationMessagePolicy: FallbackToLogsOnError
182+
volumeMounts: null
183+
nodeSelector: null
184+
serviceAccountName: otel-collector
185+
terminationGracePeriodSeconds: 120
186+
tolerations: null
187+
volumes: null

charts/sourcegraph/tests/serviceAccountAnnotations_test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tests:
1515
path: metadata.annotations
1616
value:
1717
iam.gke.io/gcp-service-account: [email protected]
18+
- matchSnapshot: {}
1819

1920
- it: should render service account annotations when cadvisor.serviceAccount.annotations is defined
2021
set:
@@ -28,6 +29,7 @@ tests:
2829
path: metadata.annotations
2930
value:
3031
iam.gke.io/gcp-service-account: [email protected]
32+
- matchSnapshot: {}
3133

3234
- it: should render service account annotations when prometheus.serviceAccount.annotations is defined
3335
set:
@@ -41,3 +43,4 @@ tests:
4143
path: metadata.annotations
4244
value:
4345
iam.gke.io/gcp-service-account: [email protected]
46+
- matchSnapshot: {}

0 commit comments

Comments
 (0)