Skip to content

Add support for devfile 2.0 global variables #509

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 3 commits into from
Jul 29, 2021

Conversation

amisevsk
Copy link
Collaborator

What does this PR do?

Add support for devfile 2.0 variables. In most string fields in a DevWorkspace, DWO will attempt to replace the string {{ some-variable }} with the corresponding variable from .spec.template.variables.

If a replacement cannot be found, a new condition DevWorkspaceWarning is set on the DevWorkspace with a message like

Error processing variable replacements: invalid variables in component test-container: 'test-variable'"

and the info message will be updated to include some warning text, e.g.

NAME         DEVWORKSPACE ID             PHASE      INFO
theia-next   workspace89e5bf5e04b34b6b   Starting   [warnings present] Waiting for workspace deployment

What issues does this PR fix or reference?

#508

Is it tested? How?

Apply the DevWorkspace below:

cat <<EOF | kubectl apply -f -
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: theia-next
spec:
  started: true
  template:
    attributes:
      controller.devfile.io/storage-type: "ephemeral"
    variables:
      test-variable: "testing_value"
    components:
      - name: test-container
        container:
          image: quay.io/libpod/busybox:latest
          command: ["tail"]
          args: ["-f", "/dev/null"]
          env:
          - name: TEST_ENV
            value: "{{test-variable}}"
      - name: theia
        plugin:
          uri: https://che-plugin-registry-main.surge.sh/v3/plugins/eclipse/che-theia/next/devfile.yaml
EOF

The value in the env var should be replaced once the pod is created.

To test warnings, delete the variable from the devworkspace

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

@amisevsk amisevsk requested review from sleshchenko and JPinkney July 23, 2021 15:21
@amisevsk amisevsk changed the title Add devfile variables Add support for devfile 2.0 global variables Jul 23, 2021
Copy link
Contributor

@JPinkney JPinkney left a comment

Choose a reason for hiding this comment

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

Just tested and it LGTM

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 just tested and works as expected. Please create an issue for dashboard to take into account DevWorkspaceWarning.

for starterProjectName, warnings := range warn.StarterProjects {
msg = append(msg, fmt.Sprintf("invalid variables in starter project %s: '%s'", starterProjectName, strings.Join(warnings, "', '")))
}
return fmt.Sprintf("Error processing variable replacements: %s", strings.Join(msg, "; "))
Copy link
Member

Choose a reason for hiding this comment

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

when I tested I noticed that probably there are even more quotas than we would like to have

  conditions:
  - lastTransitionTime: "2021-07-28T12:57:33Z"
    message: 'Error processing variable replacements: invalid variables in component
      vsix-installer: ''test-variable''; invalid variables in component tools: ''test-variable'''

Ah, I see. It's ' is used for multilines, and '' is escaped '

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The joys of YAML :D

For a while I wanted to use %q instead of %s (so that it would print "var" instead of print var), but that ends up requiring escapes all the time.

@openshift-ci
Copy link

openshift-ci bot commented Jul 28, 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

@amisevsk
Copy link
Collaborator Author

Created dashboard issue: eclipse-che/che#20220

@openshift-ci
Copy link

openshift-ci bot commented Jul 28, 2021

New changes are detected. LGTM label has been removed.

@openshift-ci openshift-ci bot removed the lgtm label Jul 28, 2021
@amisevsk
Copy link
Collaborator Author

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

@sleshchenko sleshchenko merged commit 44c0001 into devfile:main Jul 29, 2021
@amisevsk amisevsk deleted the add-devfile-variables branch July 29, 2021 16:11
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.

3 participants