diff --git a/charts/self-host/templates/admin.yaml b/charts/self-host/templates/admin.yaml index 6258c74ab..1206a99f5 100644 --- a/charts/self-host/templates/admin.yaml +++ b/charts/self-host/templates/admin.yaml @@ -7,6 +7,7 @@ metadata: labels: app.kubernetes.io/component: admin app: {{ template "bitwarden.admin" . }} + {{ include "bitwarden.labels" . | indent 4 }} {{- with .Values.component.admin.labels }} {{ toYaml . | indent 4 }} @@ -25,6 +26,7 @@ spec: app: {{ template "bitwarden.admin" . }} {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.admin.podServiceAccount }} serviceAccount: {{ .Values.component.admin.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.admin.podServiceAccount | quote }} diff --git a/charts/self-host/templates/attachments.yaml b/charts/self-host/templates/attachments.yaml index 60978f367..2baa93e13 100644 --- a/charts/self-host/templates/attachments.yaml +++ b/charts/self-host/templates/attachments.yaml @@ -12,6 +12,7 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} spec: + replicas: 1 strategy: type: {{ .Values.component.attachments.deploymentStrategy | quote }} @@ -25,6 +26,7 @@ spec: app.kubernetes.io/component: attachments {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.attachments.podServiceAccount }} serviceAccount: {{ .Values.component.attachments.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.attachments.podServiceAccount | quote }} diff --git a/charts/self-host/templates/events.yaml b/charts/self-host/templates/events.yaml index 59e075d6e..9f4158058 100644 --- a/charts/self-host/templates/events.yaml +++ b/charts/self-host/templates/events.yaml @@ -12,6 +12,7 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} spec: + replicas: 1 strategy: type: {{ .Values.component.events.deploymentStrategy | quote }} @@ -25,6 +26,7 @@ spec: app.kubernetes.io/component: events {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.events.podServiceAccount }} serviceAccount: {{ .Values.component.events.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.events.podServiceAccount | quote }} diff --git a/charts/self-host/templates/helpers.tpl b/charts/self-host/templates/helpers.tpl index 973e015ab..3b4d4eaeb 100644 --- a/charts/self-host/templates/helpers.tpl +++ b/charts/self-host/templates/helpers.tpl @@ -51,6 +51,9 @@ app.kubernetes.io/name: {{ template "bitwarden.name" . }} app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} helm.sh/chart: {{ template "bitwarden.chart" . }} +{{- if eq .Values.general.volumeAccessMode "ReadWriteOnce" }} +app.kubernetes.io/storage: "ReadWriteOnce" +{{- end -}} {{- if .Values.general.labels }} {{ toYaml .Values.general.labels }} {{- end -}} @@ -225,6 +228,22 @@ Name of SCIM components {{ template "bitwarden.fullname" . }}-scim {{- end -}} +{{- define "bitwarden.podCoLocation.affinity" -}} +{{- if eq .Values.general.volumeAccessMode "ReadWriteOnce" }} +affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app.kubernetes.io/storage + operator: In + values: + - ReadWriteOnce + topologyKey: "kubernetes.io/hostname" +{{- end -}} +{{- end -}} + + {{/* Name of the keys secret */}} diff --git a/charts/self-host/templates/icons.yaml b/charts/self-host/templates/icons.yaml index 55bed5af4..e0eb91a04 100644 --- a/charts/self-host/templates/icons.yaml +++ b/charts/self-host/templates/icons.yaml @@ -25,6 +25,7 @@ spec: app.kubernetes.io/component: icons {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.icons.podServiceAccount }} serviceAccount: {{ .Values.component.icons.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.icons.podServiceAccount | quote }} diff --git a/charts/self-host/templates/identity.yaml b/charts/self-host/templates/identity.yaml index 8d8849b1c..31d12c355 100644 --- a/charts/self-host/templates/identity.yaml +++ b/charts/self-host/templates/identity.yaml @@ -25,6 +25,7 @@ spec: app.kubernetes.io/component: identity {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.identity.podServiceAccount }} serviceAccount: {{ .Values.component.identity.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.identity.podServiceAccount | quote }} diff --git a/charts/self-host/templates/notifications.yaml b/charts/self-host/templates/notifications.yaml index ce436a30d..57ea9352c 100644 --- a/charts/self-host/templates/notifications.yaml +++ b/charts/self-host/templates/notifications.yaml @@ -25,6 +25,7 @@ spec: app.kubernetes.io/component: notifications {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.notifications.podServiceAccount }} serviceAccount: {{ .Values.component.notifications.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.notifications.podServiceAccount | quote }} diff --git a/charts/self-host/templates/post-install-db-migrator-job.yaml b/charts/self-host/templates/post-install-db-migrator-job.yaml index 670b5cb5d..6e515fd50 100644 --- a/charts/self-host/templates/post-install-db-migrator-job.yaml +++ b/charts/self-host/templates/post-install-db-migrator-job.yaml @@ -16,6 +16,18 @@ spec: labels: app.kubernetes.io/component: post-install-db-migrator-job spec: + {{- if and (.Values.database.enabled) ( eq .Values.general.volumeAccessMode "ReadWriteOnce") }} + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ template "bitwarden.mssql" . }} + topologyKey: "kubernetes.io/hostname" + {{- end }} {{- if .Values.serviceAccount.name }} serviceAccountName: "{{ .Values.serviceAccount.name }}" {{- end }} diff --git a/charts/self-host/templates/pre-install-db-migrator-job.yaml b/charts/self-host/templates/pre-install-db-migrator-job.yaml index 87e1d8fa4..29bd562fc 100644 --- a/charts/self-host/templates/pre-install-db-migrator-job.yaml +++ b/charts/self-host/templates/pre-install-db-migrator-job.yaml @@ -20,6 +20,18 @@ spec: labels: app.kubernetes.io/component: pre-install-db-migrator-job spec: + {{- if and (.Values.database.enabled) (eq .Values.general.volumeAccessMode "ReadWriteOnce") }} + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ template "bitwarden.mssql" . }} + topologyKey: "kubernetes.io/hostname" + {{- end }} {{- if .Values.serviceAccount.name }} serviceAccountName: {{ .Values.serviceAccount.name | quote }} {{- end }} diff --git a/charts/self-host/templates/scim.yaml b/charts/self-host/templates/scim.yaml index 6dd5027bd..c7aae267a 100644 --- a/charts/self-host/templates/scim.yaml +++ b/charts/self-host/templates/scim.yaml @@ -26,6 +26,7 @@ spec: app.kubernetes.io/component: scim {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.scim.podServiceAccount }} serviceAccount: {{ .Values.component.scim.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.scim.podServiceAccount | quote }} diff --git a/charts/self-host/templates/sso.yaml b/charts/self-host/templates/sso.yaml index 2b9653cfd..7175de344 100644 --- a/charts/self-host/templates/sso.yaml +++ b/charts/self-host/templates/sso.yaml @@ -25,6 +25,7 @@ spec: app.kubernetes.io/component: sso {{ include "bitwarden.labels" . | indent 8 }} spec: +{{ include "bitwarden.podCoLocation.affinity" . | indent 6 }} {{- if .Values.component.sso.podServiceAccount }} serviceAccount: {{ .Values.component.sso.podServiceAccount | quote }} serviceAccountName: {{ .Values.component.sso.podServiceAccount | quote }}