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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions charts/matrix-stack/source/common/affinity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"type": "object",
"properties": {
"nodeAffinity": {
"type": "object",
"additionalProperties": false,
"properties": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"type": "object",
"additionalProperties": true
},
"preferredDuringSchedulingIgnoredDuringExecution": {
"type": "array"
}
}
},
"podAffinity": {
"type": "object",
"additionalProperties": false,
"properties": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"type": "array"
},
"preferredDuringSchedulingIgnoredDuringExecution": {
"type": "array"
}
}
},
"podAntiAffinity": {
"type": "object",
"additionalProperties": false,
"properties": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"type": "array"
},
"preferredDuringSchedulingIgnoredDuringExecution": {
"type": "array"
}
}
}
},
"additionalProperties": false
}
22 changes: 22 additions & 0 deletions charts/matrix-stack/source/common/sub_schema_values.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ image:
{{ tolerations(global=true) }}
{{ topologySpreadConstraints(global=true) }}
{{ priorityClassName(global=true) }}
{{ affinity(global=true) }}

## The cluster's domain name which will be appended to URLs of internal Services (<name>.<namespace>.svc.<clusterDomain>).
## It is unusual to need to change this but if you do need to change it,
Expand Down Expand Up @@ -230,6 +231,27 @@ networking:
{{ key }}: ""
{%- endmacro %}

{% macro affinity(global=false, key='affinity') %}
{%- if global %}
## Default affinity rules applied to the pods of all components.
## Configured independently per affinity type (nodeAffinity, podAffinity, podAntiAffinity).
## A component that sets one of these affinity types overrides only that type for that component; the other types are still inherited from here.
## Synapse worker pods inherit the affinity of the Synapse main process; per-worker affinity is not yet configurable.
{%- else %}
## If specified, the pod's scheduling constraints, configured independently per affinity type.
## Each affinity type set here overrides only the matching global affinity type for this component.
## Set an affinity type to {} to blank out the value inherited from the global affinity for that type.
{%- endif %}
## Supports nodeAffinity, podAffinity and podAntiAffinity.
## More info: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity
## Example:
## {{ key }}:
## nodeAffinity: {}
## podAffinity: {}
## podAntiAffinity: {}
{{ key }}: {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{ key }}: {}
{{ key }}:
nodeAffinity: {}
podAffinity: {}
podAntiAffinity: {}

With commented examples above each sub-key.

Potentially the default of {} needs to differ between globally and per-component so that you've a way of unsetting/blanking out a global e.g. nodeAffinity

{%- endmacro %}

