Skip to content

Commit c96a004

Browse files
authored
Add support for deploying without using Kubernetes secrets (#752)
...and to disable RBAC resources. Customer's Kubernetes security policies block the creation of secrets and RBAC resources This PR doesn't change any default behaviour which would impact other customers, only adds a couple new configs customer can choose to use. ### Checklist - [x] Follow the [manual testing process](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/TEST.md) - [ ] Update [changelog](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/charts/sourcegraph/CHANGELOG.md) - [ ] Update [Kubernetes update doc](https://docs.sourcegraph.com/admin/updates/kubernetes) ### Test plan Tested with customer <!-- As part of SOC2/GN-104 and SOC2/GN-105 requirements, all pull requests are REQUIRED to provide a "test plan". A test plan is a loose explanation of what you have done or implemented to test this, as outlined in our Testing principles and guidelines: https://docs.sourcegraph.com/dev/background-information/testing_principles Write your test plan here after the "Test plan" header. -->
1 parent 9177600 commit c96a004

File tree

13 files changed

+48
-13
lines changed

13 files changed

+48
-13
lines changed

charts/sourcegraph/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ In addition to the documented values, all services also support the following va
249249
| preciseCodeIntel.resources | object | `{"limits":{"cpu":"2","memory":"4G"},"requests":{"cpu":"500m","memory":"2G"}}` | Resource requests & limits for the `precise-code-intel-worker` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
250250
| preciseCodeIntel.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `precise-code-intel-worker` |
251251
| preciseCodeIntel.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
252-
| priorityClasses | list | `[]` | Additional priorityClasses minimise re-scheduling downtime for StatefulSets. Each StatefulSets might use different priority class. learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass) Sample class definition: - name: gitserver-class value: 100 preemptionPolicy: Never description: "gitserver priority class" |
252+
| priorityClasses | list | `[]` | Additional priorityClasses minimize re-scheduling downtime for StatefulSets. Each StatefulSets might use different priority class. learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass) Sample class definition: - name: gitserver-class value: 100 preemptionPolicy: Never description: "gitserver priority class" |
253253
| prometheus.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":false,"runAsGroup":100,"runAsUser":100}` | Security context for the `prometheus` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
254+
| prometheus.createRoleBinding | bool | `true` | Disable the creation of a RoleBinding object, for customers who block all RBAC resource creation |
254255
| prometheus.enabled | bool | `true` | Enable `prometheus` (recommended) |
255256
| prometheus.existingConfig | string | `""` | Name of existing ConfigMap for `pgsql`. It must contain a `prometheus.yml` key |
256257
| prometheus.image.defaultTag | string | `"6.0.0@sha256:86a315720fd9813d9ef9746d92e637bc20cd9ebd90da78d8cc6906062252891f"` | Docker image tag for the `prometheus` image |
@@ -302,6 +303,7 @@ In addition to the documented values, all services also support the following va
302303
| searcher.storageSize | string | `"26Gi"` | Size of the PVC for searcher pods to store cache data |
303304
| sgTestConnection | object | `{"enabled":true}` | Enable the busybox connection test after deployment |
304305
| sourcegraph.affinity | object | `{}` | Global Affinity, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) |
306+
| sourcegraph.disableKubernetesSecrets | bool | `false` | Disable the creation of Kubernetes secrets objects |
305307
| sourcegraph.image.defaultTag | string | `"{{ .Chart.AppVersion }}"` | Global docker image tag |
306308
| sourcegraph.image.pullPolicy | string | `"IfNotPresent"` | Global docker image pull policy |
307309
| sourcegraph.image.repository | string | `"index.docker.io/sourcegraph"` | Global docker image registry or prefix |

charts/sourcegraph/templates/_helpers.tpl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ For top-level services, pass in the top-level values:
4545
{{ include "sourcegraph.serviceAccountName" (list . "frontend") }}
4646

4747
frontend:
48-
serivceAccount:
48+
serviceAccount:
4949
create: false
5050

5151
For nested services, pass in the nested values:
@@ -248,7 +248,25 @@ app.kubernetes.io/name: jaeger
248248
value: "localhost:$(DATA_SOURCE_PORT)/$(DATA_SOURCE_DB)?sslmode=disable"
249249
{{- end }}
250250

251+
{{/*
252+
Set redisCache and redisStore endpoints
253+
So that customers can configure them any of these ways:
254+
1. Create a new Kubernetes secret, with default values (default, no override config required)
255+
2. Use an existing Kubernetes secret, by configuring .Values.redisCache.connection.existingSecret
256+
3. Do not create or use Kubernetes secrets, just pass the default values directly as environment variables into the needed pods, by configuring .Values.sourcegraph.disableKubernetesSecrets = true
257+
4. Do not create or use Kubernetes secrets, but pass custom values (ex. external Redis) directly as environment variables into the needed pods, by configuring .Values.sourcegraph.disableKubernetesSecrets = true, .Values.redisCache.connection.endpoint = "", .Values.redisStore.connection.endpoint = "", and defining the REDIS_CACHE_ENDPOINT and REDIS_STORE_ENDPOINT env vars on frontend, gitserver, searcher, and worker pods
258+
*/}}
251259
{{- define "sourcegraph.redisConnection" -}}
260+
{{- if .Values.sourcegraph.disableKubernetesSecrets -}}
261+
{{- if .Values.redisCache.connection.endpoint -}}
262+
- name: REDIS_CACHE_ENDPOINT
263+
value: {{ .Values.redisCache.connection.endpoint }}
264+
{{- end -}}
265+
{{- if .Values.redisStore.connection.endpoint -}}
266+
- name: REDIS_STORE_ENDPOINT
267+
value: {{ .Values.redisStore.connection.endpoint }}
268+
{{- end -}}
269+
{{- else -}}
252270
- name: REDIS_CACHE_ENDPOINT
253271
valueFrom:
254272
secretKeyRef:
@@ -259,7 +277,8 @@ app.kubernetes.io/name: jaeger
259277
secretKeyRef:
260278
key: endpoint
261279
name: {{ default .Values.redisStore.name .Values.redisStore.connection.existingSecret }}
262-
{{- end }}
280+
{{- end -}}
281+
{{- end -}}
263282

