feat: add ability to configure custom init containers in DevWorkspace pods#20
Open
akurinnoy wants to merge 12 commits into
Open
feat: add ability to configure custom init containers in DevWorkspace pods#20akurinnoy wants to merge 12 commits into
akurinnoy wants to merge 12 commits into
Conversation
Adds a new 'DWOC init containers' Context block to devworkspace_controller_test.go with three It() cases: basic custom init injection, init-persistent-home override when persistent home is enabled, and skipping init-persistent-home when disabled. Adds a minimal supporting fixture YAML for the new tests. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The comment claimed the default init container was skipped when custom init containers were present, but the code only checks DisableInitContainer. Update the comment to accurately reflect the actual condition. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…itContainerFields - Add isValidInitPersistentHomeCommand helper that returns true only when cmd equals ["/bin/sh", "-c"] - Fix EnsureHomeInitContainerFields to validate non-empty Command via isValidInitPersistentHomeCommand, returning an error for invalid commands - Fix EnsureHomeInitContainerFields to use append-if-absent pattern for VolumeMounts instead of replacing the entire slice, preserving pre-existing mounts with other names Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ner in reconcile loop Add nil check for workspace.Config.Workspace.PersistUserHome before calling pointer.BoolDeref on PersistUserHome.DisableInitContainer to prevent a nil pointer panic when PersistUserHome is not configured. Default disableHomeInit to constants.DefaultDisableHomeInitContainer and only override inside the nil-guarded block. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…/3 | Tasks: T1, T2, T3]
…/3 | Tasks: T1, T2, T3]
Add 4 new test cases to TestMergeInitContainers covering: - nil base returns patches as result (no panic) - patch overrides image while preserving args (strategic merge) - new-named patch containers appended after base containers in patch order - mixed case: base [A,B] + patches [B-override,C] = [A,B-merged,C] Total test count: 9 (5 existing + 4 new). All pass with go vet clean. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ontainersFullFlow Implements table-driven tests for EnsureHomeInitContainerFields covering: - valid command [/bin/sh, -c]: no error, volumeMount added - invalid command [/bin/bash, -c]: returns error with exact message - empty command: set to [/bin/sh, -c], volumeMount added - idempotency test: container with existing persistent-home AND my-secret VolumeMount — asserts no duplicate persistent-home AND my-secret preserved Also implements TestDWOCMultipleInitContainersFullFlow which constructs a DevWorkspaceWithConfig with multiple DWOC initContainers (one init-persistent-home override + one extra-init), calls MergeInitContainers and EnsureHomeInitContainerFields, and verifies correct ordering, persistent-home VolumeMount presence, and custom container preservation. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add three new fixture files for TestPersistentHomeVolume covering: - DWOC with init-persistent-home initContainers (non-ephemeral, default init added) - Ephemeral workspace with init-persistent-home in DWOC (NeedsPersistentHomeDirectory=true) - No DWOC initContainers (backward compat, default stow behavior preserved) Test count increases from 12 to 15. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…/3 | Tasks: T4, T5, T6]
…/3 | Tasks: T4, T5, T6]
…/3 | Tasks: T4, T5, T6]
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
Implements the ability for platform administrators to configure custom init containers via the
DevWorkspaceOperatorConfig(DWOC) API fieldconfig.workspace.initContainers(CRW-9373, CRW-9367).DWOC API Field
Administrators set
config.workspace.initContainersin the DWOC CR. Each listed container is injected as an init container in every workspace pod, running in the specified order.init-persistent-home Override
If a container in
initContainershasname: init-persistent-home, it overrides the default operator-generated home init container:stow-based home initialization is replaced by the custom containerpersistent-home) automaticallyargsand optionallycommandneed to be specified; other fields are inheritedValidation: If the custom
init-persistent-homecontainer specifies acommandother than["/bin/sh", "-c"], the workspace fails with:Backward Compatibility
When
config.workspace.initContainersis nil or empty, existing workspace behavior is completely unchanged — the defaultstow-based home initialization runs as before.Changes
pkg/library/home/persistentHome.goisValidInitPersistentHomeCommandvalidation; fixedEnsureHomeInitContainerFieldsto use append-if-absent for VolumeMounts (not destructive replacement)pkg/library/initcontainers/merge.goMergeInitContainers— strategic merge of DWOC init containers with operator-generated onescontrollers/workspace/devworkspace_controller.goPersistUserHomebefore dereferencingDisableInitContainerpkg/library/home/custom_init_test.goTestEnsureHomeInitContainerFields,TestDWOCMultipleInitContainersFullFlowpkg/library/home/testdata/persistent-home/*.yamlTestPersistentHomeVolumepkg/library/initcontainers/merge_test.gocontrollers/workspace/devworkspace_controller_test.goCloses CRW-9373, CRW-9367