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
2 changes: 1 addition & 1 deletion charts/mageai/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.16
version: 0.2.17
21 changes: 17 additions & 4 deletions charts/mageai/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{{- if not .Values.standaloneScheduler }}
{{- $hpa := .Values.hpa | default dict }}
{{- $serverReplicas := max .Values.replicaCount ($hpa.maxReplicas | default .Values.replicaCount) }}
{{- $redisConfigured := or .Values.redis.enabled .Values.redis.customRedisURL }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -11,6 +14,10 @@ metadata:
{{- include "mageai.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
{{- if and (eq (int $serverReplicas) 1) (not $redisConfigured) }}
strategy:
type: Recreate
{{- end }}
selector:
matchLabels:
{{- include "mageai.selectorLabels" . | nindent 6 }}
Expand Down Expand Up @@ -113,10 +120,10 @@ spec:
name: {{ include "mageai.secretName" . }}
{{- end }}
env:
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 12 }}
{{- else if .Values.extraEnvs }}
{{- toYaml .Values.extraEnvs | nindent 12 }}
{{- range (.Values.env | default .Values.extraEnvs) }}
{{- if and (ne .name "MAGE_SERVER_REPLICAS") (or (not $redisConfigured) (ne .name "MAGE_PRESENCE_REQUIRE_SHARED_REDIS")) }}
{{- toYaml (list .) | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.redis.enabled }}
- name: REDIS_URL
Expand Down Expand Up @@ -160,6 +167,12 @@ spec:
name: {{ .Values.logSearch.opensearch.auth.existingSecret }}
key: OPENSEARCH_PASSWORD
{{- end }}
{{- end }}
- name: MAGE_SERVER_REPLICAS
value: {{ $serverReplicas | quote }}
{{- if $redisConfigured }}
- name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"
{{- end }}
volumeMounts:
{{- include "mageai.projectVolumeMounts" . | nindent 12 }}
Expand Down
21 changes: 17 additions & 4 deletions charts/mageai/templates/webservice.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{{- if .Values.standaloneScheduler }}
{{- $hpa := .Values.webServer.hpa | default dict }}
{{- $serverReplicas := max .Values.webServer.replicaCount ($hpa.maxReplicas | default .Values.webServer.replicaCount) }}
{{- $redisConfigured := or .Values.redis.enabled .Values.redis.customRedisURL }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -7,6 +10,10 @@ metadata:
{{- include "mageai.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.webServer.replicaCount }}
{{- if and (eq (int $serverReplicas) 1) (not $redisConfigured) }}
strategy:
type: Recreate
{{- end }}
selector:
matchLabels:
{{- include "mageai.selectorLabels" . | nindent 6 }}
Expand Down Expand Up @@ -104,10 +111,10 @@ spec:
name: {{ include "mageai.secretName" . }}
{{- end }}
env:
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 12 }}
{{- else if .Values.extraEnvs }}
{{- toYaml .Values.extraEnvs | nindent 12 }}
{{- range (.Values.env | default .Values.extraEnvs) }}
{{- if and (ne .name "MAGE_SERVER_REPLICAS") (or (not $redisConfigured) (ne .name "MAGE_PRESENCE_REQUIRE_SHARED_REDIS")) }}
{{- toYaml (list .) | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.redis.enabled }}
- name: REDIS_URL
Expand Down Expand Up @@ -153,6 +160,12 @@ spec:
name: {{ .Values.logSearch.opensearch.auth.existingSecret }}
key: OPENSEARCH_PASSWORD
{{- end }}
{{- end }}
- name: MAGE_SERVER_REPLICAS
value: {{ $serverReplicas | quote }}
{{- if $redisConfigured }}
- name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"
{{- end }}
volumeMounts:
{{- include "mageai.projectVolumeMounts" . | nindent 12 }}
Expand Down
234 changes: 234 additions & 0 deletions charts/mageai/tests/deployment_presence_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
suite: editor presence deployment safety
templates:
- templates/deployment.yaml
- templates/webservice.yaml
- templates/scheduler.yaml

tests:
- it: recreates the default Redis-free editor before starting its replacement
template: templates/deployment.yaml
asserts:
- equal:
path: spec.strategy.type
value: Recreate
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "1"

- it: exposes multiple combined editor replicas without Redis
template: templates/deployment.yaml
set:
replicaCount: 2
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "2"

- it: uses the split editor count independently of scheduler and combined counts
template: templates/webservice.yaml
set:
standaloneScheduler: true
replicaCount: 5
scheduler.replicaCount: 4
webServer.replicaCount: 1
extraEnvs:
- name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"
asserts:
- equal:
path: spec.replicas
value: 1
- equal:
path: spec.strategy.type
value: Recreate
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "1"
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"

- it: exposes multiple split editor replicas without Redis
template: templates/webservice.yaml
set:
standaloneScheduler: true
webServer.replicaCount: 2
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "2"

- it: preserves rolling upgrades with bundled Redis
template: templates/deployment.yaml
set:
redis.enabled: true
extraEnvs:
- name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "false"
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "1"
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"
- notContains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "false"
- isNull:
path: spec.template.spec.containers[0].env[3]

- it: preserves rolling upgrades with external Redis
template: templates/deployment.yaml
set:
redis.customRedisURL: redis://shared-redis:6379/0
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"

- it: preserves split editor rolling upgrades with bundled Redis
template: templates/webservice.yaml
set:
standaloneScheduler: true
redis.enabled: true
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"

- it: preserves split editor rolling upgrades with external Redis
template: templates/webservice.yaml
set:
standaloneScheduler: true
redis.customRedisURL: redis://shared-redis:6379/0
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_PRESENCE_REQUIRE_SHARED_REDIS
value: "true"

- it: requires shared presence when the combined editor can autoscale
template: templates/deployment.yaml
set:
hpa.minReplicas: 1
hpa.maxReplicas: 3
hpa.targetCPUUtilizationPercentage: 80
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "3"

- it: uses only the split editor autoscaling maximum
template: templates/webservice.yaml
set:
standaloneScheduler: true
scheduler.hpa.maxReplicas: 8
webServer.hpa.minReplicas: 1
webServer.hpa.maxReplicas: 3
webServer.hpa.targetCPUUtilizationPercentage: 80
asserts:
- isNull:
path: spec.strategy
- contains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "3"

- it: prevents extraEnvs from understating the editor count
template: templates/deployment.yaml
set:
replicaCount: 2
config.MAGE_SERVER_REPLICAS: "1"
extraEnvs:
- name: MAGE_SERVER_REPLICAS
value: "1"
- name: KEEP_ME
value: kept
asserts:
- equal:
path: spec.template.spec.containers[0].env
value:
- name: KEEP_ME
value: kept
- name: MAGE_SERVER_REPLICAS
value: "2"

- it: preserves legacy env precedence while preventing a split replica override
template: templates/webservice.yaml
set:
standaloneScheduler: true
webServer.replicaCount: 2
env:
- name: MAGE_SERVER_REPLICAS
value: "1"
- name: KEEP_ME
value: legacy
extraEnvs:
- name: KEEP_ME
value: ignored
asserts:
- equal:
path: spec.template.spec.containers[0].env
value:
- name: KEEP_ME
value: legacy
- name: INSTANCE_TYPE
value: web_server
- name: MAGE_SERVER_REPLICAS
value: "2"

- it: keeps scheduler deployments outside the editor replica contract
template: templates/scheduler.yaml
set:
standaloneScheduler: true
scheduler.replicaCount: 4
asserts:
- equal:
path: spec.replicas
value: 4
- isNull:
path: spec.strategy
- notContains:
path: spec.template.spec.containers[0].env
content:
name: MAGE_SERVER_REPLICAS
value: "4"
Loading