From a6902e9b8e0f5b15daea68a487787c9d4cefa7ed Mon Sep 17 00:00:00 2001 From: Michael Lin Date: Mon, 20 Feb 2023 10:47:07 -0800 Subject: [PATCH] sourcegraph: add `initContainers` support --- charts/sourcegraph/README.md.gotmpl | 1 + charts/sourcegraph/templates/_helpers.tpl | 10 +++ .../blobstore/blobstore.Deployment.yaml | 1 + .../indexed-search.StatefulSet.yaml | 3 +- .../initContainers_test.yaml.snap | 90 +++++++++++++++++++ .../tests/initContainers_test.yaml | 46 ++++++++++ 6 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 charts/sourcegraph/tests/__snapshot__/initContainers_test.yaml.snap create mode 100644 charts/sourcegraph/tests/initContainers_test.yaml diff --git a/charts/sourcegraph/README.md.gotmpl b/charts/sourcegraph/README.md.gotmpl index 078993df..4810b237 100644 --- a/charts/sourcegraph/README.md.gotmpl +++ b/charts/sourcegraph/README.md.gotmpl @@ -24,5 +24,6 @@ In addition to the documented values, all services also support the following va - `.env` - consult `values.yaml` file - `.serivceAccount.create` - create service account for service - `.serviceAccount.annotations` - Annotations for the service-specific service account +- `.initContainers` - [learn more](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) {{ template "chart.valuesTable" . }} diff --git a/charts/sourcegraph/templates/_helpers.tpl b/charts/sourcegraph/templates/_helpers.tpl index 29d4b5ba..e16eb064 100644 --- a/charts/sourcegraph/templates/_helpers.tpl +++ b/charts/sourcegraph/templates/_helpers.tpl @@ -239,3 +239,13 @@ checksum/auth: {{ toJson $checksum | sha256sum }} {{- $checksum := append $checksum .Values.redisCache.connection -}} checksum/redis: {{ toJson $checksum | sha256sum }} {{- end -}} + +{{- define "sourcegraph.initContainers" -}} +{{- $top := index . 0 }} +{{- $service := index . 1 }} +{{- $serviceInitContainers := (index $top.Values $service "initContainers") }} +{{- if $serviceInitContainers -}} +initContainers: +{{- $serviceInitContainers | toYaml | trim | nindent 2 -}} +{{- end -}} +{{- end -}} diff --git a/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml b/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml index 25dae8f3..8103f4be 100644 --- a/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml +++ b/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml @@ -43,6 +43,7 @@ spec: deploy: sourcegraph app: blobstore spec: + {{- include "sourcegraph.initContainers" (list . "blobstore") | nindent 6 }} containers: - name: blobstore env: diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml index 9a433c80..0997888b 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml @@ -21,7 +21,7 @@ spec: serviceName: indexed-search template: metadata: - {{- if or .Values.sourcegraph.podAnnotations .Values.indexedSearch.podAnnotations }} + {{- if or .Values.sourcegraph.podAnnotations .Values.indexedSearch.podAnnotations -}} annotations: {{- if .Values.sourcegraph.podAnnotations }} {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} @@ -41,6 +41,7 @@ spec: app: indexed-search deploy: sourcegraph spec: + {{- include "sourcegraph.initContainers" (list . "indexedSearch") | nindent 6 }} containers: - name: zoekt-webserver image: {{ include "sourcegraph.image" (list . "indexedSearch") }} diff --git a/charts/sourcegraph/tests/__snapshot__/initContainers_test.yaml.snap b/charts/sourcegraph/tests/__snapshot__/initContainers_test.yaml.snap new file mode 100644 index 00000000..3fcd5c17 --- /dev/null +++ b/charts/sourcegraph/tests/__snapshot__/initContainers_test.yaml.snap @@ -0,0 +1,90 @@ +should not render initContainers when it is not set: + 1: | + null +should render initContainers when it is set: + 1: | + affinity: null + containers: + - env: + - name: OTEL_AGENT_HOST + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://$(OTEL_AGENT_HOST):4317 + - name: OPENTELEMETRY_DISABLED + value: "false" + image: index.docker.io/sourcegraph/indexed-searcher:4.4.2@sha256:013190418308b94521e072972ae2342c41f99144205f58d61f5dfeda29ac0f58 + imagePullPolicy: IfNotPresent + name: zoekt-webserver + ports: + - containerPort: 6070 + name: http + readinessProbe: + failureThreshold: 3 + httpGet: + path: /healthz + port: http + scheme: HTTP + periodSeconds: 5 + timeoutSeconds: 5 + resources: + limits: + cpu: "2" + memory: 4G + requests: + cpu: 500m + memory: 2G + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + runAsGroup: 101 + runAsUser: 100 + terminationMessagePolicy: FallbackToLogsOnError + volumeMounts: + - mountPath: /data + name: data + - env: + - name: OTEL_AGENT_HOST + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://$(OTEL_AGENT_HOST):4317 + - name: OPENTELEMETRY_DISABLED + value: "false" + image: index.docker.io/sourcegraph/search-indexer:4.4.2@sha256:7716a32597300f7dfb7e974465a3bd3c62fae3aa485b48d9aa9f79ea3348f87f + imagePullPolicy: IfNotPresent + name: zoekt-indexserver + ports: + - containerPort: 6072 + name: index-http + resources: + limits: + cpu: "8" + memory: 8G + requests: + cpu: "4" + memory: 4G + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + runAsGroup: 101 + runAsUser: 100 + terminationMessagePolicy: FallbackToLogsOnError + volumeMounts: + - mountPath: /data + name: data + initContainers: + - command: + - echo + - hello + image: alpine + name: init + nodeSelector: null + securityContext: + fsGroup: 101 + fsGroupChangePolicy: OnRootMismatch + tolerations: null + volumes: + - name: data diff --git a/charts/sourcegraph/tests/initContainers_test.yaml b/charts/sourcegraph/tests/initContainers_test.yaml new file mode 100644 index 00000000..94448d3f --- /dev/null +++ b/charts/sourcegraph/tests/initContainers_test.yaml @@ -0,0 +1,46 @@ +suite: affinity +templates: +- searcher/searcher.StatefulSet.yaml +- indexed-search/indexed-search.StatefulSet.yaml +- codeinsights-db/codeinsights-db.StatefulSet.yaml +- grafana/grafana.StatefulSet.yaml +- codeintel-db/codeintel-db.StatefulSet.yaml +- symbols/symbols.StatefulSet.yaml +- pgsql/pgsql.StatefulSet.yaml +- gitserver/gitserver.StatefulSet.yaml +- frontend/sourcegraph-frontend.Deployment.yaml +- redis/redis-store.Deployment.yaml +- redis/redis-cache.Deployment.yaml +- jaeger/jaeger.Deployment.yaml +- blobstore/blobstore.Deployment.yaml +- syntect-server/syntect-server.Deployment.yaml +- precise-code-intel/worker.Deployment.yaml +- otel-collector/otel-collector.Deployment.yaml +- prometheus/prometheus.Deployment.yaml +- github-proxy/github-proxy.Deployment.yaml +- worker/worker.Deployment.yaml +release: + name: sourcegraph + namespace: sourcegraph +tests: +- it: should render initContainers when it is set + set: + indexedSearch: + initContainers: + - name: init + image: alpine + command: ["echo", "hello"] + asserts: + - equal: + path: spec.template.spec.initContainers + value: + - name: init + image: alpine + command: ["echo", "hello"] + - matchSnapshot: + path: spec.template.spec + +- it: should not render initContainers when it is not set + asserts: + - matchSnapshot: + path: spec.template.spec.initContainers