diff --git a/charts/sourcegraph-executor/dind/README.md b/charts/sourcegraph-executor/dind/README.md index 14bff60a9..37b1523c7 100644 --- a/charts/sourcegraph-executor/dind/README.md +++ b/charts/sourcegraph-executor/dind/README.md @@ -98,7 +98,7 @@ In addition to the documented values, the `executor` and `private-docker-registr | sourcegraph.image.repository | string | Sourcegraph's public Docker Hub registry | Global docker image registry or prefix | | sourcegraph.image.useGlobalTagAsDefault | bool | `false` | When set to true, sourcegraph.image.defaultTag is used as the default defaultTag for all services, instead of service-specific default defaultTags | | sourcegraph.imagePullSecrets | list | `[]` | Mount named secrets containing docker credentials | -| sourcegraph.labels | object | `{}` | Add a global label to all resources | +| sourcegraph.labels | object | `{}` | Add a global label to every resource the chart creates. The chart does not add it to pod templates (use `sourcegraph.podLabels`), or to the volume claim template of the `private-docker-registry` StatefulSet, which Kubernetes does not allow changing | | sourcegraph.nameOverride | string | `""` | Set a custom name for the app.kubernetes.io/name annotation | | sourcegraph.nodeSelector | object | `{}` | NodeSelector, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | | sourcegraph.podAnnotations | object | `{}` | Add extra annotations to attach to all pods | diff --git a/charts/sourcegraph-executor/dind/templates/_helpers.tpl b/charts/sourcegraph-executor/dind/templates/_helpers.tpl index 8b87b5d24..5f7d7aa71 100644 --- a/charts/sourcegraph-executor/dind/templates/_helpers.tpl +++ b/charts/sourcegraph-executor/dind/templates/_helpers.tpl @@ -136,14 +136,14 @@ 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 }} - app: {{ .name }} - deploy: sourcegraph - sourcegraph-resource-requires: no-cluster-admin - app.kubernetes.io/component: executor + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" $r) + $r.Values.executor.labels + (printf "app: %s" .name) + "deploy: sourcegraph" + "sourcegraph-resource-requires: no-cluster-admin" + "app.kubernetes.io/component: executor" + ) | nindent 4 }} spec: selector: matchLabels: @@ -160,26 +160,22 @@ spec: template: metadata: 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.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: executor" + (printf "checksum/docker-config: %s" (include "dind.daemonConfig" $r | sha256sum)) + $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 }} - app: {{ .name }} - deploy: sourcegraph - sourcegraph-resource-requires: no-cluster-admin - app.kubernetes.io/component: executor + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" $r) + $r.Values.sourcegraph.podLabels + $r.Values.executor.podLabels + (printf "app: %s" .name) + "deploy: sourcegraph" + "sourcegraph-resource-requires: no-cluster-admin" + "app.kubernetes.io/component: executor" + ) | nindent 8 }} spec: {{- with $r.Values.executor.podSecurityContext }} securityContext: diff --git a/charts/sourcegraph-executor/dind/templates/_helpers/_uniqueKeys.tpl b/charts/sourcegraph-executor/dind/templates/_helpers/_uniqueKeys.tpl new file mode 100644 index 000000000..9e8a9ffb1 --- /dev/null +++ b/charts/sourcegraph-executor/dind/templates/_helpers/_uniqueKeys.tpl @@ -0,0 +1,54 @@ +{{/* + +Render label or annotation maps as one map, with each key once. + +Strict YAML parsers, such as Kustomize, reject a map that repeats a key. Helm +and Kubernetes accept it and keep the last value. This keeps the last value +too, so the objects of an installed release do not change. + +Pass a list of maps, lowest precedence first. Each item is a map from the +values, or the text of one or more `key: value` lines. The lines are passed +through as written, so when no key repeats, the output is the same text as +rendering the items one after the other. + +labels: + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.sourcegraph.podLabels + "deploy: sourcegraph" + ) | nindent 2 }} + +*/}} + +{{- define "sourcegraph.uniqueKeys" -}} +{{- /* Split every item into entries: one `key: value`, with any lines of a multi-line value. */ -}} +{{- $entries := list -}} +{{- range $source := . -}} + {{- $text := "" -}} + {{- if and $source (kindIs "map" $source) -}} + {{- $text = toYaml $source -}} + {{- else if kindIs "string" $source -}} + {{- $text = trim $source -}} + {{- end -}} + {{- if $text -}} + {{- range $line := splitList "\n" $text -}} + {{- if and $entries (or (not $line) (hasPrefix " " $line)) -}} + {{- $entries = append (initial $entries) (printf "%s\n%s" (last $entries) $line) -}} + {{- else -}} + {{- $entries = append $entries $line -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- /* Keep the last entry of each key. */ -}} +{{- $seen := dict -}} +{{- $unique := list -}} +{{- range $entry := reverse $entries -}} + {{- $key := splitList ":" $entry | first | trimAll "\"'" -}} + {{- if not (hasKey $seen $key) -}} + {{- $_ := set $seen $key true -}} + {{- $unique = prepend $unique $entry -}} + {{- end -}} +{{- end -}} +{{- join "\n" $unique -}} +{{- end -}} diff --git a/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml b/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml index ecd96f99b..e1d1cc2f8 100644 --- a/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml +++ b/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml @@ -2,9 +2,12 @@ apiVersion: v1 kind: ConfigMap metadata: labels: - app: executor - deploy: sourcegraph - app.kubernetes.io/component: executor + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: executor" + "deploy: sourcegraph" + "app.kubernetes.io/component: executor" + ) | nindent 4 }} name: docker-config data: daemon.json: | diff --git a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml index 356293ca8..7ae6e25d8 100644 --- a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml +++ b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml @@ -7,9 +7,12 @@ metadata: {{- toYaml .Values.privateDockerRegistry.serviceAnnotations | nindent 4 }} {{- end }} labels: - app: private-docker-registry - deploy: sourcegraph - app.kubernetes.io/component: private-docker-registry + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: private-docker-registry" + "deploy: sourcegraph" + "app.kubernetes.io/component: private-docker-registry" + ) | nindent 4 }} name: private-docker-registry spec: ports: diff --git a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml index 71f3194e8..837dd76c3 100644 --- a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml +++ b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml @@ -4,12 +4,12 @@ kind: StatefulSet metadata: name: private-docker-registry labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.privateDockerRegistry.labels }} - {{- toYaml .Values.privateDockerRegistry.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: private-docker-registry + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.privateDockerRegistry.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: private-docker-registry" + ) | nindent 4 }} spec: replicas: 1 serviceName: private-docker-registry @@ -22,23 +22,19 @@ spec: template: 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.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: private-docker-registry" + .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 }} - deploy: sourcegraph - app: private-docker-registry + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" .) + .Values.sourcegraph.podLabels + .Values.privateDockerRegistry.podLabels + "deploy: sourcegraph" + "app: private-docker-registry" + ) | nindent 8 }} spec: containers: - name: private-docker-registry diff --git a/charts/sourcegraph-executor/dind/tests/labels_test.yaml b/charts/sourcegraph-executor/dind/tests/labels_test.yaml new file mode 100644 index 000000000..8e384318d --- /dev/null +++ b/charts/sourcegraph-executor/dind/tests/labels_test.yaml @@ -0,0 +1,80 @@ +# sourcegraph.labels is documented as a label for every resource the chart +# creates. The first suite asserts on every template, so a new template that +# leaves the labels out fails here. +suite: sourcegraph.labels on every resource +templates: + - "*/*.yaml" +set: + queues: + - name: batches + - name: codeintel + sourcegraph: + labels: + example.com/cost-center: "1234" +tests: + - it: should add the labels to every resource + asserts: + - equal: + path: metadata.labels["example.com/cost-center"] + value: "1234" + + - it: should not add the labels to pod templates and the volume claim template + template: private-docker-registry/private-docker-registry.Statefulset.yaml + asserts: + - notExists: + path: spec.template.metadata.labels["example.com/cost-center"] + - notExists: + path: spec.volumeClaimTemplates[0].metadata.labels["example.com/cost-center"] +--- +# helm-unittest fails a test when any rendered manifest repeats a key, as +# Kustomize does. +suite: unique keys +set: + executor: + queueName: test +tests: + - it: should render a key set in several values once + set: + sourcegraph: + labels: &labels + example.com/team: platform + app: from-values + deploy: from-values + helm.sh/chart: from-values + podLabels: &podLabels + example.com/team: platform + app: from-values + deploy: from-values + podAnnotations: &annotations + example.com/owner: platform + kubectl.kubernetes.io/default-container: from-values + executor: &component + labels: + <<: *labels + example.com/team: component + podLabels: + <<: *podLabels + example.com/team: component + podAnnotations: + <<: *annotations + example.com/owner: component + privateDockerRegistry: *component + templates: + - executor/executor.Deployment.yaml + - private-docker-registry/private-docker-registry.Statefulset.yaml + asserts: + - equal: + path: metadata.labels["example.com/team"] + value: component + - equal: + path: metadata.labels.deploy + value: sourcegraph + - equal: + path: spec.template.metadata.labels["example.com/team"] + value: component + - equal: + path: spec.template.metadata.labels.deploy + value: sourcegraph + - equal: + path: spec.template.metadata.annotations["example.com/owner"] + value: component diff --git a/charts/sourcegraph-executor/dind/values.yaml b/charts/sourcegraph-executor/dind/values.yaml index 571ebe624..384deb527 100644 --- a/charts/sourcegraph-executor/dind/values.yaml +++ b/charts/sourcegraph-executor/dind/values.yaml @@ -14,7 +14,9 @@ sourcegraph: useGlobalTagAsDefault: false # -- Mount named secrets containing docker credentials imagePullSecrets: [] - # -- Add a global label to all resources + # -- Add a global label to every resource the chart creates. The chart does not add it to pod templates + # (use `sourcegraph.podLabels`), or to the volume claim template of the `private-docker-registry` StatefulSet, + # which Kubernetes does not allow changing labels: {} # -- Set a custom name for the app.kubernetes.io/name annotation nameOverride: "" diff --git a/charts/sourcegraph-executor/k8s/templates/_helpers/_uniqueKeys.tpl b/charts/sourcegraph-executor/k8s/templates/_helpers/_uniqueKeys.tpl new file mode 100644 index 000000000..9e8a9ffb1 --- /dev/null +++ b/charts/sourcegraph-executor/k8s/templates/_helpers/_uniqueKeys.tpl @@ -0,0 +1,54 @@ +{{/* + +Render label or annotation maps as one map, with each key once. + +Strict YAML parsers, such as Kustomize, reject a map that repeats a key. Helm +and Kubernetes accept it and keep the last value. This keeps the last value +too, so the objects of an installed release do not change. + +Pass a list of maps, lowest precedence first. Each item is a map from the +values, or the text of one or more `key: value` lines. The lines are passed +through as written, so when no key repeats, the output is the same text as +rendering the items one after the other. + +labels: + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.sourcegraph.podLabels + "deploy: sourcegraph" + ) | nindent 2 }} + +*/}} + +{{- define "sourcegraph.uniqueKeys" -}} +{{- /* Split every item into entries: one `key: value`, with any lines of a multi-line value. */ -}} +{{- $entries := list -}} +{{- range $source := . -}} + {{- $text := "" -}} + {{- if and $source (kindIs "map" $source) -}} + {{- $text = toYaml $source -}} + {{- else if kindIs "string" $source -}} + {{- $text = trim $source -}} + {{- end -}} + {{- if $text -}} + {{- range $line := splitList "\n" $text -}} + {{- if and $entries (or (not $line) (hasPrefix " " $line)) -}} + {{- $entries = append (initial $entries) (printf "%s\n%s" (last $entries) $line) -}} + {{- else -}} + {{- $entries = append $entries $line -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- /* Keep the last entry of each key. */ -}} +{{- $seen := dict -}} +{{- $unique := list -}} +{{- range $entry := reverse $entries -}} + {{- $key := splitList ":" $entry | first | trimAll "\"'" -}} + {{- if not (hasKey $seen $key) -}} + {{- $_ := set $seen $key true -}} + {{- $unique = prepend $unique $entry -}} + {{- end -}} +{{- end -}} +{{- join "\n" $unique -}} +{{- end -}} diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml index 6e773607b..58eb4efd1 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml @@ -3,7 +3,10 @@ kind: ConfigMap metadata: name: {{ include "executor.name" . }} labels: -{{- include "executor.labels" . | nindent 4 }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + (include "executor.labels" .) + ) | nindent 4 }} data: EXECUTOR_USE_FIRECRACKER: "false" EXECUTOR_FRONTEND_URL: "{{ .Values.executor.frontendUrl }}" diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml index 1cb35d2c4..920fe0dd1 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml @@ -6,10 +6,11 @@ metadata: description: Runs a sourcegraph executor kubectl.kubernetes.io/default-container: executor labels: - {{- include "executor.labels" . | nindent 4 }} - {{- if .Values.executor.labels }} - {{- toYaml .Values.executor.labels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + (include "executor.labels" .) + .Values.executor.labels + ) | nindent 4 }} spec: selector: matchLabels: @@ -29,22 +30,18 @@ spec: template: 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.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: executor" + .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 "executor.labels" . | nindent 8 }} + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" .) + .Values.sourcegraph.podLabels + .Values.executor.podLabels + (include "executor.labels" .) + ) | nindent 8 }} spec: securityContext: {{- if .Values.executor.podSecurityContext }} diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml index 7a3d1ef4d..70d6c078e 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml @@ -4,10 +4,13 @@ kind: Role metadata: name: sg-executor-role labels: - category: rbac - deploy: sourcegraph - sourcegraph-resource-requires: cluster-admin - app.kubernetes.io/component: executor + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "sourcegraph-resource-requires: cluster-admin" + "app.kubernetes.io/component: executor" + ) | nindent 4 }} rules: - apiGroups: - batch diff --git a/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml b/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml index f13311c5f..9fc38361d 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml @@ -4,10 +4,13 @@ kind: RoleBinding metadata: name: sg-executor-role-binding labels: - category: rbac - deploy: sourcegraph - sourcegraph-resource-requires: cluster-admin - app.kubernetes.io/component: executor + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "sourcegraph-resource-requires: cluster-admin" + "app.kubernetes.io/component: executor" + ) | nindent 4 }} subjects: - kind: ServiceAccount name: sg-executor diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml index 669afae55..c21df3497 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml @@ -3,6 +3,10 @@ apiVersion: v1 kind: Secret metadata: name: {{ include "executor.name" . }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} type: Opaque data: EXECUTOR_FRONTEND_PASSWORD: {{ .Values.executor.frontendPassword | b64enc | quote }} diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml index 33d841b3b..2046fadd2 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml @@ -6,10 +6,11 @@ metadata: {{- toYaml .Values.executor.serviceAnnotations | nindent 4 }} {{- end }} labels: -{{ include "executor.labels" . | indent 4 }} - {{- if .Values.executor.serviceLabels }} - {{- toYaml .Values.executor.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + (include "executor.labels" .) + .Values.executor.serviceLabels + ) | nindent 4 }} name: {{ include "executor.name" . }} spec: ports: diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml index 6a0f44627..3bf16c602 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml @@ -4,8 +4,11 @@ kind: ServiceAccount metadata: name: sg-executor labels: - category: rbac - deploy: sourcegraph - sourcegraph-resource-requires: cluster-admin - app.kubernetes.io/component: executor + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "sourcegraph-resource-requires: cluster-admin" + "app.kubernetes.io/component: executor" + ) | nindent 4 }} {{- end }} diff --git a/charts/sourcegraph-executor/k8s/tests/labels_test.yaml b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml new file mode 100644 index 000000000..77a9e86fb --- /dev/null +++ b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml @@ -0,0 +1,74 @@ +# sourcegraph.labels is documented as a label for all resources. The first +# suite asserts on every template, so a new template that leaves the labels +# out fails here. +suite: sourcegraph.labels on every resource +templates: + - "*.yaml" +set: + executor: + queueName: test + sourcegraph: + labels: + example.com/cost-center: "1234" +tests: + - it: should add the labels to every resource + asserts: + - equal: + path: metadata.labels["example.com/cost-center"] + value: "1234" + + - it: should not add the labels to the pod template + template: executor.Deployment.yaml + asserts: + - notExists: + path: spec.template.metadata.labels["example.com/cost-center"] +--- +# helm-unittest fails a test when any rendered manifest repeats a key, as +# Kustomize does. +suite: unique keys +set: + executor: + queueName: test +tests: + - it: should render a key set in several values once + set: + sourcegraph: + labels: &labels + example.com/team: platform + app: from-values + deploy: from-values + podLabels: *labels + podAnnotations: &annotations + example.com/owner: platform + kubectl.kubernetes.io/default-container: from-values + executor: + labels: + <<: *labels + example.com/team: executor + podLabels: + <<: *labels + example.com/team: executor + serviceLabels: *labels + podAnnotations: + <<: *annotations + example.com/owner: executor + template: executor.Deployment.yaml + asserts: + - equal: + path: metadata.labels["example.com/team"] + value: executor + - equal: + path: spec.template.metadata.labels["example.com/team"] + value: executor + - equal: + path: spec.template.metadata.labels.app + value: executor-test + - equal: + path: spec.template.metadata.annotations["example.com/owner"] + value: executor + + - it: should render no labels key on the Secret when sourcegraph.labels is unset + template: executor.Secret.yaml + asserts: + - notExists: + path: metadata.labels diff --git a/charts/sourcegraph-migrator/templates/_helpers/_uniqueKeys.tpl b/charts/sourcegraph-migrator/templates/_helpers/_uniqueKeys.tpl new file mode 100644 index 000000000..9e8a9ffb1 --- /dev/null +++ b/charts/sourcegraph-migrator/templates/_helpers/_uniqueKeys.tpl @@ -0,0 +1,54 @@ +{{/* + +Render label or annotation maps as one map, with each key once. + +Strict YAML parsers, such as Kustomize, reject a map that repeats a key. Helm +and Kubernetes accept it and keep the last value. This keeps the last value +too, so the objects of an installed release do not change. + +Pass a list of maps, lowest precedence first. Each item is a map from the +values, or the text of one or more `key: value` lines. The lines are passed +through as written, so when no key repeats, the output is the same text as +rendering the items one after the other. + +labels: + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.sourcegraph.podLabels + "deploy: sourcegraph" + ) | nindent 2 }} + +*/}} + +{{- define "sourcegraph.uniqueKeys" -}} +{{- /* Split every item into entries: one `key: value`, with any lines of a multi-line value. */ -}} +{{- $entries := list -}} +{{- range $source := . -}} + {{- $text := "" -}} + {{- if and $source (kindIs "map" $source) -}} + {{- $text = toYaml $source -}} + {{- else if kindIs "string" $source -}} + {{- $text = trim $source -}} + {{- end -}} + {{- if $text -}} + {{- range $line := splitList "\n" $text -}} + {{- if and $entries (or (not $line) (hasPrefix " " $line)) -}} + {{- $entries = append (initial $entries) (printf "%s\n%s" (last $entries) $line) -}} + {{- else -}} + {{- $entries = append $entries $line -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- /* Keep the last entry of each key. */ -}} +{{- $seen := dict -}} +{{- $unique := list -}} +{{- range $entry := reverse $entries -}} + {{- $key := splitList ":" $entry | first | trimAll "\"'" -}} + {{- if not (hasKey $seen $key) -}} + {{- $_ := set $seen $key true -}} + {{- $unique = prepend $unique $entry -}} + {{- end -}} +{{- end -}} +{{- join "\n" $unique -}} +{{- end -}} diff --git a/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml b/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml index c77ec3b33..4f12fdb27 100644 --- a/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml +++ b/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml @@ -4,35 +4,31 @@ metadata: annotations: description: Performs Sourcegraph database migrations. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.migrator.labels }} - {{- toYaml .Values.migrator.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: migrator + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.migrator.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: migrator" + ) | nindent 4 }} name: {{ default "migrator" .Values.migrator.name }}-{{ randAlphaNum 5 | lower }} spec: backoffLimit: 5 template: 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.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: migrator" + .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 }} - job: migrator - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" .) + .Values.sourcegraph.podLabels + .Values.migrator.podLabels + "job: migrator" + "deploy: sourcegraph" + ) | nindent 8 }} spec: containers: - name: migrator diff --git a/charts/sourcegraph-migrator/tests/labels_test.yaml b/charts/sourcegraph-migrator/tests/labels_test.yaml new file mode 100644 index 000000000..f3f994720 --- /dev/null +++ b/charts/sourcegraph-migrator/tests/labels_test.yaml @@ -0,0 +1,45 @@ +# helm-unittest fails a test when any rendered manifest repeats a key, as +# Kustomize does. +suite: unique keys +tests: + - it: should render a key set in several values once + set: + sourcegraph: + labels: &labels + example.com/team: platform + deploy: from-values + helm.sh/chart: from-values + podLabels: &podLabels + example.com/team: platform + deploy: from-values + job: from-values + podAnnotations: &annotations + example.com/owner: platform + kubectl.kubernetes.io/default-container: from-values + migrator: + labels: + <<: *labels + example.com/team: migrator + podLabels: + <<: *podLabels + example.com/team: migrator + podAnnotations: + <<: *annotations + example.com/owner: migrator + template: migrator/sourcegraph-migrator.Job.yaml + asserts: + - equal: + path: metadata.labels["example.com/team"] + value: migrator + - equal: + path: metadata.labels.deploy + value: sourcegraph + - equal: + path: spec.template.metadata.labels["example.com/team"] + value: migrator + - equal: + path: spec.template.metadata.labels.job + value: migrator + - equal: + path: spec.template.metadata.annotations["example.com/owner"] + value: migrator diff --git a/charts/sourcegraph-migrator/values.yaml b/charts/sourcegraph-migrator/values.yaml index fe1ede6a7..59dacad3d 100644 --- a/charts/sourcegraph-migrator/values.yaml +++ b/charts/sourcegraph-migrator/values.yaml @@ -47,12 +47,10 @@ sourcegraph: # # Override the default docker image name # name: # -# # Add additional labels and annotations to various resources +# # Add additional labels and annotations to the Job and its pod # labels: {} # podLabels: {} # podAnnotations: {} -# serviceLabels: {} -# serviceAnnotations: {} # # Override default service/deployment names # name: "" # # Provide custom environment variables diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index 23c93e059..e1443941e 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -480,7 +480,7 @@ In addition to the documented values, all services also support the following va | sourcegraph.image.repository | string | Sourcegraph's public Docker Hub registry | Global docker image registry or prefix | | sourcegraph.image.useGlobalTagAsDefault | bool | `false` | When set to true, sourcegraph.image.defaultTag is used as the default defaultTag for all services, instead of service-specific default defaultTags | | sourcegraph.imagePullSecrets | list | `[]` | Mount named secrets containing docker credentials | -| sourcegraph.labels | object | `{}` | Add extra labels to all resources | +| sourcegraph.labels | object | `{}` | Add extra labels to every resource the chart creates. The chart does not add them to pod templates (use `sourcegraph.podLabels`), to StatefulSet volume claim templates, which Kubernetes does not allow changing (use `.storageLabels`), or to `extraResources` | | sourcegraph.localDevMode | bool | `false` | When true, remove all resource stanzas, allowing the scheduler to best-fit pods. Intended for local development with limited resources. | | sourcegraph.nameOverride | string | `""` | Set a custom name for the app.kubernetes.io/name annotation | | sourcegraph.nodeSelector | object | `{}` | Global NodeSelector, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | @@ -489,7 +489,7 @@ In addition to the documented values, all services also support the following va | sourcegraph.preShutdownPause | string | `"5s"` | Time Sourcegraph services continue accepting requests after shutdown begins so Kubernetes endpoint changes can propagate | | sourcegraph.priorityClassName | string | `""` | Assign a priorityClass to all pods (daemonSets, deployments, and statefulSets) | | sourcegraph.revisionHistoryLimit | int | `10` | Global deployment clean up policy, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#clean-up-policy) | -| sourcegraph.selectorLabelsOverride | object | `{}` | Labels that replace `app.kubernetes.io/name` and `app.kubernetes.io/instance` in every component's workload selector, pod labels, and Service and PodDisruptionBudget selectors. Only for adopting workloads created outside this chart, whose selectors Kubernetes does not allow changing: set it on the first install and never change it afterwards. Use `.extraSelectorLabels` for labels that differ per component. See [Adopting existing workloads](#adopting-existing-workloads) | +| sourcegraph.selectorLabelsOverride | object | `{}` | Labels that replace `app.kubernetes.io/name` and `app.kubernetes.io/instance` in every component's workload selector, pod labels, and Service and PodDisruptionBudget selectors. `jaeger` keeps its own selector labels and ignores this value. Only for adopting workloads created outside this chart, whose selectors Kubernetes does not allow changing: set it on the first install and never change it afterwards. Use `.extraSelectorLabels` for labels that differ per component. See [Adopting existing workloads](#adopting-existing-workloads) | | sourcegraph.serviceLabels | object | `{}` | Add extra labels to all services | | sourcegraph.terminationGracePeriodSeconds | int | `30` | Time Kubernetes allows Sourcegraph services to shut down before forced termination | | sourcegraph.tolerations | list | `[]` | Global Tolerations, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) | diff --git a/charts/sourcegraph/templates/_helpers/_uniqueKeys.tpl b/charts/sourcegraph/templates/_helpers/_uniqueKeys.tpl new file mode 100644 index 000000000..9e8a9ffb1 --- /dev/null +++ b/charts/sourcegraph/templates/_helpers/_uniqueKeys.tpl @@ -0,0 +1,54 @@ +{{/* + +Render label or annotation maps as one map, with each key once. + +Strict YAML parsers, such as Kustomize, reject a map that repeats a key. Helm +and Kubernetes accept it and keep the last value. This keeps the last value +too, so the objects of an installed release do not change. + +Pass a list of maps, lowest precedence first. Each item is a map from the +values, or the text of one or more `key: value` lines. The lines are passed +through as written, so when no key repeats, the output is the same text as +rendering the items one after the other. + +labels: + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.sourcegraph.podLabels + "deploy: sourcegraph" + ) | nindent 2 }} + +*/}} + +{{- define "sourcegraph.uniqueKeys" -}} +{{- /* Split every item into entries: one `key: value`, with any lines of a multi-line value. */ -}} +{{- $entries := list -}} +{{- range $source := . -}} + {{- $text := "" -}} + {{- if and $source (kindIs "map" $source) -}} + {{- $text = toYaml $source -}} + {{- else if kindIs "string" $source -}} + {{- $text = trim $source -}} + {{- end -}} + {{- if $text -}} + {{- range $line := splitList "\n" $text -}} + {{- if and $entries (or (not $line) (hasPrefix " " $line)) -}} + {{- $entries = append (initial $entries) (printf "%s\n%s" (last $entries) $line) -}} + {{- else -}} + {{- $entries = append $entries $line -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- /* Keep the last entry of each key. */ -}} +{{- $seen := dict -}} +{{- $unique := list -}} +{{- range $entry := reverse $entries -}} + {{- $key := splitList ":" $entry | first | trimAll "\"'" -}} + {{- if not (hasKey $seen $key) -}} + {{- $_ := set $seen $key true -}} + {{- $unique = prepend $unique $entry -}} + {{- end -}} +{{- end -}} +{{- join "\n" $unique -}} +{{- end -}} diff --git a/charts/sourcegraph/templates/_worker.tpl b/charts/sourcegraph/templates/_worker.tpl index db47f88aa..468f472e1 100644 --- a/charts/sourcegraph/templates/_worker.tpl +++ b/charts/sourcegraph/templates/_worker.tpl @@ -16,12 +16,12 @@ 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 }} - deploy: sourcegraph - app.kubernetes.io/component: worker + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" $top) + $top.Values.worker.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: worker" + ) | nindent 4 }} name: {{ $name }} spec: minReadySeconds: 10 @@ -42,27 +42,25 @@ spec: template: metadata: 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.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: worker" + (include "sourcegraph.redisChecksum" $top) + $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 }} - deploy: sourcegraph - app: worker + {{- $replicaLabel := "" }} {{- if $suffix }} - worker-replica: {{ $name | quote }} + {{- $replicaLabel = printf "worker-replica: %s" ($name | quote) }} {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list $top $top.Values.worker)) + $top.Values.sourcegraph.podLabels + $top.Values.worker.podLabels + "deploy: sourcegraph" + "app: worker" + $replicaLabel + ) | nindent 8 }} spec: {{- include "sourcegraph.terminationGracePeriodSeconds" (list $top "worker") | nindent 6 }} {{- with $top.Values.worker.extraInitContainers }} diff --git a/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml b/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml index 20575d846..e943984d4 100644 --- a/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml +++ b/charts/sourcegraph/templates/blobstore/blobstore.Deployment.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: blobstore for storing LSIF uploads. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.blobstore.labels }} - {{- toYaml .Values.blobstore.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: blobstore + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.blobstore.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: blobstore" + ) | nindent 4 }} name: {{ .Values.blobstore.name }} spec: minReadySeconds: 10 @@ -25,23 +25,19 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: blobstore - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.blobstore.podAnnotations }} - {{- toYaml .Values.blobstore.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: blobstore" + .Values.sourcegraph.podAnnotations + .Values.blobstore.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.blobstore) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.blobstore.podLabels }} - {{- toYaml .Values.blobstore.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: blobstore + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.blobstore)) + .Values.sourcegraph.podLabels + .Values.blobstore.podLabels + "deploy: sourcegraph" + "app: blobstore" + ) | nindent 8 }} spec: {{- with .Values.blobstore.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/blobstore/blobstore.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/blobstore/blobstore.PersistentVolumeClaim.yaml index 4b241dc3a..80ed5d24f 100644 --- a/charts/sourcegraph/templates/blobstore/blobstore.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/blobstore/blobstore.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: blobstore + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: blobstore" + ) | nindent 4 }} {{- if .Values.blobstore.storageAnnotations }} annotations: {{- toYaml .Values.blobstore.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml b/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml index c3c180c4d..d529c7634 100644 --- a/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml +++ b/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml @@ -7,12 +7,14 @@ metadata: {{- toYaml .Values.blobstore.serviceAnnotations | nindent 4 }} {{- end }} labels: - app: blobstore - deploy: sourcegraph - app.kubernetes.io/component: blobstore - {{- if .Values.blobstore.serviceLabels }} - {{- toYaml .Values.blobstore.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: blobstore" + "deploy: sourcegraph" + "app.kubernetes.io/component: blobstore" + .Values.blobstore.serviceLabels + ) | nindent 4 }} name: blobstore spec: ports: diff --git a/charts/sourcegraph/templates/blobstore/blobstore.ServiceAccount.yaml b/charts/sourcegraph/templates/blobstore/blobstore.ServiceAccount.yaml index 35ea8e0ef..f8045d66a 100644 --- a/charts/sourcegraph/templates/blobstore/blobstore.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/blobstore/blobstore.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: blobstore + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: blobstore" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "blobstore") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "blobstore") }} {{- end }} diff --git a/charts/sourcegraph/templates/cadvisor/cadvisor.DaemonSet.yaml b/charts/sourcegraph/templates/cadvisor/cadvisor.DaemonSet.yaml index 86d82f837..c614ba0ae 100644 --- a/charts/sourcegraph/templates/cadvisor/cadvisor.DaemonSet.yaml +++ b/charts/sourcegraph/templates/cadvisor/cadvisor.DaemonSet.yaml @@ -6,12 +6,12 @@ metadata: description: DaemonSet to ensure all nodes run a cAdvisor pod. seccomp.security.alpha.kubernetes.io/pod: 'docker/default' labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.cadvisor.labels }} - {{- toYaml .Values.cadvisor.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: cadvisor + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.cadvisor.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: cadvisor" + ) | nindent 4 }} name: {{ .Values.cadvisor.name }} spec: selector: @@ -21,26 +21,22 @@ spec: template: metadata: annotations: - description: Collects and exports container metrics. - kubectl.kubernetes.io/default-container: cadvisor - prometheus.io/port: "48080" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.cadvisor.podAnnotations }} - {{- toYaml .Values.cadvisor.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "description: Collects and exports container metrics." + "kubectl.kubernetes.io/default-container: cadvisor" + `prometheus.io/port: "48080"` + `sourcegraph.prometheus/scrape: "true"` + .Values.sourcegraph.podAnnotations + .Values.cadvisor.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.cadvisor) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.cadvisor.podLabels }} - {{- toYaml .Values.cadvisor.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: cadvisor + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.cadvisor)) + .Values.sourcegraph.podLabels + .Values.cadvisor.podLabels + "deploy: sourcegraph" + "app: cadvisor" + ) | nindent 8 }} spec: {{- include "sourcegraph.renderServiceAccountName" (list . "cadvisor") | trim | nindent 6 }} {{- with .Values.cadvisor.extraInitContainers }} diff --git a/charts/sourcegraph/templates/cadvisor/cadvisor.ServiceAccount.yaml b/charts/sourcegraph/templates/cadvisor/cadvisor.ServiceAccount.yaml index 43e8e2b7b..2601fb053 100644 --- a/charts/sourcegraph/templates/cadvisor/cadvisor.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/cadvisor/cadvisor.ServiceAccount.yaml @@ -3,10 +3,13 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - app: cadvisor - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: cadvisor + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: cadvisor" + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: cadvisor" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "cadvisor") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "cadvisor") }} {{- end }} diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml index 428fdf24e..be9010bd3 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml @@ -8,8 +8,11 @@ metadata: annotations: description: Configuration for Code Insights labels: - app.kubernetes.io/component: codeinsights-db - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app.kubernetes.io/component: codeinsights-db" + "deploy: sourcegraph" + ) | nindent 4 }} name: {{ .Values.codeInsightsDB.name }}-conf data: postgresql.conf: | diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.PersistentVolumeClaim.yaml index 566c8140a..e2a3024f1 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - app.kubernetes.io/component: codeinsights-db - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app.kubernetes.io/component: codeinsights-db" + "deploy: sourcegraph" + ) | nindent 4 }} {{- if .Values.codeInsightsDB.storageAnnotations }} annotations: {{- toYaml .Values.codeInsightsDB.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml index 650c58e82..bf837cd41 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml @@ -4,9 +4,12 @@ kind: Secret metadata: name: {{ .Values.codeInsightsDB.name }}-auth labels: - app: codeinsights-db - deploy: sourcegraph - app.kubernetes.io/component: codeinsights-db + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: codeinsights-db" + "deploy: sourcegraph" + "app.kubernetes.io/component: codeinsights-db" + ) | nindent 4 }} type: Opaque data: database: {{ .Values.codeInsightsDB.auth.database | toString | b64enc | quote }} diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml index 45ff67b0e..450ee7c46 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml @@ -3,18 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "9187" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.codeInsightsDB.serviceAnnotations }} - {{- toYaml .Values.codeInsightsDB.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "9187"` + `sourcegraph.prometheus/scrape: "true"` + .Values.codeInsightsDB.serviceAnnotations + ) | nindent 4 }} labels: - app.kubernetes.io/component: codeinsights-db - app: codeinsights-db - deploy: sourcegraph - {{- if .Values.codeInsightsDB.serviceLabels }} - {{- toYaml .Values.codeInsightsDB.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app.kubernetes.io/component: codeinsights-db" + "app: codeinsights-db" + "deploy: sourcegraph" + .Values.codeInsightsDB.serviceLabels + ) | nindent 4 }} name: codeinsights-db spec: ports: diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ServiceAccount.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ServiceAccount.yaml index faba460ec..3a1af1990 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: codeinsights-db + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: codeinsights-db" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "codeInsightsDB") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "codeInsightsDB") }} {{- end }} diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.StatefulSet.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.StatefulSet.yaml index a38dd53cd..3ac89c100 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.StatefulSet.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.StatefulSet.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Code Insights Postgresql instance. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.codeInsightsDB.labels }} - {{- toYaml .Values.codeInsightsDB.labels | nindent 4 }} - {{- end }} - app.kubernetes.io/component: codeinsights-db - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.codeInsightsDB.labels + "app.kubernetes.io/component: codeinsights-db" + "deploy: sourcegraph" + ) | nindent 4 }} name: {{ .Values.codeInsightsDB.name }} spec: replicas: 1 @@ -23,25 +23,21 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: codeinsights - checksum/codeinsights-db.secret: {{ toJson .Values.codeInsightsDB.auth | sha256sum }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.codeInsightsDB.podAnnotations }} - {{- toYaml .Values.codeInsightsDB.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: codeinsights" + (printf "checksum/codeinsights-db.secret: %s" (toJson .Values.codeInsightsDB.auth | sha256sum)) + .Values.sourcegraph.podAnnotations + .Values.codeInsightsDB.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.codeInsightsDB) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.codeInsightsDB.podLabels }} - {{- toYaml .Values.codeInsightsDB.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: codeinsights-db - group: backend + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.codeInsightsDB)) + .Values.sourcegraph.podLabels + .Values.codeInsightsDB.podLabels + "deploy: sourcegraph" + "app: codeinsights-db" + "group: backend" + ) | nindent 8 }} spec: initContainers: {{- with .Values.codeInsightsDB.extraInitContainers }} diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml index d70ffd650..3868bbe1f 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml @@ -8,8 +8,11 @@ metadata: annotations: description: Configuration for PostgreSQL labels: - app.kubernetes.io/component: codeintel-db - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app.kubernetes.io/component: codeintel-db" + "deploy: sourcegraph" + ) | nindent 4 }} name: {{ .Values.codeIntelDB.name }}-conf data: postgresql.conf: | diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.PersistentVolumeClaim.yaml index fe496da4f..3c8750733 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - app.kubernetes.io/component: codeintel-db - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app.kubernetes.io/component: codeintel-db" + "deploy: sourcegraph" + ) | nindent 4 }} {{- if .Values.codeIntelDB.storageAnnotations }} annotations: {{- toYaml .Values.codeIntelDB.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml index 021a54f0a..6029a30a8 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml @@ -4,9 +4,12 @@ kind: Secret metadata: name: {{ .Values.codeIntelDB.name }}-auth labels: - app: codeintel-db - deploy: sourcegraph - app.kubernetes.io/component: codeintel-db + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: codeintel-db" + "deploy: sourcegraph" + "app.kubernetes.io/component: codeintel-db" + ) | nindent 4 }} type: Opaque data: database: {{ .Values.codeIntelDB.auth.database | toString | b64enc | quote }} diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml index a283d4712..274cede5b 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml @@ -3,18 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "9187" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.codeIntelDB.serviceAnnotations }} - {{- toYaml .Values.codeIntelDB.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "9187"` + `sourcegraph.prometheus/scrape: "true"` + .Values.codeIntelDB.serviceAnnotations + ) | nindent 4 }} labels: - app.kubernetes.io/component: codeintel-db - app: codeintel-db - deploy: sourcegraph - {{- if .Values.codeIntelDB.serviceLabels }} - {{- toYaml .Values.codeIntelDB.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app.kubernetes.io/component: codeintel-db" + "app: codeintel-db" + "deploy: sourcegraph" + .Values.codeIntelDB.serviceLabels + ) | nindent 4 }} name: codeintel-db spec: ports: diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ServiceAccount.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ServiceAccount.yaml index d19e5abee..42c20bac9 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: codeintel-db + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: codeintel-db" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "codeIntelDB") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "codeIntelDB") }} {{- end }} diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.StatefulSet.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.StatefulSet.yaml index 60141fb1f..0cf69c5a2 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.StatefulSet.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.StatefulSet.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Postgres database for various data. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.codeIntelDB.labels }} - {{- toYaml .Values.codeIntelDB.labels | nindent 4 }} - {{- end }} - app.kubernetes.io/component: codeintel-db - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.codeIntelDB.labels + "app.kubernetes.io/component: codeintel-db" + "deploy: sourcegraph" + ) | nindent 4 }} name: {{ .Values.codeIntelDB.name }} spec: replicas: 1 @@ -23,25 +23,21 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: pgsql - checksum/codeintel-db.secret: {{ toJson .Values.codeIntelDB.auth | sha256sum }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.codeIntelDB.podAnnotations }} - {{- toYaml .Values.codeIntelDB.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: pgsql" + (printf "checksum/codeintel-db.secret: %s" (toJson .Values.codeIntelDB.auth | sha256sum)) + .Values.sourcegraph.podAnnotations + .Values.codeIntelDB.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.codeIntelDB) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.codeIntelDB.podLabels }} - {{- toYaml .Values.codeIntelDB.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: codeintel-db - group: backend + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.codeIntelDB)) + .Values.sourcegraph.podLabels + .Values.codeIntelDB.podLabels + "deploy: sourcegraph" + "app: codeintel-db" + "group: backend" + ) | nindent 8 }} spec: initContainers: {{- with .Values.codeIntelDB.extraInitContainers }} diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml index 1cf3290a5..716af1bb3 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml @@ -6,12 +6,14 @@ metadata: {{- toYaml .Values.frontend.serviceAnnotations | nindent 4 }} {{- end }} labels: - app: sourcegraph-frontend - deploy: sourcegraph - app.kubernetes.io/component: frontend - {{- if .Values.frontend.serviceLabels }} - {{- toYaml .Values.frontend.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: sourcegraph-frontend" + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + .Values.frontend.serviceLabels + ) | nindent 4 }} name: sourcegraph-frontend-internal spec: ports: diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Deployment.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Deployment.yaml index ecfcd1038..5acec8482 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Deployment.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Deployment.yaml @@ -4,12 +4,12 @@ metadata: annotations: description: Serves the frontend of Sourcegraph via HTTP(S). labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.frontend.labels }} - {{- toYaml .Values.frontend.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: frontend + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.frontend.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + ) | nindent 4 }} name: {{ .Values.frontend.name }} spec: minReadySeconds: 10 @@ -27,25 +27,21 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: frontend - {{- include "sourcegraph.authChecksum" . | nindent 8 }} - {{- include "sourcegraph.redisChecksum" . | nindent 8 }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.frontend.podAnnotations }} - {{- toYaml .Values.frontend.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: frontend" + (include "sourcegraph.authChecksum" .) + (include "sourcegraph.redisChecksum" .) + .Values.sourcegraph.podAnnotations + .Values.frontend.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.frontend) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.frontend.podLabels }} - {{- toYaml .Values.frontend.podLabels | nindent 8 }} - {{- end }} - app: sourcegraph-frontend - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.frontend)) + .Values.sourcegraph.podLabels + .Values.frontend.podLabels + "app: sourcegraph-frontend" + "deploy: sourcegraph" + ) | nindent 8 }} spec: {{- include "sourcegraph.terminationGracePeriodSeconds" (list . "frontend") | nindent 6 }} initContainers: diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml index 10a9c357e..f8a4e56eb 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml @@ -13,12 +13,13 @@ metadata: {{- toYaml .Values.frontend.ingress.annotations | nindent 4 }} {{- end }} labels: - app: sourcegraph-frontend - deploy: sourcegraph - app.kubernetes.io/component: frontend - {{- if .Values.frontend.ingress.labels}} - {{- toYaml .Values.frontend.ingress.labels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: sourcegraph-frontend" + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + .Values.frontend.ingress.labels + ) | nindent 4 }} name: {{ .Values.frontend.name }} spec: {{- if .Values.frontend.ingress.tls }} diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml index 140088ea8..22cd3b535 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: sourcegraph-frontend + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.frontend.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Role.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Role.yaml index aa3a20898..14ef74522 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Role.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Role.yaml @@ -3,10 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: frontend + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + ) | nindent 4 }} name: {{ .Values.frontend.name }} rules: - apiGroups: diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.RoleBinding.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.RoleBinding.yaml index 4bdbc1c25..1e8a25116 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.RoleBinding.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.RoleBinding.yaml @@ -3,10 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: frontend + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + ) | nindent 4 }} name: {{ .Values.frontend.name }} roleRef: {{- if .Values.frontend.privileged }} diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml index d03e1c555..faecf134e 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml @@ -2,18 +2,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.frontend.serviceAnnotations }} - {{- toYaml .Values.frontend.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.frontend.serviceAnnotations + ) | nindent 4 }} labels: - app: sourcegraph-frontend - deploy: sourcegraph - app.kubernetes.io/component: frontend - {{- if .Values.frontend.serviceLabels }} - {{- toYaml .Values.frontend.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: sourcegraph-frontend" + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + .Values.frontend.serviceLabels + ) | nindent 4 }} name: sourcegraph-frontend spec: ports: diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.ServiceAccount.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.ServiceAccount.yaml index 8dfbc2c6f..5d432788a 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.ServiceAccount.yaml @@ -7,9 +7,12 @@ imagePullSecrets: {{- end }} metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: frontend + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: frontend" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "frontend") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "frontend") }} {{- end }} diff --git a/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml index 2a62dcd29..65a5b92de 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.gitserver.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.gitserver.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml b/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml index 9f8a4ca1c..0ba2766e8 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml @@ -2,21 +2,22 @@ apiVersion: v1 kind: Service metadata: annotations: - description: Headless service that provides a stable network identity for the - gitserver stateful set. - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.gitserver.serviceAnnotations }} - {{- toYaml .Values.gitserver.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "description: Headless service that provides a stable network identity for the\n gitserver stateful set." + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.gitserver.serviceAnnotations + ) | nindent 4 }} labels: - deploy: sourcegraph - app.kubernetes.io/component: gitserver - type: gitserver - app: gitserver - {{- if .Values.gitserver.serviceLabels }} - {{- toYaml .Values.gitserver.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "deploy: sourcegraph" + "app.kubernetes.io/component: gitserver" + "type: gitserver" + "app: gitserver" + .Values.gitserver.serviceLabels + ) | nindent 4 }} name: gitserver spec: clusterIP: None diff --git a/charts/sourcegraph/templates/gitserver/gitserver.ServiceAccount.yaml b/charts/sourcegraph/templates/gitserver/gitserver.ServiceAccount.yaml index cbc894987..7ec0a3b46 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: gitserver + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: gitserver" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "gitserver") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "gitserver") }} {{- end }} diff --git a/charts/sourcegraph/templates/gitserver/gitserver.StatefulSet.yaml b/charts/sourcegraph/templates/gitserver/gitserver.StatefulSet.yaml index cec311f55..c5aaee00c 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.StatefulSet.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.StatefulSet.yaml @@ -4,12 +4,12 @@ metadata: annotations: description: Stores clones of repositories to perform Git operations. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.gitserver.labels }} - {{- toYaml .Values.gitserver.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: gitserver + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.gitserver.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: gitserver" + ) | nindent 4 }} name: {{ .Values.gitserver.name }} spec: replicas: {{ .Values.gitserver.replicaCount }} @@ -22,26 +22,22 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: gitserver - {{- include "sourcegraph.redisChecksum" . | nindent 8 }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.gitserver.podAnnotations }} - {{- toYaml .Values.gitserver.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: gitserver" + (include "sourcegraph.redisChecksum" .) + .Values.sourcegraph.podAnnotations + .Values.gitserver.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.gitserver) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.gitserver.podLabels }} - {{- toYaml .Values.gitserver.podLabels | nindent 8 }} - {{- end }} - app: gitserver - group: backend - type: gitserver - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.gitserver)) + .Values.sourcegraph.podLabels + .Values.gitserver.podLabels + "app: gitserver" + "group: backend" + "type: gitserver" + "deploy: sourcegraph" + ) | nindent 8 }} spec: {{- include "sourcegraph.terminationGracePeriodSeconds" (list . "gitserver") | nindent 6 }} {{- with .Values.gitserver.extraInitContainers }} diff --git a/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml b/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml index bcca1df13..401957f98 100644 --- a/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml @@ -28,7 +28,10 @@ data: kind: ConfigMap metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: grafana + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: grafana" + ) | nindent 4 }} name: {{ .Values.grafana.name }} {{- end }} diff --git a/charts/sourcegraph/templates/grafana/grafana.Service.yaml b/charts/sourcegraph/templates/grafana/grafana.Service.yaml index 0768f7ff6..4fda4e778 100644 --- a/charts/sourcegraph/templates/grafana/grafana.Service.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.Service.yaml @@ -7,12 +7,14 @@ metadata: {{- toYaml .Values.grafana.serviceAnnotations | nindent 4 }} {{- end }} labels: - app: grafana - deploy: sourcegraph - app.kubernetes.io/component: grafana - {{- if .Values.grafana.serviceLabels }} - {{- toYaml .Values.grafana.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: grafana" + "deploy: sourcegraph" + "app.kubernetes.io/component: grafana" + .Values.grafana.serviceLabels + ) | nindent 4 }} name: grafana spec: ports: diff --git a/charts/sourcegraph/templates/grafana/grafana.ServiceAccount.yaml b/charts/sourcegraph/templates/grafana/grafana.ServiceAccount.yaml index f5fccab8b..971b158fd 100644 --- a/charts/sourcegraph/templates/grafana/grafana.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.ServiceAccount.yaml @@ -7,9 +7,12 @@ imagePullSecrets: {{- end }} metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: grafana + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: grafana" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "grafana") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "grafana") }} {{- end }} diff --git a/charts/sourcegraph/templates/grafana/grafana.StatefulSet.yaml b/charts/sourcegraph/templates/grafana/grafana.StatefulSet.yaml index 968ce16bb..d47ac7f89 100644 --- a/charts/sourcegraph/templates/grafana/grafana.StatefulSet.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.StatefulSet.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Metrics/monitoring dashboards and alerts. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.grafana.labels }} - {{- toYaml .Values.grafana.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: grafana + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.grafana.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: grafana" + ) | nindent 4 }} name: {{ .Values.grafana.name }} spec: revisionHistoryLimit: {{ .Values.sourcegraph.revisionHistoryLimit }} @@ -27,23 +27,19 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: grafana - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.grafana.podAnnotations }} - {{- toYaml .Values.grafana.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: grafana" + .Values.sourcegraph.podAnnotations + .Values.grafana.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.grafana) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.grafana.podLabels }} - {{- toYaml .Values.grafana.podLabels | nindent 8 }} - {{- end }} - app: grafana - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.grafana)) + .Values.sourcegraph.podLabels + .Values.grafana.podLabels + "app: grafana" + "deploy: sourcegraph" + ) | nindent 8 }} spec: {{- with .Values.grafana.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml b/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml index ddefc5921..967aa0c03 100644 --- a/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: Secret metadata: labels: - app: grafana - deploy: sourcegraph - app.kubernetes.io/component: grafana + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: grafana" + "deploy: sourcegraph" + "app.kubernetes.io/component: grafana" + ) | nindent 4 }} name: {{ .Values.grafana.name }}-auth type: Opaque data: diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml index edfed32b8..5cc774ba2 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml @@ -2,20 +2,21 @@ apiVersion: v1 kind: Service metadata: annotations: - description: Headless service that provides a stable network identity for the - indexed-search stateful set. - prometheus.io/port: "6072" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.indexedSearch.serviceAnnotations }} - {{- toYaml .Values.indexedSearch.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "description: Headless service that provides a stable network identity for the\n indexed-search stateful set." + `prometheus.io/port: "6072"` + `sourcegraph.prometheus/scrape: "true"` + .Values.indexedSearch.serviceAnnotations + ) | nindent 4 }} labels: - app: indexed-search-indexer - deploy: sourcegraph - app.kubernetes.io/component: indexed-search - {{- if .Values.indexedSearch.serviceLabels }} - {{- toYaml .Values.indexedSearch.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: indexed-search-indexer" + "deploy: sourcegraph" + "app.kubernetes.io/component: indexed-search" + .Values.indexedSearch.serviceLabels + ) | nindent 4 }} name: {{ default "indexed-search-indexer" .Values.indexedSearch.indexerName }} spec: clusterIP: None diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml index 7ec274581..78680fa6f 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.indexedSearch.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.indexedSearch.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml index 5edffe2a9..db4a4388a 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml @@ -2,20 +2,21 @@ apiVersion: v1 kind: Service metadata: annotations: - description: Headless service that provides a stable network identity for the - indexed-search stateful set. - prometheus.io/port: "6070" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.indexedSearch.serviceAnnotations }} - {{- toYaml .Values.indexedSearch.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "description: Headless service that provides a stable network identity for the\n indexed-search stateful set." + `prometheus.io/port: "6070"` + `sourcegraph.prometheus/scrape: "true"` + .Values.indexedSearch.serviceAnnotations + ) | nindent 4 }} labels: - app: indexed-search - deploy: sourcegraph - app.kubernetes.io/component: indexed-search - {{- if .Values.indexedSearch.serviceLabels }} - {{- toYaml .Values.indexedSearch.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: indexed-search" + "deploy: sourcegraph" + "app.kubernetes.io/component: indexed-search" + .Values.indexedSearch.serviceLabels + ) | nindent 4 }} name: indexed-search spec: clusterIP: None diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.ServiceAccount.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.ServiceAccount.yaml index 01bc6a1b7..2a456bd36 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: indexed-search + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: indexed-search" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "indexedSearch") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "indexedSearch") }} {{- end }} diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml index 1c7742885..fc948fd11 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml @@ -4,12 +4,12 @@ metadata: annotations: description: Backend for indexed text search operations. labels: - deploy: sourcegraph - app.kubernetes.io/component: indexed-search - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.indexedSearch.labels }} - {{- toYaml .Values.indexedSearch.labels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "deploy: sourcegraph" + "app.kubernetes.io/component: indexed-search" + (include "sourcegraph.labels" .) + .Values.indexedSearch.labels + ) | nindent 4 }} name: {{ .Values.indexedSearch.name }} spec: replicas: {{ .Values.indexedSearch.replicaCount }} @@ -23,23 +23,19 @@ spec: metadata: {{- if or .Values.sourcegraph.podAnnotations .Values.indexedSearch.podAnnotations }} annotations: - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.indexedSearch.podAnnotations }} - {{- toYaml .Values.indexedSearch.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.podAnnotations + .Values.indexedSearch.podAnnotations + ) | nindent 8 }} {{- end }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.indexedSearch) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.indexedSearch.podLabels }} - {{- toYaml .Values.indexedSearch.podLabels | nindent 8 }} - {{- end }} - app: indexed-search - deploy: sourcegraph + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.indexedSearch)) + .Values.sourcegraph.podLabels + .Values.indexedSearch.podLabels + "app: indexed-search" + "deploy: sourcegraph" + ) | nindent 8 }} spec: {{- with .Values.indexedSearch.extraInitContainers }} initContainers: @@ -155,10 +151,10 @@ spec: volumeClaimTemplates: - metadata: labels: - deploy: sourcegraph - {{- with .Values.indexedSearch.storageLabels }} - {{- toYaml . | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "deploy: sourcegraph" + .Values.indexedSearch.storageLabels + ) | nindent 8 }} name: data {{- if .Values.indexedSearch.storageAnnotations }} annotations: diff --git a/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml b/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml index 3665df98e..b2e5d4527 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml @@ -7,13 +7,15 @@ metadata: {{- toYaml .Values.jaeger.collector.serviceAnnotations | nindent 4 }} {{- end }} labels: - deploy: sourcegraph - app.kubernetes.io/component: all-in-one - app: jaeger - app.kubernetes.io/name: jaeger - {{- if .Values.jaeger.collector.serviceLabels }} - {{- toYaml .Values.jaeger.collector.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "deploy: sourcegraph" + "app.kubernetes.io/component: all-in-one" + "app: jaeger" + "app.kubernetes.io/name: jaeger" + .Values.jaeger.collector.serviceLabels + ) | nindent 4 }} name: {{ default "jaeger-collector" .Values.jaeger.collector.name }} spec: ports: diff --git a/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml b/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml index cfc9464b2..ef00eb082 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml @@ -7,13 +7,15 @@ metadata: {{- toYaml .Values.jaeger.query.serviceAnnotations | nindent 4 }} {{- end }} labels: - deploy: sourcegraph - app.kubernetes.io/component: all-in-one - app: jaeger - app.kubernetes.io/name: jaeger - {{- if .Values.jaeger.query.serviceLabels }} - {{- toYaml .Values.jaeger.query.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "deploy: sourcegraph" + "app.kubernetes.io/component: all-in-one" + "app: jaeger" + "app.kubernetes.io/name: jaeger" + .Values.jaeger.query.serviceLabels + ) | nindent 4 }} name: {{ default "jaeger-query" .Values.jaeger.query.name }} spec: ports: diff --git a/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml b/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml index 7e2a388cf..bbce825e2 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml @@ -3,10 +3,12 @@ apiVersion: v1 kind: ConfigMap metadata: labels: - {{- include "sourcegraph.jaeger.labels" . | nindent 4 }} - deploy: sourcegraph - app.kubernetes.io/component: all-in-one - app: jaeger + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.jaeger.labels" .) + "deploy: sourcegraph" + "app.kubernetes.io/component: all-in-one" + "app: jaeger" + ) | nindent 4 }} name: {{ .Values.jaeger.name }} data: jaeger-config.yaml: | diff --git a/charts/sourcegraph/templates/jaeger/jaeger.Deployment.yaml b/charts/sourcegraph/templates/jaeger/jaeger.Deployment.yaml index 856233e29..2a6e69d8d 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger.Deployment.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger.Deployment.yaml @@ -6,13 +6,13 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - {{- include "sourcegraph.jaeger.labels" . | nindent 4 }} - {{- if .Values.jaeger.labels }} - {{- toYaml .Values.jaeger.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: all-in-one - app: jaeger + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.jaeger.labels" .) + .Values.jaeger.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: all-in-one" + "app: jaeger" + ) | nindent 4 }} name: {{ .Values.jaeger.name }} spec: replicas: {{ .Values.jaeger.replicaCount }} @@ -27,30 +27,28 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: jaeger - prometheus.io/port: "16686" - sourcegraph.prometheus/scrape: "true" + {{- $configChecksum := "" }} {{- if not .Values.jaeger.config.existingConfigMap }} - checksum/jaeger-config: {{ include (print $.Template.BasePath "/jaeger/jaeger.ConfigMap.yaml") . | sha256sum }} + {{- $configChecksum = printf "checksum/jaeger-config: %s" (include (print $.Template.BasePath "/jaeger/jaeger.ConfigMap.yaml") . | sha256sum) }} {{- end }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.jaeger.podAnnotations }} - {{- toYaml .Values.jaeger.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: jaeger" + `prometheus.io/port: "16686"` + `sourcegraph.prometheus/scrape: "true"` + $configChecksum + .Values.sourcegraph.podAnnotations + .Values.jaeger.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.jaeger.selectorLabels" . | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.jaeger.podLabels }} - {{- toYaml .Values.jaeger.podLabels | nindent 8 }} - {{- end }} - app.kubernetes.io/instance: {{ .Release.Name }} - app: jaeger - deploy: sourcegraph - app.kubernetes.io/component: all-in-one + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.jaeger.selectorLabels" .) + .Values.sourcegraph.podLabels + .Values.jaeger.podLabels + (printf "app.kubernetes.io/instance: %s" .Release.Name) + "app: jaeger" + "deploy: sourcegraph" + "app.kubernetes.io/component: all-in-one" + ) | nindent 8 }} spec: {{- with .Values.jaeger.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/jaeger/jaeger.ServiceAccount.yaml b/charts/sourcegraph/templates/jaeger/jaeger.ServiceAccount.yaml index 1832c6b4c..cf41891d1 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: tracing + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: tracing" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "tracing") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "tracing") }} {{- end }} diff --git a/charts/sourcegraph/templates/node-exporter/node-exporter.DaemonSet.yaml b/charts/sourcegraph/templates/node-exporter/node-exporter.DaemonSet.yaml index df74ab081..663d0dbc1 100644 --- a/charts/sourcegraph/templates/node-exporter/node-exporter.DaemonSet.yaml +++ b/charts/sourcegraph/templates/node-exporter/node-exporter.DaemonSet.yaml @@ -6,13 +6,13 @@ metadata: description: DaemonSet to ensure all nodes run a node-exporter pod. seccomp.security.alpha.kubernetes.io/pod: 'docker/default' labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.nodeExporter.labels }} - {{- toYaml .Values.nodeExporter.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app: node-exporter - app.kubernetes.io/component: node-exporter + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.nodeExporter.labels + "deploy: sourcegraph" + "app: node-exporter" + "app.kubernetes.io/component: node-exporter" + ) | nindent 4 }} name: {{ .Values.nodeExporter.name }} spec: selector: @@ -22,24 +22,20 @@ spec: template: metadata: annotations: - description: Collects and exports machine metrics. - kubectl.kubernetes.io/default-container: node-exporter - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.nodeExporter.podAnnotations }} - {{- toYaml .Values.nodeExporter.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "description: Collects and exports machine metrics." + "kubectl.kubernetes.io/default-container: node-exporter" + .Values.sourcegraph.podAnnotations + .Values.nodeExporter.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.nodeExporter) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.nodeExporter.podLabels }} - {{- toYaml .Values.nodeExporter.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: node-exporter + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.nodeExporter)) + .Values.sourcegraph.podLabels + .Values.nodeExporter.podLabels + "deploy: sourcegraph" + "app: node-exporter" + ) | nindent 8 }} spec: {{- if .Values.nodeExporter.serviceAccount.create }} {{- include "sourcegraph.renderServiceAccountName" (list . "nodeExporter") | trim | nindent 6 }} diff --git a/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml b/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml index b2dd5dabe..1e748eecd 100644 --- a/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml +++ b/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml @@ -3,21 +3,23 @@ apiVersion: v1 kind: Service metadata: annotations: - description: Prometheus exporter for hardware and OS metrics. - prometheus.io/port: "9100" - sourcegraph.prometheus/scrape: "true" - url: https://github.com/prometheus/node_exporter - {{- if .Values.nodeExporter.serviceAnnotations }} - {{- toYaml .Values.nodeExporter.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "description: Prometheus exporter for hardware and OS metrics." + `prometheus.io/port: "9100"` + `sourcegraph.prometheus/scrape: "true"` + "url: https://github.com/prometheus/node_exporter" + .Values.nodeExporter.serviceAnnotations + ) | nindent 4 }} labels: - app.kubernetes.io/component: node-exporter - app: node-exporter - deploy: sourcegraph - sourcegraph-resource-requires: no-cluster-admin - {{- if .Values.nodeExporter.serviceLabels }} - {{- toYaml .Values.nodeExporter.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app.kubernetes.io/component: node-exporter" + "app: node-exporter" + "deploy: sourcegraph" + "sourcegraph-resource-requires: no-cluster-admin" + .Values.nodeExporter.serviceLabels + ) | nindent 4 }} name: node-exporter spec: ports: diff --git a/charts/sourcegraph/templates/node-exporter/node-exporter.ServiceAccount.yaml b/charts/sourcegraph/templates/node-exporter/node-exporter.ServiceAccount.yaml index 0d0cf7b53..32f4c205a 100644 --- a/charts/sourcegraph/templates/node-exporter/node-exporter.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/node-exporter/node-exporter.ServiceAccount.yaml @@ -3,10 +3,13 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - app: node-exporter - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: node-exporter + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: node-exporter" + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: node-exporter" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "nodeExporter") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "nodeExporter") }} {{- end }} diff --git a/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml index e4b103289..340ed1b7d 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml @@ -5,8 +5,11 @@ kind: ConfigMap metadata: name: {{ .Values.openTelemetry.agent.name }} labels: - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} data: config.yaml: | receivers: diff --git a/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml b/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml index 6a2f9446c..83cdd34ea 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Forwards telemetry data to the OpenTelemetry Collector Deployment. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.openTelemetry.agent.labels }} - {{- toYaml .Values.openTelemetry.agent.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.openTelemetry.agent.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} name: {{ .Values.openTelemetry.agent.name }} spec: selector: @@ -21,23 +21,19 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: otel-agent - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.openTelemetry.agent.podAnnotations }} - {{- toYaml .Values.openTelemetry.agent.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: otel-agent" + .Values.sourcegraph.podAnnotations + .Values.openTelemetry.agent.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.openTelemetry.agent) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.openTelemetry.agent.podLabels }} - {{- toYaml .Values.openTelemetry.agent.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: otel-agent + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.openTelemetry.agent)) + .Values.sourcegraph.podLabels + .Values.openTelemetry.agent.podLabels + "deploy: sourcegraph" + "app: otel-agent" + ) | nindent 8 }} spec: {{- with .Values.openTelemetry.agent.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/otel-collector/otel-agent.ServiceAccount.yaml b/charts/sourcegraph/templates/otel-collector/otel-agent.ServiceAccount.yaml index 00dde11c6..354a1d92c 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-agent.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-agent.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list .Values.openTelemetry "agent") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list .Values.openTelemetry "agent") }} {{- end }} diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml index b236ee0bb..206aac8e3 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml @@ -7,8 +7,11 @@ kind: ConfigMap metadata: name: {{ .Values.openTelemetry.gateway.name }} labels: - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} data: config.yaml: | receivers: diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml index c25b8e5cf..d65a53fff 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Receives, processes, and exports telemetry data. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.openTelemetry.gateway.labels }} - {{- toYaml .Values.openTelemetry.gateway.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.openTelemetry.gateway.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} name: {{ .Values.openTelemetry.gateway.name }} spec: selector: @@ -23,23 +23,19 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: otel-collector - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.openTelemetry.gateway.podAnnotations }} - {{- toYaml .Values.openTelemetry.gateway.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: otel-collector" + .Values.sourcegraph.podAnnotations + .Values.openTelemetry.gateway.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.openTelemetry.gateway) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.openTelemetry.gateway.podLabels }} - {{- toYaml .Values.openTelemetry.gateway.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.openTelemetry.gateway)) + .Values.sourcegraph.podLabels + .Values.openTelemetry.gateway.podLabels + "deploy: sourcegraph" + "app: otel-collector" + ) | nindent 8 }} spec: {{- with .Values.openTelemetry.gateway.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml index 9b5e03bc8..9159ffcf2 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml @@ -3,18 +3,19 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "8888" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.openTelemetry.gateway.serviceAnnotations }} - {{- toYaml .Values.openTelemetry.gateway.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "8888"` + `sourcegraph.prometheus/scrape: "true"` + .Values.openTelemetry.gateway.serviceAnnotations + ) | nindent 4 }} labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.openTelemetry.gateway.serviceLabels }} - {{- toYaml .Values.openTelemetry.gateway.serviceLabels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.sourcegraph.serviceLabels + .Values.openTelemetry.gateway.serviceLabels + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} name: otel-collector spec: ports: diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.ServiceAccount.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.ServiceAccount.yaml index d8aeb7b2a..b4aa42113 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: otel-collector + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: otel-collector" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list .Values.openTelemetry "gateway") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list .Values.openTelemetry "gateway") }} {{- end }} diff --git a/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml b/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml index 580849390..95d91f550 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml @@ -8,8 +8,11 @@ metadata: annotations: description: Configuration for PostgreSQL labels: - deploy: sourcegraph - app.kubernetes.io/component: pgsql + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: pgsql" + ) | nindent 4 }} name: {{ .Values.pgsql.name }}-conf data: postgresql.conf: | diff --git a/charts/sourcegraph/templates/pgsql/pgsql.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/pgsql/pgsql.PersistentVolumeClaim.yaml index 9e4db93aa..84f212887 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: pgsql + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: pgsql" + ) | nindent 4 }} {{- if .Values.pgsql.storageAnnotations }} annotations: {{- toYaml .Values.pgsql.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml b/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml index 63ec30eb5..6371f00c1 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: Secret metadata: labels: - app: pgsql - deploy: sourcegraph - app.kubernetes.io/component: pgsql + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: pgsql" + "deploy: sourcegraph" + "app.kubernetes.io/component: pgsql" + ) | nindent 4 }} name: {{ .Values.pgsql.name }}-auth type: Opaque data: diff --git a/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml b/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml index eed8b3074..eb279a178 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml @@ -3,18 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "9187" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.pgsql.serviceAnnotations }} - {{- toYaml .Values.pgsql.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "9187"` + `sourcegraph.prometheus/scrape: "true"` + .Values.pgsql.serviceAnnotations + ) | nindent 4 }} labels: - app: pgsql - deploy: sourcegraph - app.kubernetes.io/component: pgsql - {{- if .Values.pgsql.serviceLabels }} - {{- toYaml .Values.pgsql.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: pgsql" + "deploy: sourcegraph" + "app.kubernetes.io/component: pgsql" + .Values.pgsql.serviceLabels + ) | nindent 4 }} name: pgsql spec: ports: diff --git a/charts/sourcegraph/templates/pgsql/pgsql.ServiceAccount.yaml b/charts/sourcegraph/templates/pgsql/pgsql.ServiceAccount.yaml index 8255446b8..50d411043 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: pgsql + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: pgsql" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "pgsql") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "pgsql") }} {{- end }} diff --git a/charts/sourcegraph/templates/pgsql/pgsql.StatefulSet.yaml b/charts/sourcegraph/templates/pgsql/pgsql.StatefulSet.yaml index 594ed6a99..ee0f93f53 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.StatefulSet.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.StatefulSet.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Postgres database for various data. labels: - deploy: sourcegraph - app.kubernetes.io/component: pgsql - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.pgsql.labels }} - {{- toYaml .Values.pgsql.labels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "deploy: sourcegraph" + "app.kubernetes.io/component: pgsql" + (include "sourcegraph.labels" .) + .Values.pgsql.labels + ) | nindent 4 }} name: {{ .Values.pgsql.name }} spec: replicas: 1 @@ -23,25 +23,21 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: pgsql - checksum/pgsql.secret: {{ toJson .Values.pgsql.auth | sha256sum }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.pgsql.podAnnotations }} - {{- toYaml .Values.pgsql.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: pgsql" + (printf "checksum/pgsql.secret: %s" (toJson .Values.pgsql.auth | sha256sum)) + .Values.sourcegraph.podAnnotations + .Values.pgsql.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.pgsql) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.pgsql.podLabels }} - {{- toYaml .Values.pgsql.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: pgsql - group: backend + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.pgsql)) + .Values.sourcegraph.podLabels + .Values.pgsql.podLabels + "deploy: sourcegraph" + "app: pgsql" + "group: backend" + ) | nindent 8 }} spec: initContainers: {{- with .Values.pgsql.extraInitContainers }} diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.Deployment.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.Deployment.yaml index eaedb63a0..8f5c10708 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.Deployment.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.Deployment.yaml @@ -4,12 +4,12 @@ metadata: annotations: description: Handles conversion of uploaded precise code intelligence bundles. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.preciseCodeIntel.labels }} - {{- toYaml .Values.preciseCodeIntel.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: precise-code-intel + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.preciseCodeIntel.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: precise-code-intel" + ) | nindent 4 }} name: {{ .Values.preciseCodeIntel.name }} spec: minReadySeconds: 10 @@ -27,24 +27,20 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: precise-code-intel-worker - {{- include "sourcegraph.redisChecksum" . | nindent 8 }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.preciseCodeIntel.podAnnotations }} - {{- toYaml .Values.preciseCodeIntel.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: precise-code-intel-worker" + (include "sourcegraph.redisChecksum" .) + .Values.sourcegraph.podAnnotations + .Values.preciseCodeIntel.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.preciseCodeIntel) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.preciseCodeIntel.podLabels }} - {{- toYaml .Values.preciseCodeIntel.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: precise-code-intel-worker + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.preciseCodeIntel)) + .Values.sourcegraph.podLabels + .Values.preciseCodeIntel.podLabels + "deploy: sourcegraph" + "app: precise-code-intel-worker" + ) | nindent 8 }} spec: {{- $storageType := .Values.preciseCodeIntel.storageType | default "emptyDir" }} {{- if not (has $storageType (list "emptyDir" "pvc")) }} diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml index 535f7f187..6804e5f51 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.preciseCodeIntel.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.preciseCodeIntel.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml index 59f9ed7aa..2fbd64854 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml @@ -2,18 +2,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.preciseCodeIntel.serviceAnnotations }} - {{- toYaml .Values.preciseCodeIntel.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.preciseCodeIntel.serviceAnnotations + ) | nindent 4 }} labels: - app: precise-code-intel-worker - deploy: sourcegraph - app.kubernetes.io/component: precise-code-intel - {{- if .Values.preciseCodeIntel.serviceLabels }} - {{- toYaml .Values.preciseCodeIntel.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: precise-code-intel-worker" + "deploy: sourcegraph" + "app.kubernetes.io/component: precise-code-intel" + .Values.preciseCodeIntel.serviceLabels + ) | nindent 4 }} name: precise-code-intel-worker spec: ports: diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.ServiceAccount.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.ServiceAccount.yaml index 60448ca2b..513dbcae2 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: precise-code-intel + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: precise-code-intel" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "preciseCodeIntel") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "preciseCodeIntel") }} {{- end }} diff --git a/charts/sourcegraph/templates/priorityClass.yaml b/charts/sourcegraph/templates/priorityClass.yaml index 50d5e3829..f0b656f37 100644 --- a/charts/sourcegraph/templates/priorityClass.yaml +++ b/charts/sourcegraph/templates/priorityClass.yaml @@ -3,6 +3,10 @@ apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: {{ $class.name }} + {{- with $.Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} value: {{ $class.value }} preemptionPolicy: {{ $class.preemptionPolicy }} globalDefault: false diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ClusterRole.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ClusterRole.yaml index 383623b40..b22ac96a1 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ClusterRole.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ClusterRole.yaml @@ -3,9 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} name: {{ .Values.prometheus.name }} rules: - apiGroups: diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ClusterRoleBinding.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ClusterRoleBinding.yaml index 67017b7c0..8fc788d23 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ClusterRoleBinding.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ClusterRoleBinding.yaml @@ -3,9 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} name: {{ .Values.prometheus.name }} roleRef: apiGroup: "rbac.authorization.k8s.io" diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml index 9d5f789b8..5e39c1b27 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: ConfigMap metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} name: {{ .Values.prometheus.name }} data: prometheus.yml: | diff --git a/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml b/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml index f9044e9e1..1b41d0e8e 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Collects metrics and aggregates them into graphs. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.prometheus.labels }} - {{- toYaml .Values.prometheus.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.prometheus.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} name: {{ .Values.prometheus.name }} spec: minReadySeconds: 10 @@ -25,23 +25,19 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: prometheus - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.prometheus.podAnnotations }} - {{- toYaml .Values.prometheus.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: prometheus" + .Values.sourcegraph.podAnnotations + .Values.prometheus.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.prometheus) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.prometheus.podLabels }} - {{- toYaml .Values.prometheus.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: prometheus + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.prometheus)) + .Values.sourcegraph.podLabels + .Values.prometheus.podLabels + "deploy: sourcegraph" + "app: prometheus" + ) | nindent 8 }} spec: {{- with .Values.prometheus.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/prometheus/prometheus.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/prometheus/prometheus.PersistentVolumeClaim.yaml index d79efa8b3..6b765ebb2 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} {{- if .Values.prometheus.storageAnnotations }} annotations: {{- toYaml .Values.prometheus.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/prometheus/prometheus.RoleBinding.yaml b/charts/sourcegraph/templates/prometheus/prometheus.RoleBinding.yaml index e28e94ceb..a25617a30 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.RoleBinding.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.RoleBinding.yaml @@ -3,9 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} name: {{ .Values.prometheus.name }} roleRef: apiGroup: "" diff --git a/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml b/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml index 45b7367ac..f3ed75e1d 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml @@ -7,12 +7,14 @@ metadata: {{- toYaml .Values.prometheus.serviceAnnotations | nindent 4 }} {{- end }} labels: - app: prometheus - deploy: sourcegraph - app.kubernetes.io/component: prometheus - {{- if .Values.prometheus.serviceLabels }} - {{- toYaml .Values.prometheus.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: prometheus" + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + .Values.prometheus.serviceLabels + ) | nindent 4 }} name: prometheus spec: ports: diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ServiceAccount.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ServiceAccount.yaml index ba0586448..bdab5e85e 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: prometheus + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: prometheus" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "prometheus") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "prometheus") }} {{- end }} diff --git a/charts/sourcegraph/templates/redis/redis-cache.ConfigMap.yaml b/charts/sourcegraph/templates/redis/redis-cache.ConfigMap.yaml index fc2b350ed..9d6ad852d 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.ConfigMap.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.ConfigMap.yaml @@ -9,12 +9,12 @@ metadata: annotations: description: Configuration for redis-cache labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.redisCache.labels }} - {{- toYaml .Values.redisCache.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.redisCache.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} name: {{ .Values.redisCache.name }}-conf data: redis.conf: | diff --git a/charts/sourcegraph/templates/redis/redis-cache.Deployment.yaml b/charts/sourcegraph/templates/redis/redis-cache.Deployment.yaml index b971f5c53..76b9dc4c2 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.Deployment.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.Deployment.yaml @@ -8,12 +8,12 @@ metadata: annotations: description: Redis for storing short-lived caches. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.redisCache.labels }} - {{- toYaml .Values.redisCache.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.redisCache.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} name: {{ .Values.redisCache.name }} spec: minReadySeconds: 10 @@ -28,26 +28,24 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: redis-cache + {{- $configChecksum := "" }} {{- if and .Values.redisCache.config.enabled (not .Values.redisCache.config.existingConfig) }} - checksum/redis-config: {{ include "sourcegraph.redis.conf" (list . "redisCache") | sha256sum }} + {{- $configChecksum = printf "checksum/redis-config: %s" (include "sourcegraph.redis.conf" (list . "redisCache") | sha256sum) }} {{- end }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.redisCache.podAnnotations }} - {{- toYaml .Values.redisCache.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: redis-cache" + $configChecksum + .Values.sourcegraph.podAnnotations + .Values.redisCache.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.redisCache) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.redisCache.podLabels }} - {{- toYaml .Values.redisCache.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: redis-cache + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.redisCache)) + .Values.sourcegraph.podLabels + .Values.redisCache.podLabels + "deploy: sourcegraph" + "app: redis-cache" + ) | nindent 8 }} spec: {{- with .Values.redisCache.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/redis/redis-cache.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/redis/redis-cache.PersistentVolumeClaim.yaml index bac546ffa..6809e3770 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} {{- if .Values.redisCache.storageAnnotations }} annotations: {{- toYaml .Values.redisCache.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml index 0668eac6c..0d0b6b841 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.redisCache.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.redisCache.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml b/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml index 3e2129d22..7c8917089 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: Secret metadata: labels: - app: redis-cache - deploy: sourcegraph - app.kubernetes.io/component: redis-cache + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: redis-cache" + "deploy: sourcegraph" + "app.kubernetes.io/component: redis-cache" + ) | nindent 4 }} name: {{ .Values.redisCache.name }} type: Opaque data: diff --git a/charts/sourcegraph/templates/redis/redis-cache.Service.yaml b/charts/sourcegraph/templates/redis/redis-cache.Service.yaml index a5c7433e7..a13f69714 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.Service.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.Service.yaml @@ -3,18 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "9121" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.redisCache.serviceAnnotations }} - {{- toYaml .Values.redisCache.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "9121"` + `sourcegraph.prometheus/scrape: "true"` + .Values.redisCache.serviceAnnotations + ) | nindent 4 }} labels: - app: redis-cache - deploy: sourcegraph - app.kubernetes.io/component: redis - {{- if .Values.redisCache.serviceLabels }} - {{- toYaml .Values.redisCache.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: redis-cache" + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + .Values.redisCache.serviceLabels + ) | nindent 4 }} name: redis-cache spec: ports: diff --git a/charts/sourcegraph/templates/redis/redis-cache.ServiceAccount.yaml b/charts/sourcegraph/templates/redis/redis-cache.ServiceAccount.yaml index e7f2c88c7..5d42e4d11 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "redisCache") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "redisCache") }} {{- end }} diff --git a/charts/sourcegraph/templates/redis/redis-store.ConfigMap.yaml b/charts/sourcegraph/templates/redis/redis-store.ConfigMap.yaml index dca95755d..809661cba 100644 --- a/charts/sourcegraph/templates/redis/redis-store.ConfigMap.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.ConfigMap.yaml @@ -9,12 +9,12 @@ metadata: annotations: description: Configuration for redis-store labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.redisStore.labels }} - {{- toYaml .Values.redisStore.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.redisStore.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} name: {{ .Values.redisStore.name }}-conf data: redis.conf: | diff --git a/charts/sourcegraph/templates/redis/redis-store.Deployment.yaml b/charts/sourcegraph/templates/redis/redis-store.Deployment.yaml index 28f0ad05f..01cde3cd0 100644 --- a/charts/sourcegraph/templates/redis/redis-store.Deployment.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.Deployment.yaml @@ -8,12 +8,12 @@ metadata: annotations: description: Redis for storing semi-persistent data like user sessions. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.redisStore.labels }} - {{- toYaml .Values.redisStore.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.redisStore.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} name: {{ .Values.redisStore.name }} spec: minReadySeconds: 10 @@ -28,26 +28,24 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: redis-store + {{- $configChecksum := "" }} {{- if and .Values.redisStore.config.enabled (not .Values.redisStore.config.existingConfig) }} - checksum/redis-config: {{ include "sourcegraph.redis.conf" (list . "redisStore") | sha256sum }} + {{- $configChecksum = printf "checksum/redis-config: %s" (include "sourcegraph.redis.conf" (list . "redisStore") | sha256sum) }} {{- end }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.redisStore.podAnnotations }} - {{- toYaml .Values.redisStore.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: redis-store" + $configChecksum + .Values.sourcegraph.podAnnotations + .Values.redisStore.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.redisStore) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.redisStore.podLabels }} - {{- toYaml .Values.redisStore.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: redis-store + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.redisStore)) + .Values.sourcegraph.podLabels + .Values.redisStore.podLabels + "deploy: sourcegraph" + "app: redis-store" + ) | nindent 8 }} spec: {{- with .Values.redisStore.extraInitContainers }} initContainers: diff --git a/charts/sourcegraph/templates/redis/redis-store.PersistentVolumeClaim.yaml b/charts/sourcegraph/templates/redis/redis-store.PersistentVolumeClaim.yaml index 41cb911ac..59cef628a 100644 --- a/charts/sourcegraph/templates/redis/redis-store.PersistentVolumeClaim.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.PersistentVolumeClaim.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} {{- if .Values.redisStore.storageAnnotations }} annotations: {{- toYaml .Values.redisStore.storageAnnotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml index 99cf9f58b..853d89569 100644 --- a/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.redisStore.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.redisStore.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/redis/redis-store.Secret.yaml b/charts/sourcegraph/templates/redis/redis-store.Secret.yaml index 534fc3779..c27b88178 100644 --- a/charts/sourcegraph/templates/redis/redis-store.Secret.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.Secret.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: Secret metadata: labels: - app: redis-store - deploy: sourcegraph - app.kubernetes.io/component: redis-store + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "app: redis-store" + "deploy: sourcegraph" + "app.kubernetes.io/component: redis-store" + ) | nindent 4 }} name: {{ .Values.redisStore.name }} type: Opaque data: diff --git a/charts/sourcegraph/templates/redis/redis-store.Service.yaml b/charts/sourcegraph/templates/redis/redis-store.Service.yaml index 120724ead..94b479333 100644 --- a/charts/sourcegraph/templates/redis/redis-store.Service.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.Service.yaml @@ -3,18 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "9121" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.redisStore.serviceAnnotations }} - {{- toYaml .Values.redisStore.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "9121"` + `sourcegraph.prometheus/scrape: "true"` + .Values.redisStore.serviceAnnotations + ) | nindent 4 }} labels: - app: redis-store - deploy: sourcegraph - app.kubernetes.io/component: redis - {{- if .Values.redisStore.serviceLabels }} - {{- toYaml .Values.redisStore.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: redis-store" + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + .Values.redisStore.serviceLabels + ) | nindent 4 }} name: redis-store spec: ports: diff --git a/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml b/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml index 94ab30011..8102ce4ea 100644 --- a/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml @@ -3,8 +3,11 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: redis + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: redis" + ) | nindent 4 }} name: {{ include "sourcegraph.serviceAccountName" (list . "redisStore") }} {{- end }} diff --git a/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml index 2683b028c..02b920156 100644 --- a/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.searcher.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.searcher.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/searcher/searcher.Service.yaml b/charts/sourcegraph/templates/searcher/searcher.Service.yaml index 6fc01a7cd..d2faf6c87 100644 --- a/charts/sourcegraph/templates/searcher/searcher.Service.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.Service.yaml @@ -2,18 +2,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.searcher.serviceAnnotations }} - {{- toYaml .Values.searcher.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.searcher.serviceAnnotations + ) | nindent 4 }} labels: - app: searcher - deploy: sourcegraph - app.kubernetes.io/component: searcher - {{- if .Values.searcher.serviceLabels }} - {{- toYaml .Values.searcher.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: searcher" + "deploy: sourcegraph" + "app.kubernetes.io/component: searcher" + .Values.searcher.serviceLabels + ) | nindent 4 }} name: searcher spec: clusterIP: None diff --git a/charts/sourcegraph/templates/searcher/searcher.ServiceAccount.yaml b/charts/sourcegraph/templates/searcher/searcher.ServiceAccount.yaml index d065a9f1d..e92e7ace5 100644 --- a/charts/sourcegraph/templates/searcher/searcher.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: searcher + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: searcher" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "searcher") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "searcher") }} {{- end }} diff --git a/charts/sourcegraph/templates/searcher/searcher.StatefulSet.yaml b/charts/sourcegraph/templates/searcher/searcher.StatefulSet.yaml index 218c932c8..01185d64f 100644 --- a/charts/sourcegraph/templates/searcher/searcher.StatefulSet.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.StatefulSet.yaml @@ -4,12 +4,12 @@ metadata: annotations: description: Backend for text search operations. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.searcher.labels }} - {{- toYaml .Values.searcher.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: searcher + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.searcher.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: searcher" + ) | nindent 4 }} name: {{ .Values.searcher.name }} spec: replicas: {{ .Values.searcher.replicaCount }} @@ -24,24 +24,20 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: searcher - {{- include "sourcegraph.redisChecksum" . | nindent 8 }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.searcher.podAnnotations }} - {{- toYaml .Values.searcher.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: searcher" + (include "sourcegraph.redisChecksum" .) + .Values.sourcegraph.podAnnotations + .Values.searcher.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.searcher) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.searcher.podLabels }} - {{- toYaml .Values.searcher.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: searcher + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.searcher)) + .Values.sourcegraph.podLabels + .Values.searcher.podLabels + "deploy: sourcegraph" + "app: searcher" + ) | nindent 8 }} spec: {{- include "sourcegraph.terminationGracePeriodSeconds" (list . "searcher") | nindent 6 }} {{- with .Values.searcher.extraInitContainers }} diff --git a/charts/sourcegraph/templates/storageclass.yaml b/charts/sourcegraph/templates/storageclass.yaml index a3af7c53d..3b3601975 100644 --- a/charts/sourcegraph/templates/storageclass.yaml +++ b/charts/sourcegraph/templates/storageclass.yaml @@ -4,8 +4,10 @@ apiVersion: storage.k8s.io/v1 metadata: name: {{ .Values.storageClass.name }} labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - deploy: sourcegraph-storage + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + "deploy: sourcegraph-storage" + ) | nindent 4 }} {{- if .Values.storageClass.annotations}} annotations: {{- toYaml .Values.storageClass.annotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.Deployment.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.Deployment.yaml index 73b6394b6..164c186fa 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.Deployment.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.Deployment.yaml @@ -5,12 +5,12 @@ metadata: annotations: description: Handles syntactic code intelligence indexing labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.syntacticCodeIntel.labels }} - {{- toYaml .Values.syntacticCodeIntel.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: syntactic-code-intel + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.syntacticCodeIntel.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: syntactic-code-intel" + ) | nindent 4 }} name: {{ .Values.syntacticCodeIntel.name }} spec: minReadySeconds: 10 @@ -28,24 +28,20 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: syntactic-code-intel-worker - {{- include "sourcegraph.redisChecksum" . | nindent 8 }} - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.syntacticCodeIntel.podAnnotations }} - {{- toYaml .Values.syntacticCodeIntel.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: syntactic-code-intel-worker" + (include "sourcegraph.redisChecksum" .) + .Values.sourcegraph.podAnnotations + .Values.syntacticCodeIntel.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.syntacticCodeIntel) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.syntacticCodeIntel.podLabels }} - {{- toYaml .Values.syntacticCodeIntel.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: syntactic-code-intel-worker + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.syntacticCodeIntel)) + .Values.sourcegraph.podLabels + .Values.syntacticCodeIntel.podLabels + "deploy: sourcegraph" + "app: syntactic-code-intel-worker" + ) | nindent 8 }} spec: {{- $storageType := .Values.syntacticCodeIntel.storageType | default "emptyDir" }} {{- if not (has $storageType (list "emptyDir" "pvc")) }} diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml index 9f62342ad..5d697c2aa 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.syntacticCodeIntel.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.syntacticCodeIntel.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml index 9a8d54260..6c5286f54 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml @@ -3,18 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.syntacticCodeIntel.serviceAnnotations }} - {{- toYaml .Values.syntacticCodeIntel.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.syntacticCodeIntel.serviceAnnotations + ) | nindent 4 }} labels: - app: syntactic-code-intel-worker - deploy: sourcegraph - app.kubernetes.io/component: syntactic-code-intel - {{- if .Values.syntacticCodeIntel.serviceLabels }} - {{- toYaml .Values.syntacticCodeIntel.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: syntactic-code-intel-worker" + "deploy: sourcegraph" + "app.kubernetes.io/component: syntactic-code-intel" + .Values.syntacticCodeIntel.serviceLabels + ) | nindent 4 }} name: syntactic-code-intel-worker spec: ports: diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.ServiceAccount.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.ServiceAccount.yaml index 10f1e741c..f9a477401 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: syntactic-code-intel + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: syntactic-code-intel" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "syntacticCodeIntel") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "syntacticCodeIntel") }} {{- end }} diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.Deployment.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.Deployment.yaml index 94fa63718..58742279f 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.Deployment.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.Deployment.yaml @@ -4,12 +4,12 @@ metadata: annotations: description: Backend for syntax highlighting operations. labels: - {{- include "sourcegraph.labels" . | nindent 4 }} - {{- if .Values.syntectServer.labels }} - {{- toYaml .Values.syntectServer.labels | nindent 4 }} - {{- end }} - deploy: sourcegraph - app.kubernetes.io/component: syntect-server + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.syntectServer.labels + "deploy: sourcegraph" + "app.kubernetes.io/component: syntect-server" + ) | nindent 4 }} name: {{ .Values.syntectServer.name }} spec: minReadySeconds: 10 @@ -27,23 +27,19 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-container: syntect-server - {{- if .Values.sourcegraph.podAnnotations }} - {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} - {{- end }} - {{- if .Values.syntectServer.podAnnotations }} - {{- toYaml .Values.syntectServer.podAnnotations | nindent 8 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + "kubectl.kubernetes.io/default-container: syntect-server" + .Values.sourcegraph.podAnnotations + .Values.syntectServer.podAnnotations + ) | nindent 8 }} labels: - {{- include "sourcegraph.selectorLabels" (list . .Values.syntectServer) | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.syntectServer.podLabels }} - {{- toYaml .Values.syntectServer.podLabels | nindent 8 }} - {{- end }} - deploy: sourcegraph - app: syntect-server + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.selectorLabels" (list . .Values.syntectServer)) + .Values.sourcegraph.podLabels + .Values.syntectServer.podLabels + "deploy: sourcegraph" + "app: syntect-server" + ) | nindent 8 }} spec: {{- include "sourcegraph.terminationGracePeriodSeconds" (list . "syntectServer") | nindent 6 }} {{- with .Values.syntectServer.extraInitContainers }} diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml index d34cf4bee..998e6a9fb 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml @@ -3,6 +3,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ .Values.syntectServer.name }} + {{- with .Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml .Values.syntectServer.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml index dc5eccc7d..484807736 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml @@ -2,18 +2,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.syntectServer.serviceAnnotations }} - {{- toYaml .Values.syntectServer.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.syntectServer.serviceAnnotations + ) | nindent 4 }} labels: - app: syntect-server - deploy: sourcegraph - app.kubernetes.io/component: syntect-server - {{- if .Values.syntectServer.serviceLabels }} - {{- toYaml .Values.syntectServer.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: syntect-server" + "deploy: sourcegraph" + "app.kubernetes.io/component: syntect-server" + .Values.syntectServer.serviceLabels + ) | nindent 4 }} name: syntect-server spec: ports: diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.ServiceAccount.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.ServiceAccount.yaml index 36764b58c..3e805a4ea 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: syntect-server + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: syntect-server" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "syntectServer") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "syntectServer") }} {{- end }} diff --git a/charts/sourcegraph/templates/tests/test-connection.yaml b/charts/sourcegraph/templates/tests/test-connection.yaml index 3aafe14f7..0b3a88407 100644 --- a/charts/sourcegraph/templates/tests/test-connection.yaml +++ b/charts/sourcegraph/templates/tests/test-connection.yaml @@ -5,7 +5,10 @@ metadata: annotations: "helm.sh/hook": test labels: - {{- include "sourcegraph.labels" . | nindent 4 }} + {{- include "sourcegraph.uniqueKeys" (list + (include "sourcegraph.labels" .) + .Values.sourcegraph.podLabels + ) | nindent 4 }} name: "sg-test-connection" spec: containers: diff --git a/charts/sourcegraph/templates/worker/worker-executors.Service.yaml b/charts/sourcegraph/templates/worker/worker-executors.Service.yaml index a12d9e122..0eddf467c 100644 --- a/charts/sourcegraph/templates/worker/worker-executors.Service.yaml +++ b/charts/sourcegraph/templates/worker/worker-executors.Service.yaml @@ -2,18 +2,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6996" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.worker.serviceAnnotations }} - {{- toYaml .Values.worker.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6996"` + `sourcegraph.prometheus/scrape: "true"` + .Values.worker.serviceAnnotations + ) | nindent 4 }} labels: - app: worker - deploy: sourcegraph - app.kubernetes.io/component: worker - {{- if .Values.worker.serviceLabels }} - {{- toYaml .Values.worker.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: worker" + "deploy: sourcegraph" + "app.kubernetes.io/component: worker" + .Values.worker.serviceLabels + ) | nindent 4 }} name: worker-executors spec: ports: diff --git a/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml index cd52d3c6d..e634efd29 100644 --- a/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml @@ -9,6 +9,10 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ $name }} + {{- with $top.Values.sourcegraph.labels }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- toYaml $top.Values.worker.podDisruptionBudget | nindent 2 }} selector: diff --git a/charts/sourcegraph/templates/worker/worker.Service.yaml b/charts/sourcegraph/templates/worker/worker.Service.yaml index b5a5ffb12..eb2a1692f 100644 --- a/charts/sourcegraph/templates/worker/worker.Service.yaml +++ b/charts/sourcegraph/templates/worker/worker.Service.yaml @@ -2,18 +2,20 @@ apiVersion: v1 kind: Service metadata: annotations: - prometheus.io/port: "6060" - sourcegraph.prometheus/scrape: "true" - {{- if .Values.worker.serviceAnnotations }} - {{- toYaml .Values.worker.serviceAnnotations | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + `prometheus.io/port: "6060"` + `sourcegraph.prometheus/scrape: "true"` + .Values.worker.serviceAnnotations + ) | nindent 4 }} labels: - app: worker - deploy: sourcegraph - app.kubernetes.io/component: worker - {{- if .Values.worker.serviceLabels }} - {{- toYaml .Values.worker.serviceLabels | nindent 4 }} - {{- end }} + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + .Values.sourcegraph.serviceLabels + "app: worker" + "deploy: sourcegraph" + "app.kubernetes.io/component: worker" + .Values.worker.serviceLabels + ) | nindent 4 }} name: worker spec: ports: diff --git a/charts/sourcegraph/templates/worker/worker.ServiceAccount.yaml b/charts/sourcegraph/templates/worker/worker.ServiceAccount.yaml index 21b276c82..6d37a35ff 100644 --- a/charts/sourcegraph/templates/worker/worker.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/worker/worker.ServiceAccount.yaml @@ -3,9 +3,12 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - category: rbac - deploy: sourcegraph - app.kubernetes.io/component: worker + {{- include "sourcegraph.uniqueKeys" (list + .Values.sourcegraph.labels + "category: rbac" + "deploy: sourcegraph" + "app.kubernetes.io/component: worker" + ) | nindent 4 }} {{- include "sourcegraph.serviceAccountAnnotations" (list . "worker") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "worker") }} {{- end }} diff --git a/charts/sourcegraph/tests/sourcegraphLabels_test.yaml b/charts/sourcegraph/tests/sourcegraphLabels_test.yaml new file mode 100644 index 000000000..de610dd60 --- /dev/null +++ b/charts/sourcegraph/tests/sourcegraphLabels_test.yaml @@ -0,0 +1,92 @@ +# sourcegraph.labels is documented as labels for every resource the chart +# creates. The first test asserts on every template, so a new template that +# leaves the labels out fails here. +suite: sourcegraph.labels on every resource +release: + name: sourcegraph + namespace: sourcegraph +templates: +- "*.yaml" +- "*/*.yaml" +excludeTemplates: +# Rendered as the user wrote them +- extraResources.yaml +# Fails to render when enabled, with or without sourcegraph.labels +- jaeger/jaeger.ServiceAccount.yaml +# Empty with the values of this suite; the next suite covers them +- otel-collector/otel-collector.ConfigMap.yaml +- prometheus/prometheus.RoleBinding.yaml +values: +- uniqueKeys_everyValue.yaml +set: + sourcegraph: + labels: + example.com/cost-center: "1234" +tests: +- it: should add the labels to every resource + asserts: + - equal: + path: metadata.labels["example.com/cost-center"] + value: "1234" + +- it: should not add the labels to pod templates and volume claim templates + template: gitserver/gitserver.StatefulSet.yaml + asserts: + - notExists: + path: spec.template.metadata.labels["example.com/cost-center"] + - notExists: + path: spec.volumeClaimTemplates[0].metadata.labels["example.com/cost-center"] +--- +suite: sourcegraph.labels +release: + name: sourcegraph + namespace: sourcegraph +tests: +- it: should add the labels to the resources that replace others + set: + sourcegraph: + labels: + example.com/cost-center: "1234" + prometheus: + privileged: false + openTelemetry: + gateway: + config: + traces: + exporters: + otlp: + endpoint: otel.example.com:4317 + templates: + - otel-collector/otel-collector.ConfigMap.yaml + - prometheus/prometheus.RoleBinding.yaml + asserts: + - equal: + path: metadata.labels["example.com/cost-center"] + value: "1234" + +- it: should keep the labels the chart sets + set: + sourcegraph: + labels: + example.com/cost-center: "1234" + app: from-values + deploy: from-values + template: frontend/sourcegraph-frontend.Service.yaml + asserts: + - equal: + path: metadata.labels + value: + example.com/cost-center: "1234" + app: sourcegraph-frontend + deploy: sourcegraph + app.kubernetes.io/component: frontend + +- it: should render no labels key on a resource without labels when unset + set: + gitserver: + podDisruptionBudget: + minAvailable: 1 + template: gitserver/gitserver.PodDisruptionBudget.yaml + asserts: + - notExists: + path: metadata.labels diff --git a/charts/sourcegraph/tests/sourcegraphPodLabels_test.yaml b/charts/sourcegraph/tests/sourcegraphPodLabels_test.yaml new file mode 100644 index 000000000..5b5ddb1df --- /dev/null +++ b/charts/sourcegraph/tests/sourcegraphPodLabels_test.yaml @@ -0,0 +1,54 @@ +# sourcegraph.podLabels is documented as labels for all pods. The first test +# asserts on every workload template, so a new workload that leaves the labels +# out fails here. +suite: sourcegraph.podLabels on every pod template +release: + name: sourcegraph + namespace: sourcegraph +templates: +- "*/*Deployment.yaml" +- "*/*StatefulSet.yaml" +- "*/*DaemonSet.yaml" +excludeTemplates: +# Reads its ConfigMap template, which this suite does not render; the next suite covers it +- jaeger/jaeger.Deployment.yaml +values: +- uniqueKeys_everyValue.yaml +set: + sourcegraph: + podLabels: + example.com/mesh: enabled +tests: +- it: should add the labels to every pod template + asserts: + - equal: + path: spec.template.metadata.labels["example.com/mesh"] + value: enabled +--- +suite: sourcegraph.podLabels +release: + name: sourcegraph + namespace: sourcegraph +set: + sourcegraph: + podLabels: + example.com/mesh: enabled +tests: +- it: should add the labels to the jaeger pod template + set: + jaeger: + enabled: true + template: jaeger/jaeger.Deployment.yaml + asserts: + - equal: + path: spec.template.metadata.labels["example.com/mesh"] + value: enabled + +- it: should add the labels to the helm test pod + template: tests/test-connection.yaml + asserts: + - isKind: + of: Pod + - equal: + path: metadata.labels["example.com/mesh"] + value: enabled diff --git a/charts/sourcegraph/tests/sourcegraphServiceLabels_test.yaml b/charts/sourcegraph/tests/sourcegraphServiceLabels_test.yaml new file mode 100644 index 000000000..8d0364020 --- /dev/null +++ b/charts/sourcegraph/tests/sourcegraphServiceLabels_test.yaml @@ -0,0 +1,58 @@ +# sourcegraph.serviceLabels is documented as labels for all Services. The first +# test asserts on every Service template, so a new Service that leaves the +# labels out fails here. +suite: sourcegraph.serviceLabels on every Service +release: + name: sourcegraph + namespace: sourcegraph +templates: +- "*/*Service.yaml" +values: +- uniqueKeys_everyValue.yaml +set: + sourcegraph: + serviceLabels: + example.com/exposure: internal +tests: +- it: should add the labels to every Service + asserts: + - isKind: + of: Service + - equal: + path: metadata.labels["example.com/exposure"] + value: internal +--- +suite: sourcegraph.serviceLabels +release: + name: sourcegraph + namespace: sourcegraph +set: + sourcegraph: + labels: + example.com/exposure: unset + serviceLabels: + example.com/exposure: internal + frontend: + serviceLabels: + example.com/exposure: public +tests: +- it: should take precedence over sourcegraph.labels, and a component's serviceLabels over both + templates: + - frontend/sourcegraph-frontend.Service.yaml + - gitserver/gitserver.Service.yaml + asserts: + - equal: + path: metadata.labels["example.com/exposure"] + value: public + template: frontend/sourcegraph-frontend.Service.yaml + - equal: + path: metadata.labels["example.com/exposure"] + value: internal + template: gitserver/gitserver.Service.yaml + +- it: should not add the labels to other resources + template: frontend/sourcegraph-frontend.Deployment.yaml + asserts: + - equal: + path: metadata.labels["example.com/exposure"] + value: unset diff --git a/charts/sourcegraph/tests/uniqueKeys_everyValue.yaml b/charts/sourcegraph/tests/uniqueKeys_everyValue.yaml new file mode 100644 index 000000000..785561f85 --- /dev/null +++ b/charts/sourcegraph/tests/uniqueKeys_everyValue.yaml @@ -0,0 +1,97 @@ +# Every label and annotation value sets the same keys, including keys the chart +# sets itself, and every optional object is enabled. Used by uniqueKeys_test.yaml. +sourcegraph: + labels: &objectLabels + example.com/team: platform + deploy: from-values + app: from-values + app.kubernetes.io/component: from-values + app.kubernetes.io/name: from-values + helm.sh/chart: from-values + podLabels: &podLabels + example.com/team: platform + deploy: from-values + app: from-values + app.kubernetes.io/component: from-values + serviceLabels: *objectLabels + podAnnotations: &annotations + example.com/owner: platform + kubectl.kubernetes.io/default-container: from-values + prometheus.io/port: "9999" + sourcegraph.prometheus/scrape: "false" + +blobstore: &component + labels: *objectLabels + podLabels: *podLabels + podAnnotations: *annotations + serviceLabels: *objectLabels + serviceAnnotations: *annotations + serviceAccount: + create: true +cadvisor: *component +codeInsightsDB: *component +codeIntelDB: *component +grafana: + <<: *component + storageLabels: *objectLabels +nodeExporter: *component +pgsql: *component +prometheus: *component + +syntectServer: &componentWithBudget + <<: *component + podDisruptionBudget: + minAvailable: 1 +frontend: + <<: *componentWithBudget + ingress: + labels: *objectLabels +gitserver: + <<: *componentWithBudget + storageLabels: *objectLabels +indexedSearch: + <<: *componentWithBudget + storageLabels: *objectLabels +searcher: + <<: *componentWithBudget + storageLabels: *objectLabels +worker: + <<: *componentWithBudget + replicas: + - jobs: ["codeintel-upload-janitor"] + - jobs: ["insights-job"] + +redisCache: &redis + <<: *componentWithBudget + config: + enabled: true +redisStore: *redis + +preciseCodeIntel: &codeIntel + <<: *componentWithBudget + enabled: true + storageType: pvc + storageSize: 10Gi +syntacticCodeIntel: *codeIntel + +openTelemetry: + agent: *component + gateway: *component + +jaeger: + enabled: true + labels: *objectLabels + podLabels: *podLabels + podAnnotations: *annotations + collector: + serviceLabels: *objectLabels + serviceAnnotations: *annotations + query: + serviceLabels: *objectLabels + serviceAnnotations: *annotations + +storageClass: + create: true +priorityClasses: +- name: sourcegraph-high-priority + value: 1000 diff --git a/charts/sourcegraph/tests/uniqueKeys_test.yaml b/charts/sourcegraph/tests/uniqueKeys_test.yaml new file mode 100644 index 000000000..82633dc53 --- /dev/null +++ b/charts/sourcegraph/tests/uniqueKeys_test.yaml @@ -0,0 +1,115 @@ +# The chart renders each label and annotation key once on an object. +# helm-unittest fails a test when any rendered manifest repeats a key, as +# Kustomize does, so every test here checks the whole chart as well as its own +# assertions. +suite: unique keys +release: + name: sourcegraph + namespace: sourcegraph +tests: +- it: should render a label set for every component and for one component once, with the component's value + set: + sourcegraph: + labels: + example.com/team: platform + podLabels: + example.com/team: platform + frontend: + labels: + example.com/team: frontend + podLabels: + example.com/team: frontend + templates: + - frontend/sourcegraph-frontend.Deployment.yaml + - gitserver/gitserver.StatefulSet.yaml + asserts: + - equal: + path: metadata.labels["example.com/team"] + value: frontend + template: frontend/sourcegraph-frontend.Deployment.yaml + - equal: + path: spec.template.metadata.labels["example.com/team"] + value: frontend + template: frontend/sourcegraph-frontend.Deployment.yaml + - equal: + path: metadata.labels["example.com/team"] + value: platform + template: gitserver/gitserver.StatefulSet.yaml + - equal: + path: spec.template.metadata.labels["example.com/team"] + value: platform + template: gitserver/gitserver.StatefulSet.yaml + +- it: should keep the labels the chart sets after the values, as before + set: + sourcegraph: + labels: + deploy: from-values + podLabels: + app: from-values + template: frontend/sourcegraph-frontend.Deployment.yaml + asserts: + - equal: + path: metadata.labels.deploy + value: sourcegraph + - equal: + path: spec.template.metadata.labels.app + value: sourcegraph-frontend + +- it: should keep a value that replaces a label the chart sets before it, as before + set: + frontend: + serviceLabels: + app: from-values + template: frontend/sourcegraph-frontend.Service.yaml + asserts: + - equal: + path: metadata.labels + value: + app: from-values + deploy: sourcegraph + app.kubernetes.io/component: frontend + +- it: should render an annotation set for every pod and for one component's pods once, with the component's value + set: + sourcegraph: + podAnnotations: + example.com/owner: platform + example.com/notes: | + Set for every pod. + On two lines. + frontend: + podAnnotations: + example.com/owner: frontend + template: frontend/sourcegraph-frontend.Deployment.yaml + asserts: + - equal: + path: spec.template.metadata.annotations["example.com/owner"] + value: frontend + - equal: + path: spec.template.metadata.annotations["example.com/notes"] + value: | + Set for every pod. + On two lines. + +- it: should keep a value that replaces an annotation the chart sets before it, as before + set: + frontend: + serviceAnnotations: + prometheus.io/port: "9999" + template: frontend/sourcegraph-frontend.Service.yaml + asserts: + - equal: + path: metadata.annotations + value: + prometheus.io/port: "9999" + sourcegraph.prometheus/scrape: "true" + +- it: should render every object when every label and annotation value sets the same keys + values: + - uniqueKeys_everyValue.yaml + template: worker/worker.Deployment.yaml + asserts: + - equal: + path: metadata.labels["example.com/team"] + value: platform diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index ff4b04e02..14fac40aa 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -15,7 +15,9 @@ sourcegraph: useGlobalTagAsDefault: false # -- Mount named secrets containing docker credentials imagePullSecrets: [] - # -- Add extra labels to all resources + # -- Add extra labels to every resource the chart creates. The chart does not add them to pod templates + # (use `sourcegraph.podLabels`), to StatefulSet volume claim templates, which Kubernetes does not allow changing + # (use `.storageLabels`), or to `extraResources` labels: {} # -- When true, remove all resource stanzas, allowing the scheduler to best-fit pods. Intended for local development with limited resources. localDevMode: false @@ -48,7 +50,8 @@ sourcegraph: # -- Add extra labels to all services serviceLabels: {} # -- Labels that replace `app.kubernetes.io/name` and `app.kubernetes.io/instance` in every component's - # workload selector, pod labels, and Service and PodDisruptionBudget selectors. + # workload selector, pod labels, and Service and PodDisruptionBudget selectors. `jaeger` keeps its own selector + # labels and ignores this value. # Only for adopting workloads created outside this chart, whose selectors Kubernetes does not allow changing: # set it on the first install and never change it afterwards. Use `.extraSelectorLabels` # for labels that differ per component. See [Adopting existing workloads](#adopting-existing-workloads) @@ -70,10 +73,12 @@ sourcegraph: # # Override the global sourcegraph.image.repository on a service-specific basis # repository: # -# # Add additional labels and annotations to various resources +# # Add labels to the component's Deployment, StatefulSet, or DaemonSet # labels: {} +# # Add labels and annotations to the component's pods # podLabels: {} # podAnnotations: {} +# # Add labels and annotations to the component's Services. jaeger has collector and query values instead # serviceLabels: {} # serviceAnnotations: {} # # Provide custom environment variables @@ -96,7 +101,8 @@ sourcegraph: # # Add ports to the component's primary Service # extraServicePorts: [] # # Add labels to the component's workload selector, pod labels, and Service and PodDisruptionBudget selectors, -# # to adopt a workload created outside this chart. Never change it on an installed release +# # to adopt a workload created outside this chart. Never change it on an installed release. +# # jaeger does not support it # extraSelectorLabels: {} # # Toggle serviceAccount creation # serviceAccount.create: true