Skip to content
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

Disable automount resources for the init-container-home init container #1273

Merged
merged 2 commits into from
Jun 24, 2024

Conversation

dkwon17
Copy link
Collaborator

@dkwon17 dkwon17 commented Jun 11, 2024

What does this PR do?

Disable automount resources for the init-persistent-home initcontainer (an not the other initcontainers) if persistent home is enabled.

What issues does this PR fix or reference?

#1257

Is it tested? How?

  1. Deploy DWO:
export DWO_IMG=quay.io/dkwon17/devworkspace-controller:init-container-mount
make install
  1. In the DWOC named devworkspace-operator-config, enable persistent storage.
apiVersion: controller.devfile.io/v1alpha1
kind: DevWorkspaceOperatorConfig
metadata:
  name: devworkspace-operator-config
  namespace: eclipse-che
config:
  workspace:
    persistUserHome:
      enabled: true
  1. Create a configmap that mounts to any directory:
kind: ConfigMap
apiVersion: v1
metadata:
  name: storageconf
  labels:
    controller.devfile.io/mount-to-devworkspace: 'true'
    controller.devfile.io/watch-configmap: 'true'
  annotations:
    controller.devfile.io/mount-as: subpath
    controller.devfile.io/mount-path: /home/user/.config/containers
data:
  storage.conf: test1234
  1. Create a workspace and wait for it to start:
oc apply -f ./samples/code-latest.yaml
  1. Verify that the first initcontainer is init-persistent-home, and that the configmap is mounted in all containers except for init-persistent-home:
$ oc get pod <pod name> -o jsonpath='{.spec.initContainers[0].name}'
init-persistent-home

$ oc get pod <pod name> -o jsonpath='{.spec.initContainers[0].volumeMounts}' | grep storageconf
// no match exists

$ oc get pod <pod name> -o jsonpath='{.spec.initContainers[1].volumeMounts}' | grep storageconf
// match exists

$ oc get pod <pod name> -o jsonpath='{.spec.initContainers[2].volumeMounts}' | grep storageconf
// match exists

$ oc get pod <pod name> -o jsonpath='{.spec.containers[*].volumeMounts}' | grep storageconf
// match exists
  1. Verify that stow has run successfully in the dev container:
sh-4.4$ cat ~/.stow.log | tail -n 10 
LINK: go/pkg/mod/mvdan.cc/xurls/[email protected]/xurls_test.go => ../../../../../../../tooling/go/pkg/mod/mvdan.cc/xurls/[email protected]/xurls_test.go
    level of go/pkg/sumdb is 2
MKDIR: go/pkg/sumdb
    level of go/pkg/sumdb/sum.golang.org is 3
MKDIR: go/pkg/sumdb/sum.golang.org
    level of go/pkg/sumdb/sum.golang.org/latest is 4
LINK: go/pkg/sumdb/sum.golang.org/latest => ../../../../../tooling/go/pkg/sumdb/sum.golang.org/latest
Planning stow of package .... done
Processing tasks...
Processing tasks... done

PR Checklist

  • E2E tests pass (when PR is ready, comment /test v8-devworkspace-operator-e2e, v8-che-happy-path to trigger)
    • v8-devworkspace-operator-e2e: DevWorkspace e2e test
    • v8-che-happy-path: Happy path for verification integration with Che

Copy link

openshift-ci bot commented Jun 11, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@dkwon17 dkwon17 force-pushed the init-container-mount branch from cd920bc to 1a5164c Compare June 12, 2024 19:21
@dkwon17 dkwon17 marked this pull request as ready for review June 12, 2024 19:24
@dkwon17 dkwon17 requested review from AObuchow and ibuziuk as code owners June 12, 2024 19:24
@dkwon17
Copy link
Collaborator Author

dkwon17 commented Jun 12, 2024

Hello @AObuchow could you please take a look? I just want to make sure the code is OK before I add new tests

}
}
return initContainers
}
Copy link
Collaborator Author

