You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnr.failWorkspace(workspace, fmt.Sprintf("Failed to mount ServiceAccount tokens to workspace: %s", err), metrics.ReasonBadRequest, reqLogger, &reconcileStatus), nil
Copy file name to clipboardExpand all lines: docs/dwo-configuration.md
+80Lines changed: 80 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,3 +125,83 @@ config:
125
125
```
126
126
127
127
The config above will have newly created PVCs to have its access mode set to `ReadWriteMany`.
128
+
129
+
## Configuring Custom Init Containers
130
+
131
+
The DevWorkspace Operator allows cluster administrators to inject custom init containers into all workspace pods via the `config.workspace.initContainers` field in the global DWOC. This feature enables use cases such as:
132
+
133
+
- Injecting organization-specific tools or configurations
134
+
- Customizing the persistent home directory initialization logic
135
+
- Extracting cluster utilities (e.g., `oc` CLI) to ensure version compatibility
136
+
137
+
**Security Note:** Only trusted administrators should have RBAC permissions to edit the `DevWorkspaceOperatorConfig`, as custom init containers run in every workspace and can execute arbitrary code.
A specially-named init container `init-persistent-home` can be used to override the built-in persistent home directory initialization logic when `config.workspace.persistUserHome.enabled: true`. This is useful for enterprises using customized UDI images that require different home directory setup logic.
165
+
166
+
**Contract for `init-persistent-home`:**
167
+
168
+
- **Name:** Must be exactly `init-persistent-home`
169
+
- **Image:** Optional. If omitted, defaults to the first non-imported workspace container's image. If no suitable image can be inferred, the workspace will fail to start with an error.
170
+
- **Command:** Optional. If omitted, defaults to `["/bin/sh", "-c"]`. If provided, must exactly match this value.
171
+
- **Args:** Required. Must contain exactly one string with the initialization script.
172
+
- **VolumeMounts:** Forbidden. The operator automatically mounts the `persistent-home` volume at `/home/user/`.
173
+
- **Env:** Optional. Environment variables are allowed.
174
+
- **Other fields:** Not allowed. Fields such as `ports`, `probes`, `lifecycle`, `securityContext`, `resources`, `volumeDevices`, `stdin`, `tty`, and `workingDir` are rejected to keep behavior predictable.
175
+
176
+
**Note:** If `persistUserHome.enabled` is `false`, any `init-persistent-home` container is ignored.
177
+
178
+
### Example: Custom Persistent Home Initialization
179
+
180
+
```yaml
181
+
apiVersion: controller.devfile.io/v1alpha1
182
+
kind: DevWorkspaceOperatorConfig
183
+
metadata:
184
+
name: devworkspace-operator-config
185
+
namespace: $OPERATOR_INSTALL_NAMESPACE
186
+
config:
187
+
workspace:
188
+
persistUserHome:
189
+
enabled: true
190
+
initContainers:
191
+
- name: init-persistent-home
192
+
# image: optional - defaults to workspace image
193
+
# command: optional - defaults to ["/bin/sh", "-c"]
194
+
args:
195
+
- |
196
+
echo "Enterprise home init"
197
+
# Custom logic for enterprise UDI
198
+
rsync -a --ignore-existing /home/tooling/ /home/user/ || true
199
+
touch /home/user/.home_initialized
200
+
env:
201
+
- name: CUSTOM_VAR
202
+
value: "custom-value"
203
+
```
204
+
205
+
### Execution Order
206
+
207
+
Custom init containers are injected after the project-clone init container in the order they are defined in the configuration. The `init-persistent-home` container runs in this sequence along with other custom init containers.
// Add default init container only if not disabled and no custom init is configured
77
+
if (workspace.Config.Workspace.PersistUserHome.DisableInitContainer==nil||!*workspace.Config.Workspace.PersistUserHome.DisableInitContainer) &&!hasCustomHomeInit {
66
78
err:=addInitContainer(dwTemplateSpecCopy)
67
79
iferr!=nil {
68
80
returnnil, fmt.Errorf("failed to add init container for home persistence setup: %w", err)
0 commit comments