264283
{{- define "sourcegraph.authChecksum" -}}
265284
{{- $checksum := list .Values.codeInsightsDB.auth -}}

charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if not .Values.codeInsightsDB.auth.existingSecret }}
1+
{{- if and (not .Values.sourcegraph.disableKubernetesSecrets) (not .Values.codeInsightsDB.auth.existingSecret) -}}
22
apiVersion: v1
33
kind: Secret
44
metadata:

charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if not .Values.codeIntelDB.auth.existingSecret }}
1+
{{- if and (not .Values.sourcegraph.disableKubernetesSecrets) (not .Values.codeIntelDB.auth.existingSecret) -}}
22
apiVersion: v1
33
kind: Secret
44
metadata:

charts/sourcegraph/templates/frontend/sourcegraph-frontend.Deployment.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ spec:
5252
- name: migrator
5353
image: {{ include "sourcegraph.image" (list . "migrator") }}
5454
imagePullPolicy: {{ .Values.sourcegraph.image.pullPolicy }}
55+
{{- if .Values.migrator.command }}
56+
command: {{ .Values.migrator.command }}
57+
{{- end }}
5558
args: {{- default (list "up") .Values.migrator.args | toYaml | nindent 8 }}
5659
env:
57-
{{- if not .Values.migrator.databaseAuthOverrideEnvVars }}
60+
{{- if and (not .Values.migrator.databaseAuthOverrideEnvVars) (not .Values.sourcegraph.disableKubernetesSecrets) }}
5861
{{- include "sourcegraph.databaseAuth" (list . "pgsql" "PG") | nindent 8 }}
5962
{{- include "sourcegraph.databaseAuth" (list . "codeIntelDB" "CODEINTEL_PG") | nindent 8 }}
6063
{{- include "sourcegraph.databaseAuth" (list . "codeInsightsDB" "CODEINSIGHTS_PG") | nindent 8 }}
@@ -78,11 +81,16 @@ spec:
7881
- name: frontend
7982
image: {{ include "sourcegraph.image" (list . "frontend") }}
8083
imagePullPolicy: {{ .Values.sourcegraph.image.pullPolicy }}
84+
{{- if .Values.frontend.command }}
85+
command: {{ .Values.frontend.command }}
86+
{{- end }}
8187
args: {{- default (list "serve") .Values.frontend.args | toYaml | nindent 8 }}
8288
env:
89+
{{- if not .Values.sourcegraph.disableKubernetesSecrets }}
8390
{{- include "sourcegraph.databaseAuth" (list . "pgsql" "PG") | nindent 8 }}
8491
{{- include "sourcegraph.databaseAuth" (list . "codeIntelDB" "CODEINTEL_PG") | nindent 8 }}
8592
{{- include "sourcegraph.databaseAuth" (list . "codeInsightsDB" "CODEINSIGHTS_PG") | nindent 8 }}
93+
{{- end }}
8694
{{- range $name, $item := .Values.frontend.env}}
8795
- name: {{ $name }}
8896
{{- $item | toYaml | nindent 10 }}

charts/sourcegraph/templates/grafana/grafana.StatefulSet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ spec:
5252
{{- end }}
5353
terminationMessagePolicy: FallbackToLogsOnError
5454
env:
55+
{{- if not .Values.sourcegraph.disableKubernetesSecrets -}}
5556
{{- include "sourcegraph.databaseAuth" (list . "grafana" "GRAFANA_PGSQL_") | nindent 8 }}
57+
{{- end -}}
5658
{{- range $name, $item := .Values.grafana.env}}
5759
- name: {{ $name }}
5860
{{- $item | toYaml | nindent 10 }}

charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.grafana.auth (not .Values.grafana.auth.existingSecret) }}
1+
{{- if and (not .Values.sourcegraph.disableKubernetesSecrets) .Values.grafana.auth (not .Values.grafana.auth.existingSecret) -}}
22
apiVersion: v1
33
kind: Secret
44
metadata:

charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if not .Values.pgsql.auth.existingSecret }}
1+
{{- if and (not .Values.sourcegraph.disableKubernetesSecrets) (not .Values.pgsql.auth.existingSecret) -}}
22
apiVersion: v1
33
kind: Secret
44
metadata:

charts/sourcegraph/templates/prometheus/prometheus.ClusterRoleBinding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.prometheus.enabled .Values.prometheus.privileged -}}
1+
{{- if and .Values.prometheus.enabled .Values.prometheus.privileged .Values.prometheus.createRoleBinding -}}
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRoleBinding
44
metadata:

charts/sourcegraph/templates/prometheus/prometheus.RoleBinding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.prometheus.enabled (not .Values.prometheus.privileged) -}}
1+
{{- if and .Values.prometheus.enabled (not .Values.prometheus.privileged) .Values.prometheus.createRoleBinding -}}
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: RoleBinding
44
metadata:

0 commit comments

Comments
 (0)