@dkwon17 dkwon17 Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the init-persistent-home initcontainer to the front is necessary because if there is another initcontainer that runs before it, the automount resource can mount within /home/user and cause stow conflicts in init-persistent-home since the mounted configmap file would be saved in the PVC.

Basically, this function is here to have a way to ensure that init-persistent-home is the first initcontainer that runs, running before initcontainers like che-code-injector and project-clone

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification, makes sense to me. It's probably worth leaving a similar comment explaining this in the code.

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.

Project coverage is 52.84%. Comparing base (adc8b5a) to head (1a5164c).
Report is 26 commits behind head on main.

Current head 1a5164c differs from pull request most recent head f83b0ba

Please upload reports for the commit f83b0ba to get more accurate results.

Files Patch % Lines
pkg/library/lifecycle/prestart.go 50.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1273      +/-   ##
==========================================
+ Coverage   52.52%   52.84%   +0.32%     
==========================================
  Files          84       84              
  Lines        7642     7864     +222     
==========================================
+ Hits         4014     4156     +142     
- Misses       3335     3408      +73     
- Partials      293      300       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@AObuchow AObuchow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkwon17 looks great to me so far :) I think you're good to go ahead and add tests 🙏

pkg/provision/automount/common.go Outdated Show resolved Hide resolved
@AObuchow
Copy link
Collaborator

@dkwon17 In the testing instructions, you said to grep for my-settings instead of storageconf: oc get pod <pod name> -o jsonpath='{.spec.containers[*].volumeMounts}' | grep my-settings. Was that intentional?

@dkwon17
Copy link
Collaborator Author

dkwon17 commented Jun 19, 2024

@AObuchow sorry that was a mistake, it should be storageconf

Copy link
Collaborator

@AObuchow AObuchow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on OpenShift 4.15 & works as expected.

Looks good to me in its current state. Left some minor comments for consideration, but they are just suggestions. Great work @dkwon17 🥳!

pkg/library/lifecycle/prestart.go Outdated Show resolved Hide resolved
cmp.Diff(tt.Output.EnvFrom, container.EnvFrom, testDiffOpts))
}

for _, container := range podAdditions.InitContainers {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat redundant since it's already implicitly being checked in the preStart event test, but we could also explicitly check that the first container in the podAdditions.initContainers[] is the init-persistent-home initContainer (since this is a change introduced in this PR).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to do that check here because the function that the this test is for:

err := ProvisionAutoMountResourcesInto(podAdditions, testAPI, testNamespace, true)

doesn't reorder the initcontainers

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, makes sense 👍

pkg/library/lifecycle/prestart.go Show resolved Hide resolved
@AObuchow
Copy link
Collaborator

@dkwon17 also before merging please squash your fixup commits & mention in the "Add test" commit that the tests are related to automount functionality with home persistence.

@dkwon17 dkwon17 force-pushed the init-container-mount branch from d804278 to 9874cd4 Compare June 21, 2024 19:32
@openshift-ci openshift-ci bot removed the lgtm label Jun 21, 2024
dkwon17 added 2 commits June 21, 2024 15:41
…tainer if persistent home is enabled

Fix devfile#1257

Disabling automount resources for the init-persistent-home initconatiner
is done to avoid possible stow conflicts which can be introduced by
automount resources.

Signed-off-by: David Kwon <[email protected]>
@dkwon17 dkwon17 force-pushed the init-container-mount branch from 9874cd4 to f83b0ba Compare June 21, 2024 19:41
Copy link
Collaborator

@AObuchow AObuchow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Great job @dkwon17 :)

@openshift-ci openshift-ci bot added the lgtm label Jun 24, 2024
Copy link

openshift-ci bot commented Jun 24, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AObuchow, dkwon17, ibuziuk

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dkwon17 dkwon17 merged commit fb3a8fe into devfile:main Jun 24, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants