CRW-9373-run-77683332#17
Open
akurinnoy wants to merge 13 commits into
Open
Conversation
Document injection order, init-persistent-home override behavior (must use command: [/bin/sh, -c]), automatic image and volume mount inheritance for init-persistent-home, and explicit requirements for all other custom init containers.
Add isValidInitPersistentHomeCommand helper and command validation to EnsureHomeInitContainerFields. When Command is non-empty and not exactly [/bin/sh, -c], returns error: "Invalid init-persistent-home container: command must be exactly [/bin/sh, -c]". Empty Command still defaults to [/bin/sh, -c]. VolumeMounts always overwritten with persistent-home mount. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…-persistent-home) Add three new test cases to TestMergeInitContainers covering DWOC init container injection scenarios beyond init-persistent-home overrides: - Single custom DWOC container (custom-setup) is appended after the built-in init-persistent-home in the merged list - Multiple custom DWOC containers are appended in the order they appear in the DWOC spec - A DWOC container whose name matches an existing devfile-level init container is merged (fields overridden) rather than duplicated No production code changes — tests only. All eight test cases pass. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…5 | Tasks: 1, 5, 6]
…5 | Tasks: 1, 5, 6]
…5 | Tasks: 1, 5, 6]
…ContainerFields Extend EnsureHomeInitContainerFields to accept a workspace parameter and infer the init-persistent-home container image from the workspace's primary container when the DWOC spec does not specify an image. Non-empty DWOC images are preserved. Update the call site in devworkspace_controller.go accordingly. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…o prevent silent override Previously, EnsureHomeInitContainerFields validated c.Command but never reset c.Args, creating a silent-success path where a DWOC container with Command=[/bin/sh, -c] and custom Args could replace the initScript payload without any error or log. Now c.Args is always overwritten with initScript regardless of operator config, ensuring the init behavior cannot be silently replaced via strategic merge. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ommand validation Tests cover: no command (defaults to [/bin/sh, -c]), explicit valid command, invalid commands (/bin/bash, missing -c, extra args), and VolumeMounts overwrite. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add TestEnsureHomeInitContainerFieldsImageInheritance covering three scenarios: - init-persistent-home container with empty image gets image inferred from workspace primary container (InferWorkspaceImage) - init-persistent-home container with image already set preserves it unchanged - non-init-persistent-home container with image set also preserves it (function does not overwrite non-empty images) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for operator-level custom init containers that are injected into all workspace pods via the DevWorkspaceOperatorConfig (DWOC). It also introduces an override mechanism for the built-in
init-persistent-homeinit container, command validation, and image inheritance behavior.Feature Description
New field:
config.workspace.initContainersA new field
InitContainers []corev1.Containeris added toWorkspaceConfigin the DWOC. Any init containers defined here are automatically injected into every workspace pod before startup.Example DWOC configuration:
Pattern 1 — Generic init container injection
Any named init container defined in
config.workspace.initContainers(other thaninit-persistent-home) is merged into the workspace pod's init containers using Kubernetes strategic merge patch semantics (pkg/library/initcontainers/merge.go). This allows cluster administrators to inject tooling, configuration, or environment initialization into every workspace without modifying DevWorkspace definitions.Pattern 2 — Overriding
init-persistent-homeWhen an init container named
init-persistent-homeis present inconfig.workspace.initContainers, it overrides the default home-persistence init container behavior. This pattern enables custom home initialization scripts for ephemeral storage workspaces, or for replacing the built-in stow-based initialization entirely.The override is applied after the default init component is generated (if not disabled via
persistUserHome.disableInitContainer). The DWOC-supplied container fields are merged on top of the generated container using strategic merge patch.Ephemeral workspaces:
NeedsPersistentHomeDirectorynow returnstruefor ephemeral-storage workspaces wheninit-persistent-homeis present inconfig.workspace.initContainers, enabling consistent behavior between ephemeral and non-ephemeral workspaces when a custom init is configured.Key Behaviors
Command validation (
/bin/sh -crequirement)EnsureHomeInitContainerFieldsinpkg/library/home/persistentHome.goenforces that theinit-persistent-homecontainer uses["/bin/sh", "-c"]as its command if no command is already set. If the container already specifies a command, that value is preserved. This means an override container must either omitcommand(to accept the default) or provide a valid shell-compatible command.Image inheritance
When an
init-persistent-homeoverride is provided inconfig.workspace.initContainerswithout specifying an image, the image is inherited from the first non-imported container component in the workspace. This mirrors the behavior of the auto-generated init container (inferInitContainer) so that the override does not need to repeat the workspace image.Merge semantics
Init container merging (
pkg/library/initcontainers/merge.go) usesstrategicpatch.StrategicMergePatchover acorev1.PodSpecstructure withnameas the merge key. Containers matching by name in the DWOC are merged field-by-field into the base set; new containers are appended. Order is preserved: base containers come first in their original order, then new containers from the DWOC in their original order.Backward Compatibility
Backward compatibility is preserved. All changes are additive:
config.workspace.initContainersis empty or absent, behavior is identical to previous releases.init-persistent-homeinit container injection behavior is unchanged when no override is present in the DWOC.persistUserHome.disableInitContainerfield continues to work as before.Changed Files
apis/controller/v1alpha1/devworkspaceoperatorconfig_types.goInitContainers []corev1.Containerfield toWorkspaceConfig; updated godocpkg/library/home/persistentHome.goEnsureHomeInitContainerFields,hasInitPersistentHomeInConfig; updatedNeedsPersistentHomeDirectoryfor ephemeral storagepkg/library/initcontainers/merge.gocontrollers/workspace/devworkspace_controller.gopkg/library/home/custom_init_test.goAddPersistentHomeVolume,InferWorkspaceImage, custom init behaviortest/e2e/pkg/tests/custom_init_container_tests.goTest Plan
pkg/library/homecover:persistUserHome.enabled=truedisableInitContainer=trueEnsureHomeInitContainerFieldssets["/bin/sh", "-c"]command when none is providedEnsureHomeInitContainerFieldspreserves existing commandhasInitPersistentHomeInConfigreturns true/false correctlypkg/library/initcontainerscover:test/e2e/pkg/tests/custom_init_container_tests.gocover:init-persistent-homeoverride replaces default behaviorgo build ./...— no compilation errorsgo test ./pkg/library/... ./pkg/provision/... ./webhook/...— all tests pass