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

configurable default Workspace Spec Template #867

Merged
merged 2 commits into from
Jun 23, 2022

Conversation

AObuchow
Copy link
Collaborator

This PR adds a new CRD configuration option defaultTemplate to DWO. The configuration option takes in a DevWorkspaceTemplateSpecContent which gets applied to the workspace's devfile if the devfile does not define any components. Currently, the DevWorkspaceTemplateSpecContent will overwrite the devfile's existing template spec but keep the existing projects (if they were defined).

What issues does this PR fix or reference?

Fix #853

Is it tested? How?

  1. Create a minimal devfile, such as the following:
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: minimal
spec:
  started: true
  1. Start up DWO
  2. Edit the DWO config custom resource kubectl edit dwoc -n $NAMESPACE
  3. Add the defaultTemplate to the workspace attribute:
    defaultTemplate:
      commands:
      - exec:
          commandLine: echo "Hello from $(pwd)"
          component: theia-ide
          workingDir: ${PROJECTS_ROOT}/project/app
        id: say-hello
      components:
      - name: theia
        plugin:
          components:
          - container:
              env:
              - name: THEIA_HOST
                value: 0.0.0.0
            name: theia-ide
          uri: https://che-plugin-registry-main.surge.sh/v3/plugins/eclipse/che-theia/next/devfile.yaml
      projects:
      - git:
          remotes:
            origin: https://github.com/che-samples/web-nodejs-sample.git
        name: web-nodejs-sample

The resulting DWO configuration should ressemble something like the following:

apiVersion: controller.devfile.io/v1alpha1
config:
  routing:
    clusterHostSuffix: 192.168.39.217.nip.io
    defaultRoutingClass: basic
  workspace:
    defaultTemplate:
      commands:
      - exec:
          commandLine: echo "Hello from $(pwd)"
          component: theia-ide
          workingDir: ${PROJECTS_ROOT}/project/app
        id: say-hello
      components:
      - name: theia
        plugin:
          components:
          - container:
              env:
              - name: THEIA_HOST
                value: 0.0.0.0
            name: theia-ide
          uri: https://che-plugin-registry-main.surge.sh/v3/plugins/eclipse/che-theia/next/devfile.yaml
      projects:
      - git:
          remotes:
            origin: https://github.com/che-samples/web-nodejs-sample.git
        name: web-nodejs-sample
    imagePullPolicy: Always
kind: DevWorkspaceOperatorConfig
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"controller.devfile.io/v1alpha1","config":{"routing":{"clusterHostSuffix":"192.168.39.217.nip.io","defaultRoutingClass":"basic"},"workspace":{"imagePu\
llPolicy":"Always"}},"kind":"DevWorkspaceOperatorConfig","metadata":{"annotations":{},"name":"devworkspace-operator-config","namespace":"devworkspace-controller"}}
  creationTimestamp: "2022-06-10T20:28:38Z"
  generation: 4
  name: devworkspace-operator-config
  namespace: devworkspace-controller
  resourceVersion: "42646"
  uid: 4f5198b5-1d0d-48d6-9f10-6d0955363934
  1. Apply the minimal devfile from step 1: kubectl apply -f minimal_devfile.yaml -n $NAMESPACE
  2. Wait for the workspace to startup and open it:
$: kubectl get devworkspace -n $NAMESPACE 
NAME      DEVWORKSPACE ID             PHASE     INFO
minimal   workspace7dab320bcbd64672   Running   https://workspace7dab320bcbd64672-theia-3100.192.168.39.217.nip.io/
  1. Once opened, the workspace should contain the web-nodejs-sample project

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

@AObuchow
Copy link
Collaborator Author

To test out that existing projects (from the minimal devfile) are not being overwritten, try the following devfile:

kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: minimal
spec:
  started: true
  template:
    projects:
      - name: go-starter
        git:
          remotes:
            origin: https://github.com/devfile-samples/devfile-stack-go.git

After applying the devfile and opening the workspace, the node and go project should both be present:
image

@AObuchow
Copy link
Collaborator Author

