-
Notifications
You must be signed in to change notification settings - Fork 68
Add ability to configure custom init containers #1532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Oleksii Kurinnyi <[email protected]>
…erate_all Signed-off-by: Oleksii Kurinnyi <[email protected]>
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: akurinnoy The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
I tested with the steps provided in the PR description and can confirm it works as expected ✔️ |
Signed-off-by: Oleksii Kurinnyi <[email protected]>
Co-authored-by: Rohan Kumar <[email protected]> Signed-off-by: Oleksii Kurinnyi <[email protected]>
Co-authored-by: Rohan Kumar <[email protected]> Signed-off-by: Oleksii Kurinnyi <[email protected]>
Signed-off-by: Oleksii Kurinnyi <[email protected]>
2e3e20f to
1ff60c7
Compare
Signed-off-by: Oleksii Kurinnyi <[email protected]>
Signed-off-by: Oleksii Kurinnyi <[email protected]>
Signed-off-by: Oleksii Kurinnyi <[email protected]>
Signed-off-by: Oleksii Kurinnyi <[email protected]>
| // If the feature is disabled, setting this field may cause an endless workspace start loop. | ||
| // +kubebuilder:validation:Optional | ||
| HostUsers *bool `json:"hostUsers,omitempty"` | ||
| // InitContainers defines a list of Kubernetes init containers that are automatically injected into all workspace pods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // InitContainers defines a list of Kubernetes init containers that are automatically injected into all workspace pods. | |
| // InitContainers defines a list of Kubernetes init containers that are automatically added into all workspace pods. |
| HostUsers *bool `json:"hostUsers,omitempty"` | ||
| // InitContainers defines a list of Kubernetes init containers that are automatically injected into all workspace pods. | ||
| // Typical uses: injecting organization tools/configs, initializing persistent home, etc. | ||
| // Note: Only trusted administrators should be allowed to edit the DevWorkspaceOperatorConfig. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Note: Only trusted administrators should be allowed to edit the DevWorkspaceOperatorConfig. | |
| // Note: Only administrators should be allowed to edit the DevWorkspaceOperatorConfig. |
|
/retest |
|
@akurinnoy: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
| if len(c.Command) != 2 || c.Command[0] != "/bin/sh" || c.Command[1] != "-c" { | ||
| return fmt.Errorf("command must be exactly [/bin/sh, -c] for %s", constants.HomeInitComponentName) | ||
| } | ||
|
|
||
| if len(c.Args) != 1 { | ||
| return fmt.Errorf("args must contain exactly one script string for %s", constants.HomeInitComponentName) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why do we need to limit command and args?
|
|
||
| // validateNoAdvancedFields validates that the init-persistent-home container | ||
| // does not use advanced Kubernetes container fields that could make behavior unpredictable. | ||
| func validateNoAdvancedFields(c corev1.Container) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you share the documentation where those limitations come from?
| disableHomeInit := workspace.Config.Workspace.PersistUserHome.DisableInitContainer != nil && | ||
| *workspace.Config.Workspace.PersistUserHome.DisableInitContainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use pointer package
| if !home.PersistUserHomeEnabled(workspace) { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't take this clause into account
cc @dkwon17
| c.VolumeMounts = []corev1.VolumeMount{{ | ||
| Name: constants.HomeVolumeName, | ||
| MountPath: constants.HomeUserDirectory, | ||
| }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this to some utility class since it has been used twice so far.
| } | ||
| // Skip if init container is explicitly disabled | ||
| if disableHomeInit { | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's log some info here
| disableHomeInit := workspace.Config.Workspace.PersistUserHome.DisableInitContainer != nil && | ||
| *workspace.Config.Workspace.PersistUserHome.DisableInitContainer | ||
|
|
||
| for _, c := range workspace.Config.Workspace.InitContainers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a better readability?
| for _, c := range workspace.Config.Workspace.InitContainers { | |
| for _, container := range workspace.Config.Workspace.InitContainers { |
| continue | ||
| } | ||
| // Apply defaults and validation for init-persistent-home | ||
| validated, err := defaultAndValidateHomeInitContainer(c, workspace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, if we can do in this way, but can you check?
| validated, err := defaultAndValidateHomeInitContainer(c, workspace) | |
| container, err = defaultAndValidateHomeInitContainer(c, workspace) |
What does this PR do?
This PR adds the ability for cluster administrators to configure custom init containers that run in all workspace pods via the DWOC.
So, now administrators can:
config.workspace.initContainers.init-persistent-homelogic by providing a custom container with the same name.What issues does this PR fix or reference?
https://issues.redhat.com/browse/CRW-9373
https://issues.redhat.com/browse/CRW-9367
Is it tested? How?
Deploy the DevWorkspace Operator with these changes
Test 1: Custom init-persistent-home script execution
Apply a DWOC with a custom init container:
Create a test workspace and wait for it to start
Wait for workspace to run:
Verify the init container was injected:
POD_NAME=$(kubectl get pods -n $WORKSPACE_NAMESPACE -l controller.devfile.io/devworkspace_name=test1-custom-home -o jsonpath='{.items[0].metadata.name}')Verify marker file
Expected output
Verify config file
Expected output
Cleanup
kubectl delete devworkspace test1-custom-home -n $WORKSPACE_NAMESPACETest 2: Default init-persistent-home behavior
Reset DWOC to default (no custom init)
Create workspace with persistent home enabled
Wait for workspace to run:
Verify default
stowlogic still workskubectl logs -n $WORKSPACE_NAMESPACE -l controller.devfile.io/devworkspace_name=test2-backward-compat -c init-persistent-homeExpected output
Cleanup
kubectl delete devworkspace test2-backward-compat -n $WORKSPACE_NAMESPACETest 3: Validation of init-persistent-home configuration
Apply
DWOCwith invalid commandCreate workspace
Wait a few seconds for reconciliation
Verify workspace fails with validation error
Expected output
Expected output
Cleanup
kubectl delete devworkspace test3-invalid-command -n $WORKSPACE_NAMESPACETest 4: Multiple Custom Init Containers
Apply DWOC with multiple init containers
Create workspace
Wait for workspace to run:
Verify all init containers were injected and ran in order
POD_NAME=$(kubectl get pods -n $WORKSPACE_NAMESPACE -l controller.devfile.io/devworkspace_name=test4-multiple-init -o jsonpath='{.items[0].metadata.name}')Verify all 3 init containers are present
Expected output
Verify the sequence log shows all 3 steps
Expected output
Verify marker files from each init container
Expected output
Expected output
Cleanup
kubectl delete devworkspace test4-multiple-init -n $WORKSPACE_NAMESPACEPR Checklist
/test v8-devworkspace-operator-e2e, v8-che-happy-pathto trigger)v8-devworkspace-operator-e2e: DevWorkspace e2e testv8-che-happy-path: Happy path for verification integration with Che