Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions charts/sourcegraph-executor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- START CHANGELOG -->
## Unreleased

- Fixed a label or pod annotation key set both in `sourcegraph.labels`, `sourcegraph.podLabels`, or `sourcegraph.podAnnotations` and in the `executor` or `privateDockerRegistry` equivalent being rendered twice in one map. Helm used the last one, but kustomize rejected the manifest. Each key is now rendered once, with the component's value, so Helm releases render the same objects as before.

## 8.0.0

* Added a `network-policy` example to the `sourcegraph-executor-k8s` and `sourcegraph-executor-dind` charts, with `CiliumNetworkPolicy` resources which limit Executor and job pods to the frontend API.
Expand Down
39 changes: 23 additions & 16 deletions charts/sourcegraph-executor/dind/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- end }}

{{/*
Merges a list of maps, such as the labels or annotations set globally and per
component, so each key is rendered once. A later map wins when a key is set in
more than one. Kustomize rejects a key rendered twice in one map. Renders
nothing when every map is empty.

{{ include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.frontend.podLabels) }}
*/}}
{{- define "sourcegraph.mergedMaps" -}}
{{- $merged := dict -}}
{{- range . -}}
{{- range $key, $value := . -}}
{{- $_ := set $merged $key $value -}}
{{- end -}}
{{- end -}}
{{- with $merged -}}
{{- toYaml . -}}
{{- end -}}
{{- end }}

{{/*
Selector labels
*/}}
Expand Down Expand Up @@ -136,10 +156,7 @@ metadata:
description: Runs sourcegraph executors
kubectl.kubernetes.io/default-container: executor
labels:
{{- include "sourcegraph.labels" $r | nindent 4 }}
{{- if $r.Values.executor.labels }}
{{- toYaml $r.Values.executor.labels | nindent 4 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list (include "sourcegraph.labels" $r | fromYaml) $r.Values.executor.labels) | nindent 4 }}
app: {{ .name }}
deploy: sourcegraph
sourcegraph-resource-requires: no-cluster-admin
Expand All @@ -162,20 +179,10 @@ spec:
annotations:
kubectl.kubernetes.io/default-container: executor
checksum/docker-config: {{ include "dind.daemonConfig" $r | sha256sum }}
{{- if $r.Values.sourcegraph.podAnnotations }}
{{- toYaml $r.Values.sourcegraph.podAnnotations | nindent 8 }}
{{- end }}
{{- if $r.Values.executor.podAnnotations }}
{{- toYaml $r.Values.executor.podAnnotations | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list $r.Values.sourcegraph.podAnnotations $r.Values.executor.podAnnotations) | nindent 8 }}
labels:
{{- include "sourcegraph.selectorLabels" $r | nindent 8 }}
{{- if $r.Values.sourcegraph.podLabels }}
{{- toYaml $r.Values.sourcegraph.podLabels | nindent 8 }}
{{- end }}
{{- if $r.Values.executor.podLabels }}
{{- toYaml $r.Values.executor.podLabels | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list $r.Values.sourcegraph.podLabels $r.Values.executor.podLabels) | nindent 8 }}
app: {{ .name }}
deploy: sourcegraph
sourcegraph-resource-requires: no-cluster-admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ kind: StatefulSet
metadata:
name: private-docker-registry
labels:
{{- include "sourcegraph.labels" . | nindent 4 }}
{{- if .Values.privateDockerRegistry.labels }}
{{- toYaml .Values.privateDockerRegistry.labels | nindent 4 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list (include "sourcegraph.labels" . | fromYaml) .Values.privateDockerRegistry.labels) | nindent 4 }}
deploy: sourcegraph
app.kubernetes.io/component: private-docker-registry
spec:
Expand All @@ -23,20 +20,10 @@ spec:
metadata:
annotations:
kubectl.kubernetes.io/default-container: private-docker-registry
{{- if .Values.sourcegraph.podAnnotations }}
{{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }}
{{- end }}
{{- if .Values.privateDockerRegistry.podAnnotations }}
{{- toYaml .Values.privateDockerRegistry.podAnnotations | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podAnnotations .Values.privateDockerRegistry.podAnnotations) | nindent 8 }}
labels:
{{- include "sourcegraph.selectorLabels" . | nindent 8 }}
{{- if .Values.sourcegraph.podLabels }}
{{- toYaml .Values.sourcegraph.podLabels | nindent 8 }}
{{- end }}
{{- if .Values.privateDockerRegistry.podLabels }}
{{- toYaml .Values.privateDockerRegistry.podLabels | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.privateDockerRegistry.podLabels) | nindent 8 }}
deploy: sourcegraph
app: private-docker-registry
spec:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Used by CI: the "Render charts through kustomize" GitHub Actions job
# (.github/workflows/kustomize_render.yml) renders this chart with this file
# through scripts/ci/kustomize-render.sh.
#
# The same label and annotation keys at the global and per-component levels,
# where the per-component value should win. Without deduplication, the chart
# renders the key twice in one map, which kustomize rejects.