Currently, sync_test'sTestMergeConfigLooksAtAllFieldsis failing when fuzzing the expected config. It seems to have trouble fuzzing the DefaultTemplate, specifically for the Components.

controllers/workspace/devworkspace_controller.go Outdated Show resolved Hide resolved
controllers/workspace/devworkspace_controller.go Outdated Show resolved Hide resolved
pkg/config/defaults.go Outdated Show resolved Hide resolved
@AObuchow
Copy link
Collaborator Author

Currently, sync_test'sTestMergeConfigLooksAtAllFieldsis failing when fuzzing the expected config. It seems to have trouble fuzzing the DefaultTemplate, specifically for the Components.

The fuzzer seems to be panicking on Object from runtime.RawExtension which is reached from the DefaultTemplate:
DefaultTemplate *dw.DevWorkspaceTemplateSpecContent -> Components []Component -> ComponentUnion -> Custom *CustomComponent -> EmbeddedResource runtime.RawExtension -> Object Object

// limitations under the License.
//

package workspace
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'm not really sure about this package name or file name...
We already have /pkg/controllers/workspace and there's also another file called helper.go for the flatten package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not name the package e.g. defaults or workspacedefaults

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 went with defaults as it seems more generic/could potentially be reused more easily in the future. However, I'm not yet sure about the filename helper.go, maybe it should just be called workspace.go?

@AObuchow
Copy link
Collaborator Author

Currently, sync_test'sTestMergeConfigLooksAtAllFieldsis failing when fuzzing the expected config. It seems to have trouble fuzzing the DefaultTemplate, specifically for the Components.

The fuzzer seems to be panicking on Object from runtime.RawExtension which is reached from the DefaultTemplate: DefaultTemplate *dw.DevWorkspaceTemplateSpecContent -> Components []Component -> ComponentUnion -> Custom *CustomComponent -> EmbeddedResource runtime.RawExtension -> Object Object

This was fixed with f.SkipFieldsWithPattern(regexp.MustCompile("^Object$")) but there might be a better way to fix this?

pkg/config/defaults.go Outdated Show resolved Hide resolved
@AObuchow AObuchow requested a review from amisevsk June 13, 2022 22:05
controllers/workspace/devworkspace_controller.go Outdated Show resolved Hide resolved
pkg/config/sync_test.go Outdated Show resolved Hide resolved
// limitations under the License.
//

package workspace
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not name the package e.g. defaults or workspacedefaults

pkg/library/workspace/helper.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@amisevsk amisevsk left a comment

Choose a reason for hiding this comment

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

LGTM, still need to test it (tomorrow)

@AObuchow AObuchow changed the title WIP: configurable default Workspace Spec Template configurable default Workspace Spec Template Jun 16, 2022
@openshift-ci openshift-ci bot removed the lgtm label Jun 16, 2022
@AObuchow
Copy link
Collaborator Author

LGTM, still need to test it (tomorrow)

Sounds good :) I just rebased the PR

Copy link
Collaborator

@amisevsk amisevsk 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 and it works like a charm 👍

Well done!

@openshift-ci openshift-ci bot added the lgtm label Jun 16, 2022
@amisevsk
Copy link
Collaborator

Don't forget to squash the commits down to something tidy and make sure all commits have signoff -- tests will need to be re-run once this is done.

/ok-to-test

Fix devfile#853

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
Part of devfile#853

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
@@ -80,6 +80,1278 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
defaultTemplate:
Copy link
Contributor

Choose a reason for hiding this comment

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

@AObuchow could you please clarify if the spec for defaultTemplate was created from scratch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was automatically created with make generate manifests fmt generate_default_deployment generate_olm_bundle_yaml. The reason it is so large is because of all the fields contained within the DevWorkspaceTemplateSpecContent struct

Copy link
Contributor

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

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

great job 👍

@openshift-ci
Copy link

openshift-ci bot commented Jun 23, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amisevsk, AObuchow, 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

@AObuchow AObuchow merged commit bc018d1 into devfile:main Jun 23, 2022
@AObuchow AObuchow deleted the AObuchow/issue853 branch June 23, 2022 14:04
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.

Start a (default, configurable) Pod if the DevWorkspace.spec.template is empty
3 participants