Skip to content

Add automount functionality for PVCs #544

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

Merged
merged 6 commits into from
Aug 12, 2021
Merged

Conversation

amisevsk
Copy link
Collaborator

@amisevsk amisevsk commented Aug 9, 2021

What does this PR do?

Adds the ability to mount PVCs to all DevWorkspaces by applying the controller.devfile.io/mount-to-devworkspace label (similarly to configmaps/secrets). PVCs are mounted to the path specified by controller.devfile.io/mount-path, or /tmp/<claim-name> if annotation is not present.

PVCs can be mounted read-only (to support read-only-many volumes)

The first three commits in this PR are just moving stuff around to make things sensible:

  • Move controllers/workspace/provision to pkg/provision/workspace so that all "provisioning" code is in same place
  • Split controllers/workspace/env into pkg/provision/workspace and pkg/constants
  • Move automount-processing code into subpackage pkg/provision/workspace/automount

What issues does this PR fix or reference?

Closes #503

Is it tested? How?

Create a PVC on your cluster, e.g.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
  labels:
    controller.devfile.io/mount-to-devworkspace: "true"
  annotations:
    controller.devfile.io/mount-path: "/testing/"
    controller.devfile.io/read-only: "false" # Change to "true" to test read-only mounts 
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: standard
EOF

and create a DevWorkspace. PVC should be mounted to /testing

If mounted read-write, try creating a file there, stopping the current workspace, and creating a new one.

PR Checklist

  • E2E tests pass (when PR is ready, comment /test v7-devworkspaces-operator-e2e, v7-devworkspace-happy-path to trigger)
    • v7-devworkspaces-operator-e2e: DevWorkspace e2e test
    • v7-devworkspace-happy-path: DevWorkspace e2e test

Copy link
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

I haven't tested but changes seem to be pretty straightforward

"github.com/go-logr/logr"
coputil "github.com/redhat-cop/operator-utils/pkg/util"
corev1 "k8s.io/api/core/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/devfile/devworkspace-operator/pkg/provision/storage"
provision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
Copy link
Member

Choose a reason for hiding this comment

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

really minor. Maybe it makes sense to drop provision alias, or make it wsProvision to avoid confusion with provision/storage...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I had a bit of trouble with this since we're having some aliasing issues 😄

  • Can't use workspace as we name the DevWorkspace instance that
  • provision isn't ideal since it's completely unrelated to the package (as you point out)
  • workspaceprovision is too long

I think wsprovision makes sense. I'll update the PR -- do we want to settle on wsProvision or wsprovision? We kind of use both (k8serrors vs k8sErrors) but I think the standard is all-lowercase.

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with any

"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/config"
"github.com/devfile/devworkspace-operator/pkg/constants"
workspace2 "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
Copy link
Member

Choose a reason for hiding this comment

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

IDE's footprint is found

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 just wish it would warn me it was doing this 😄

Thanks for catching it.

@amisevsk
Copy link
Collaborator Author

/test v7-devworkspaces-operator-e2e, v7-devworkspace-happy-path

@openshift-ci
Copy link

openshift-ci bot commented Aug 11, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amisevsk, JPinkney, sleshchenko

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:
  • OWNERS [JPinkney,amisevsk,sleshchenko]

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

@openshift-ci
Copy link

openshift-ci bot commented Aug 12, 2021

New changes are detected. LGTM label has been removed.

Move all provisioning code (i.e. code that creates resources on-cluster)
to the same place

Signed-off-by: Angel Misevski <[email protected]>
Split common env var package to merge it into existing pkg/ structure:

* Constants (env var names) to pkg/constants/env.go
* Function providing common env vars to pkg/provision/workspace to sit
  alongside alongside where it's used.

Signed-off-by: Angel Misevski <[email protected]>
Since we're adding more features to automounting, it makes sense to move
functionality for getting configmaps/secrets/pvcs to a separate package
from workspace provisioning.

This commit splits the only large automount file into files for common
functionality, managing secrets, and managing configmaps

Signed-off-by: Angel Misevski <[email protected]>
Add ability to automatically mount PVCs to DevWorkspace pods based on
the automount label. Automounted PVCs require a mountPath specified via
the mount-path annotation.

Signed-off-by: Angel Misevski <[email protected]>
Add annotation 'controller.devfile.io/read-only' to enable automounting PVCs
with read-only access.

Signed-off-by: Angel Misevski <[email protected]>
This is a really annoying change to make, since
1. VS Code will remove "unused" imports and reimport the unaliased
   package name on save, *even* if you use find-replace
2. Goland will let you refactor the import alias, but will basically
   find-replace throughout the file to do so, meaning that "workspace"
   gets replaced with "wsprovision" *in comments*.

Signed-off-by: Angel Misevski <[email protected]>
@amisevsk
Copy link
Collaborator Author

/test v7-devworkspaces-operator-e2e, v7-devworkspace-happy-path

@openshift-ci
Copy link

openshift-ci bot commented Aug 12, 2021

@amisevsk: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Rerun command
ci/prow/v7-devworkspace-happy-path 449fd7f link /test v7-devworkspace-happy-path

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/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automount PVCs if they have labels similar to what we do for secrets/configmaps
3 participants