Skip to content
Merged
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
19 changes: 13 additions & 6 deletions helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ helm install weknora ./helm \

The chart-created data-files PVC uses `ReadWriteOnce` (RWO). RWO allows several
Pods to mount the volume on the same node; it does not provide shared writable
access across nodes. With a single-node-attach volume, the default rolling update
(`maxSurge: 1`, `maxUnavailable: 0`) can leave a replacement Pod waiting for the
old Pod's attachment to be released. `Recreate` terminates the old Pods before
starting replacements during an upgrade, so **App upgrades have downtime**;
volume detach/attach can still take time. This strategy does not make RWO storage
access across nodes. When `app.strategy.type` is omitted, the chart detects this
single-writer storage and defaults to `Recreate`, which terminates the old Pods
before starting replacements. **App upgrades have downtime**; volume
detach/attach can still take time. This strategy does not make RWO storage
suitable for multiple App replicas across nodes. See Kubernetes documentation on
[access modes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)
and [Deployment strategies](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy).
Expand Down Expand Up @@ -252,7 +251,7 @@ pre-existing Service name does not automatically transfer its ownership to Helm.
|-----------|-------------|---------|
| `app.enabled` | Enable backend | `true` |
| `app.replicaCount` | Number of replicas | `1` |
| `app.strategy.type` | App update strategy: `RollingUpdate` or `Recreate` | `RollingUpdate` |
| `app.strategy.type` | App update strategy: `RollingUpdate` or `Recreate`; empty selects `Recreate` for persistent non-RWX data-files storage and `RollingUpdate` otherwise | `""` |
| `app.strategy.rollingUpdate.maxSurge` | Extra Pods during rolling updates (integer or percentage); ignored with `Recreate` | `1` |
| `app.strategy.rollingUpdate.maxUnavailable` | Unavailable Pods during rolling updates (integer or percentage); ignored with `Recreate` | `0` |
| `app.image.repository` | Image repository | `wechatopenai/weknora-app` |
Expand All @@ -261,6 +260,14 @@ pre-existing Service name does not automatically transfer its ownership to Helm.
| `app.env` | Environment variables | See values.yaml |
| `app.extraEnv` | Additional env vars | `[]` |

### Data Files Storage

| Parameter | Description | Default |
|-----------|-------------|---------|
| `dataFiles.persistence.enabled` | Create or mount persistent uploaded-file storage | `true` |
| `dataFiles.persistence.accessModes` | Access modes for a chart-created data-files PVC; `ReadWriteMany` permits rolling App updates | `[ReadWriteOnce]` |
| `dataFiles.persistence.existingClaim` | Use a pre-provisioned PVC instead of creating one | `""` |

### Frontend

| Parameter | Description | Default |
Expand Down
7 changes: 6 additions & 1 deletion helm/templates/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ spec:
{{- include "weknora.componentSelectorLabels" (dict "component" "app" "context" .) | nindent 6 }}
strategy:
{{- $strategy := .Values.app.strategy | default dict }}
{{- $strategyType := $strategy.type | default "RollingUpdate" }}
{{- $accessModes := .Values.dataFiles.persistence.accessModes | default (list "ReadWriteOnce") }}
{{- $defaultStrategyType := "RollingUpdate" }}
{{- if and .Values.dataFiles.persistence.enabled (not (has "ReadWriteMany" $accessModes)) }}
{{- $defaultStrategyType = "Recreate" }}
{{- end }}
{{- $strategyType := $strategy.type | default $defaultStrategyType }}
{{- if not (has $strategyType (list "RollingUpdate" "Recreate")) }}
{{- fail "app.strategy.type must be RollingUpdate or Recreate" }}
{{- end }}
Expand Down
28 changes: 23 additions & 5 deletions helm/tests/test_app_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,29 @@ def readme_values(self, filename):
return yaml.safe_load(next(block for block in blocks
if block.startswith(f"# {filename}\n")))

def test_default_strategy_is_unchanged(self):
def test_persistent_single_writer_storage_defaults_to_recreate(self):
app = self.app(self.documents())
self.assertEqual(app["spec"]["strategy"], {
"type": "Recreate",
})

def test_nonpersistent_storage_defaults_to_rolling_update(self):
app = self.app(self.documents({"dataFiles": {"persistence": {"enabled": False}}}))
self.assertEqual(app["spec"]["strategy"], {
"type": "RollingUpdate",
"rollingUpdate": {"maxSurge": 1, "maxUnavailable": 0},
})

def test_shared_storage_defaults_to_rolling_update(self):
app = self.app(self.documents({"dataFiles": {"persistence": {
"accessModes": ["ReadWriteMany"],
}}}))
self.assertEqual(app["spec"]["strategy"]["type"], "RollingUpdate")

def test_explicit_rolling_update_overrides_safe_default(self):
app = self.app(self.documents({"app": {"strategy": {
"type": "RollingUpdate",
}}}))
self.assertEqual(app["spec"]["strategy"], {
"type": "RollingUpdate",
"rollingUpdate": {"maxSurge": 1, "maxUnavailable": 0},
Expand All @@ -78,10 +99,7 @@ def test_custom_rolling_update_preserves_zero_and_percentage(self):

def test_null_strategy_falls_back_to_defaults(self):
app = self.app(self.documents({"app": {"strategy": None}}))
self.assertEqual(app["spec"]["strategy"], {
"type": "RollingUpdate",
"rollingUpdate": {"maxSurge": 1, "maxUnavailable": 0},
})
self.assertEqual(app["spec"]["strategy"], {"type": "Recreate"})

def test_invalid_strategy_is_rejected(self):
result = render({"app": {"strategy": {"type": "Invalid"}}})
Expand Down
11 changes: 5 additions & 6 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ app:
# -- Number of replicas
replicaCount: 1

# -- App update strategy. `RollingUpdate` needs storage that can be attached
# by two Pods at once: with the default `ReadWriteOnce` `data-files` claim an
# upgrade fails with `Multi-Attach error` unless this is `Recreate`. Set
# `dataFiles.persistence.accessModes` to `ReadWriteMany` to keep rolling
# updates with more than one replica.
# -- App update strategy. Leave empty to select a safe default from the
# data-files storage: `Recreate` for a persistent single-writer claim, and
# `RollingUpdate` when persistence is disabled or `ReadWriteMany` is used.
# Set this explicitly to override the derived strategy.
strategy:
type: RollingUpdate
type: ""
# -- Only used with RollingUpdate; integers and percentages are supported.
rollingUpdate:
maxSurge: 1
Expand Down
Loading