sourcegraph:
labels:
example.com/team: platform
podLabels:
example.com/team: platform
podAnnotations:
metrics.example.com/port: "9090"

executor:
frontendUrl: https://sourcegraph.example.com
frontendExistingSecret: example-secret
queueName: batches
labels:
example.com/team: executors
podLabels:
example.com/team: executors
podAnnotations:
metrics.example.com/port: "6060"

privateDockerRegistry:
labels:
example.com/team: registry
podLabels:
example.com/team: registry
podAnnotations:
metrics.example.com/port: "6060"
20 changes: 20 additions & 0 deletions charts/sourcegraph-executor/k8s/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- end }}

{{/*
Merges a list of maps, such as the labels or annotations set globally and per
component, so each key is rendered once. A later map wins when a key is set in
more than one. Kustomize rejects a key rendered twice in one map. Renders
nothing when every map is empty.

{{ include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.frontend.podLabels) }}
*/}}
{{- define "sourcegraph.mergedMaps" -}}
{{- $merged := dict -}}
{{- range . -}}
{{- range $key, $value := . -}}
{{- $_ := set $merged $key $value -}}
{{- end -}}
{{- end -}}
{{- with $merged -}}
{{- toYaml . -}}
{{- end -}}
{{- end }}

{{/*
Selector labels
*/}}
Expand Down
14 changes: 2 additions & 12 deletions charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,10 @@ spec:
metadata:
annotations:
kubectl.kubernetes.io/default-container: executor
{{- if .Values.sourcegraph.podAnnotations }}
{{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }}
{{- end }}
{{- if .Values.executor.podAnnotations }}
{{- toYaml .Values.executor.podAnnotations | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podAnnotations .Values.executor.podAnnotations) | nindent 8 }}
labels:
{{- include "sourcegraph.selectorLabels" . | nindent 8 }}
{{- if .Values.sourcegraph.podLabels }}
{{- toYaml .Values.sourcegraph.podLabels | nindent 8 }}
{{- end }}
{{- if .Values.executor.podLabels }}
{{- toYaml .Values.executor.podLabels | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.executor.podLabels) | nindent 8 }}
{{- include "executor.labels" . | nindent 8 }}
spec:
securityContext:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Used by CI: the "Render charts through kustomize" GitHub Actions job
# (.github/workflows/kustomize_render.yml) renders this chart with this file
# through scripts/ci/kustomize-render.sh.
#
# The same label and annotation keys at the global and per-component levels,
# where the per-component value should win. Without deduplication, the chart
# renders the key twice in one map, which kustomize rejects.

sourcegraph:
labels:
example.com/team: platform
podLabels:
example.com/team: platform
podAnnotations:
metrics.example.com/port: "9090"

executor:
frontendUrl: https://sourcegraph.example.com
frontendExistingSecret: example-secret
queueName: batches
labels:
example.com/team: executors
podLabels:
example.com/team: executors
podAnnotations:
metrics.example.com/port: "6060"
20 changes: 20 additions & 0 deletions charts/sourcegraph-migrator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- end }}

{{/*
Merges a list of maps, such as the labels or annotations set globally and per
component, so each key is rendered once. A later map wins when a key is set in
more than one. Kustomize rejects a key rendered twice in one map. Renders
nothing when every map is empty.

{{ include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.frontend.podLabels) }}
*/}}
{{- define "sourcegraph.mergedMaps" -}}
{{- $merged := dict -}}
{{- range . -}}
{{- range $key, $value := . -}}
{{- $_ := set $merged $key $value -}}
{{- end -}}
{{- end -}}
{{- with $merged -}}
{{- toYaml . -}}
{{- end -}}
{{- end }}