{% macro persistentVolumeClaim(key, global=false) %}
## Configures the {{ 'defaults for all constructed PersistentVolumeClaims' if global else 'PersistentVolumeClaim to be used for storage' }}
{{ key }}:
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/deployment-markers.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/deployment-markers.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rbac:
{{- sub_schema_values.extraInitContainers("Deployment Markers") }}
{{- sub_schema_values.nodeSelector() -}}
{{- sub_schema_values.priorityClassName() -}}
{{- sub_schema_values.affinity() -}}
{{- sub_schema_values.podSecurityContext(user_id='10010', group_id='10010') -}}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='200Mi') -}}
{{- sub_schema_values.serviceAccount() -}}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/element-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/element-admin.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ replicas: 1
{{- sub_schema_values.containersSecurityContext() -}}
{{- sub_schema_values.nodeSelector() -}}
{{- sub_schema_values.priorityClassName() -}}
{{- sub_schema_values.affinity() -}}
{{- sub_schema_values.podSecurityContext(user_id='10104', group_id='10104') -}}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='200Mi') -}}
{{- sub_schema_values.serviceAccount() -}}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/element-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/element-web.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ replicas: 1
{{- sub_schema_values.containersSecurityContext() -}}
{{- sub_schema_values.nodeSelector() -}}
{{- sub_schema_values.priorityClassName() -}}
{{- sub_schema_values.affinity() -}}
{{- sub_schema_values.podSecurityContext(user_id='10004', group_id='10004') -}}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='200Mi') -}}
{{- sub_schema_values.serviceAccount() -}}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/haproxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/haproxy.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ replicas: 1
{{- sub_schema_values.extraInitContainers("HAProxy") }}
{{- sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{- sub_schema_values.podSecurityContext(user_id='10001', group_id='10001') }}
{{- sub_schema_values.resources(requests_memory='100Mi', requests_cpu='100m', limits_memory='200Mi') }}
{{- sub_schema_values.serviceAccount() }}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/hookshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/hookshot.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ replicas: 1
{{ sub_schema_values.serviceAccount() }}
{{ sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{ sub_schema_values.tolerations() }}
{{ sub_schema_values.topologySpreadConstraints() }}
{{ sub_schema_values.podSecurityContext(user_id=10007, group_id=10007) }}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/init-secrets.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/init-secrets.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rbac:
{{- sub_schema_values.extraInitContainers("Init Secrets") }}
{{- sub_schema_values.nodeSelector() -}}
{{- sub_schema_values.priorityClassName() -}}
{{- sub_schema_values.affinity() -}}
{{- sub_schema_values.podSecurityContext(user_id='10010', group_id='10010') -}}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='200Mi') -}}
{{- sub_schema_values.serviceAccount() -}}
Expand Down
6 changes: 6 additions & 0 deletions charts/matrix-stack/source/matrix-rtc.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down Expand Up @@ -213,6 +216,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
2 changes: 2 additions & 0 deletions charts/matrix-stack/source/matrix-rtc.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ replicas: 1
{{- sub_schema_values.extraInitContainers("Matrix RTC") }}
{{- sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{- sub_schema_values.podSecurityContext(user_id='10033', group_id='10033') }}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='200Mi') }}
{{- sub_schema_values.serviceMonitors() }}
Expand Down Expand Up @@ -92,6 +93,7 @@ sfu:
{{- sub_schema_values.containersSecurityContext() | indent(2) }}
{{- sub_schema_values.nodeSelector() | indent(2) }}
{{- sub_schema_values.priorityClassName() | indent(2) }}
{{- sub_schema_values.affinity() | indent(2) }}
{{- sub_schema_values.podSecurityContext(user_id='10030', group_id='10030') | indent(2) }}
{{- sub_schema_values.resources(requests_memory='150Mi', requests_cpu='100m', limits_memory='4Gi') | indent(2) }}
{{- sub_schema_values.serviceAccount() | indent(2) }}
Expand Down
6 changes: 6 additions & 0 deletions charts/matrix-stack/source/matrixAuthenticationService.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down Expand Up @@ -136,6 +139,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ privateKeys: {}
{{ sub_schema_values.serviceAccount() }}
{{ sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{ sub_schema_values.tolerations() }}
{{ sub_schema_values.hostAliases() }}
{{ sub_schema_values.topologySpreadConstraints() }}
Expand Down Expand Up @@ -70,6 +71,7 @@ syn2mas:
{{- sub_schema_values.containersSecurityContext() | indent(2) -}}
{{- sub_schema_values.nodeSelector() | indent(2) -}}
{{- sub_schema_values.priorityClassName() | indent(2) -}}
{{- sub_schema_values.affinity() | indent(2) -}}
{{- sub_schema_values.podSecurityContext(user_id='10005', group_id='10005') | indent(2) -}}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='350Mi') | indent(2) -}}
{{- sub_schema_values.serviceAccount() | indent(2) -}}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/postgres.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ essPasswords: {}
{{- sub_schema_values.containersSecurityContext() }}
{{- sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{- sub_schema_values.podSecurityContext(user_id='10091', group_id='10091') }}
{{- sub_schema_values.resources(requests_memory='100Mi', requests_cpu='100m', limits_memory='4Gi') }}
{{- sub_schema_values.serviceAccount() }}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/redis.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"podSecurityContext": {
"$ref": "file://common/podSecurityContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/redis.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ replicas: 1
{{- sub_schema_values.extraInitContainers("Redis") }}
{{- sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{- sub_schema_values.podSecurityContext(user_id='10002', group_id='10002') }}
{{- sub_schema_values.resources(requests_memory='50Mi', requests_cpu='50m', limits_memory='50Mi') }}
{{- sub_schema_values.serviceAccount() }}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/synapse.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"extraVolumes": {
"$ref": "file://common/extraVolumesWithContext.json"
},
Expand Down
1 change: 1 addition & 0 deletions charts/matrix-stack/source/synapse.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ replicas: 1
{{- sub_schema_values.hostAliases() }}
{{- sub_schema_values.nodeSelector() }}
{{- sub_schema_values.priorityClassName() }}
{{- sub_schema_values.affinity() }}
{{- sub_schema_values.podSecurityContext(user_id='10091', group_id='10091') }}
{{- sub_schema_values.resources(requests_memory='100Mi', requests_cpu='100m', limits_memory='4Gi') }}
{{- sub_schema_values.serviceAccount() }}
Expand Down
3 changes: 3 additions & 0 deletions charts/matrix-stack/source/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
"priorityClassName": {
"type": "string"
},
"affinity": {
"$ref": "file://common/affinity.json"
},
"clusterDomain": {
"type": "string"
},
Expand Down
30 changes: 30 additions & 0 deletions charts/matrix-stack/templates/ess-library/_pods.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ nodeSelector:
{{- with (coalesce .priorityClassName $root.Values.priorityClassName) }}
priorityClassName: {{ . }}
{{- end }}
{{- include "element-io.ess-library.pods.affinity" (dict "root" $root "context" (dict "affinity" .affinity)) }}
restartPolicy: {{ (eq $kind "Job") | ternary "Never" "Always" }}
{{- include "element-io.ess-library.pods.tolerations" (dict "root" $root "context" .tolerations) }}
{{- include "element-io.ess-library.pods.topologySpreadConstraints" (dict "root" $root "context" (dict "instanceSuffix" $instanceSuffix "deployment" (eq $kind "Deployment") "topologySpreadConstraints" .topologySpreadConstraints)) }}
Expand Down Expand Up @@ -103,6 +104,35 @@ topologySpreadConstraints:
{{- end }}
{{- end }}

{{- define "element-io.ess-library.pods.affinity" -}}
{{- $root := .root -}}
{{- with required "element-io.ess-library.pods.affinity missing context" .context -}}
{{- $componentAffinity := .affinity | default dict -}}
{{- $globalAffinity := $root.Values.affinity | default dict -}}
{{- $affinity := dict -}}
{{- /*
Each affinity type is resolved independently so that setting one type at a component level does not drop
the other types inherited from the global affinity. A component that sets an affinity type overrides only
that type; setting it to an empty value ({} or null) blanks out the inherited global value for that type.
*/ -}}
{{- range $affinityType := (list "nodeAffinity" "podAffinity" "podAntiAffinity") -}}
{{- if hasKey $componentAffinity $affinityType -}}
{{- with (get $componentAffinity $affinityType) -}}
{{- $_ := set $affinity $affinityType . -}}
{{- end -}}
{{- else -}}
{{- with (get $globalAffinity $affinityType) -}}
{{- $_ := set $affinity $affinityType . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- with $affinity }}
affinity:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end -}}
{{- end -}}

{{- /*
The only differences this has over (. | toYaml) are that
* it allows us to omit nullable values for individual properties
Expand Down
Loading