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

Fixes export and execution of env variables for devfile commands #4267

Merged

Conversation

mik-dass
Copy link
Contributor

@mik-dass mik-dass commented Nov 27, 2020

What type of PR is this?

/kind bug

What does does this PR do / why we need it:

Fixes export and execution of env variables for command in the devfile.

Which issue(s) this PR fixes:

Fixes #4232

PR acceptance criteria:

How to test changes / Special notes to the reviewer:

  • Use a devfile that defines a command spawning a new shell, for example like this:
  - id: run 
    exec:
      component: tools
      commandLine: "sh -c 'mkdir $foo'"
      group:
        kind: run
        isDefault: true
      env:
        - name: foo
          value: bar
  • Check if the command is executed successfully.

@dharmit
Copy link
Member

dharmit commented Dec 2, 2020

@mik-dass @kadel @adisky correct me if I'm doing something dumb here.

Here's the devfile that I used:

schemaVersion: 2.0.0
metadata:
  name: nodejs
  version: 1.0.0
  alpha.build-dockerfile: "https://raw.githubusercontent.com/odo-devfiles/registry/master/devfiles/nodejs/build/Dockerfile"
  alpha.deployment-manifest: "https://raw.githubusercontent.com/odo-devfiles/registry/master/devfiles/nodejs/deploy/deployment-manifest.yaml"
starterProjects:
  - name: nodejs-starter
    git:
      remotes:
        origin: "https://github.com/odo-devfiles/nodejs-ex.git"
components:
  - name: runtime
    container:
      image: registry.access.redhat.com/ubi8/nodejs-12:1-45
      memoryLimit: 1024Mi
      mountSources: true
      sourceMapping: /project
      endpoints:
        - name: http-3000
          targetPort: 3000
commands:
  - id: run 
    exec:
      component: runtime
      commandLine: "sh -c 'mkdir $foo'"
      group:
        kind: run
        isDefault: true
      env:
        - name: foo
          value: bar

And here's the odo push output:

$ odo push        

Validation
 ✓  Validating the devfile [34638ns]

Creating Kubernetes resources for component node-todo
 ✓  Waiting for component to start [6s]

Applying URL changes
 ✓  URL http-3000: http://http-3000-node-todo-buikmestmo.apps-crc.testing/ created

Syncing to component node-todo
 ✓  Checking files for pushing [680178ns]
 ✓  Syncing files to the component [243ms]

Executing devfile commands for component node-todo
 ✓  Executing run command "sh -c 'mkdir $foo'" [1s]

Pushing devfile component node-todo
 ✓  Changes successfully pushed to component

But if I spin up another shell, the env var doesn't seem to persist:

$ kubectl exec node-todo-5f5d5d5dd-7mcxm -- env | grep foo
ODO_COMMAND_RUN=export foo="bar" && sh -c 'mkdir $foo'

$ kubectl exec node-todo-5f5d5d5dd-7mcxm -- echo $foo

Am I doing or expecting something that's out of place or doing something wrong here?

@mik-dass
Copy link
Contributor Author

mik-dass commented Dec 4, 2020

But if I spin up another shell, the env var doesn't seem to persist:

These env vars are only used during the execution of run, debug etc commands from the devfile.

Copy link
Member

@dharmit dharmit left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Dec 7, 2020
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dharmit, mik-dass

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Dec 7, 2020
@openshift-merge-robot openshift-merge-robot merged commit 6b7d258 into redhat-developer:master Dec 7, 2020
@mik-dass mik-dass deleted the export_env_devfile_cmd branch December 7, 2020 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

env variables in exec commands are not properly exported
5 participants