{{/*
Selector labels
*/}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ metadata:
annotations:
description: Performs Sourcegraph database migrations.
labels:
{{- include "sourcegraph.labels" . | nindent 4 }}
{{- if .Values.migrator.labels }}
{{- toYaml .Values.migrator.labels | nindent 4 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list (include "sourcegraph.labels" . | fromYaml) .Values.migrator.labels) | nindent 4 }}
deploy: sourcegraph
app.kubernetes.io/component: migrator
name: {{ default "migrator" .Values.migrator.name }}-{{ randAlphaNum 5 | lower }}
Expand All @@ -17,20 +14,10 @@ spec:
metadata:
annotations:
kubectl.kubernetes.io/default-container: migrator
{{- if .Values.sourcegraph.podAnnotations }}
{{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }}
{{- end }}
{{- if .Values.migrator.podAnnotations }}
{{- toYaml .Values.migrator.podAnnotations | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podAnnotations .Values.migrator.podAnnotations) | nindent 8 }}
labels:
{{- include "sourcegraph.selectorLabels" . | nindent 8 }}
{{- if .Values.sourcegraph.podLabels }}
{{- toYaml .Values.sourcegraph.podLabels | nindent 8 }}
{{- end }}
{{- if .Values.migrator.podLabels }}
{{- toYaml .Values.migrator.podLabels | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.migrator.podLabels) | nindent 8 }}
job: migrator
deploy: sourcegraph
spec:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Used by CI: the "Render charts through kustomize" GitHub Actions job
# (.github/workflows/kustomize_render.yml) renders this chart with this file
# through scripts/ci/kustomize-render.sh.
#
# The same label and annotation keys at the global and per-component levels,
# where the per-component value should win. Without deduplication, the chart
# renders the key twice in one map, which kustomize rejects.

sourcegraph:
labels:
example.com/team: platform
podLabels:
example.com/team: platform
podAnnotations:
metrics.example.com/port: "9090"

migrator:
labels:
example.com/team: database
podLabels:
example.com/team: database
podAnnotations:
metrics.example.com/port: "6060"
1 change: 1 addition & 0 deletions charts/sourcegraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Use `**BREAKING**:` to denote a breaking change

## Unreleased

- Fixed a label or pod annotation key set both globally (`sourcegraph.labels`, `sourcegraph.podLabels`, `sourcegraph.podAnnotations`) and per component (`<serviceName>.labels`, `.podLabels`, `.podAnnotations`, or `openTelemetry.gateway.serviceLabels`) being rendered twice in one map. Helm used the last one, but kustomize rejected the manifest. Each key is now rendered once, with the component's value, so Helm releases render the same objects as before.
- 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.
- 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).
- 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.
Expand Down
20 changes: 20 additions & 0 deletions charts/sourcegraph/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- end }}

{{/*
Merges a list of maps, such as the labels or annotations set globally and per
component, so each key is rendered once. A later map wins when a key is set in
more than one. Kustomize rejects a key rendered twice in one map. Renders
nothing when every map is empty.

{{ include "sourcegraph.mergedMaps" (list .Values.sourcegraph.podLabels .Values.frontend.podLabels) }}
*/}}
{{- define "sourcegraph.mergedMaps" -}}
{{- $merged := dict -}}
{{- range . -}}
{{- range $key, $value := . -}}
{{- $_ := set $merged $key $value -}}
{{- end -}}
{{- end -}}
{{- with $merged -}}
{{- toYaml . -}}
{{- end -}}
{{- end }}

{{/*
Selector labels, shared by a component's workload selector, pod labels, and
Service and PodDisruptionBudget selectors, so they cannot drift apart.
Expand Down
19 changes: 3 additions & 16 deletions charts/sourcegraph/templates/_worker.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ metadata:
annotations:
description: Manages background processes.
labels:
{{- include "sourcegraph.labels" $top | nindent 4 }}
{{- if $top.Values.worker.labels }}
{{- toYaml $top.Values.worker.labels | nindent 4 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list (include "sourcegraph.labels" $top | fromYaml) $top.Values.worker.labels) | nindent 4 }}
deploy: sourcegraph
app.kubernetes.io/component: worker
name: {{ $name }}
Expand All @@ -44,20 +41,10 @@ spec:
annotations:
kubectl.kubernetes.io/default-container: worker
{{- include "sourcegraph.redisChecksum" $top | nindent 8 }}
{{- if $top.Values.sourcegraph.podAnnotations }}
{{- toYaml $top.Values.sourcegraph.podAnnotations | nindent 8 }}
{{- end }}
{{- if $top.Values.worker.podAnnotations }}
{{- toYaml $top.Values.worker.podAnnotations | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list $top.Values.sourcegraph.podAnnotations $top.Values.worker.podAnnotations) | nindent 8 }}
labels:
{{- include "sourcegraph.selectorLabels" (list $top $top.Values.worker) | nindent 8 }}
{{- if $top.Values.sourcegraph.podLabels }}
{{- toYaml $top.Values.sourcegraph.podLabels | nindent 8 }}
{{- end }}
{{- if $top.Values.worker.podLabels }}
{{- toYaml $top.Values.worker.podLabels | nindent 8 }}
{{- end }}
{{- include "sourcegraph.mergedMaps" (list $top.Values.sourcegraph.podLabels $top.Values.worker.podLabels) | nindent 8 }}
deploy: sourcegraph
app: worker
{{- if $suffix }}
Expand Down
Loading
Loading