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

Inconsistent Environment Variables in postStart Events #23237

Open
eye0fra opened this issue Nov 7, 2024 · 0 comments
Open

Inconsistent Environment Variables in postStart Events #23237

eye0fra opened this issue Nov 7, 2024 · 0 comments
Labels
area/devworkspace-operator kind/bug Outline of a bug - must adhere to the bug report template. severity/P2 Has a minor but important impact to the usage or development of the system.

Comments

@eye0fra
Copy link

eye0fra commented Nov 7, 2024

Describe the bug

This issue arises from the discussion in issue #23009.

Problem

There is an inconsistency in the environment variables, specifically the $PATH, when commands are executed during the postStart event in a Devfile. The commands do not share the same environment variables as they would if launched normally inside the workspace. This is particularly problematic when dealing with images that offer multiple shell environments, such as bash and zsh.
The postStart events are executed with /bin/sh/ by default, which does not load shell-specific configuration files like .bashrc or .zshrc, leading to missing environment variables and configurations.

Comments Summary

  • @AObuchow suggested that the issue might be due to the use of /bin/sh/, which does not load shell-specific configuration files. A workaround is to add a postStart event that sources the appropriate configuration file (e.g., ~/.bashrc or ~/.zshrc) to initialize the environment variables.
  • @eye0fra acknowledged the workaround but highlighted the challenge (parent-devfile) of managing multiple shell environments. Restoring the SHELL environment variable to ensure the correct shell is used, which is crucial for avoiding terminal issues and ensuring consistency in the workspace terminal.

Proposed Solution

  • Implement a mechanism to allow configuration of the shell used for postStart events, enabling users to specify whether to use bash, zsh, or another shell.
  • Automatically source the appropriate shell configuration file (e.g., .bashrc, .zshrc) if the specified shell supports it, ensuring that all necessary environment variables and configurations are loaded.
  • Provide a way to restore the SHELL environment variable to its intended value, ensuring that subsequent commands and terminal sessions use the correct shell.

Che version

7.94@latest

Steps to reproduce

Create a devfile with the following command and event:

events:
  postStart:
    - display-path
commands:
  - id: display-path
    exec:
      component: tools
      commandLine: echo $PATH

Expected behavior

PATH on the event must have the same value as the PATH env defined inside command and image component.

Runtime

OpenShift

Screenshots

image (5)
image (4)

Installation method

OperatorHub

Environment

other (please specify in additional context)

Eclipse Che Logs

No response

Additional context

OpenShift DevSpaces 3.16.1

@eye0fra eye0fra added the kind/bug Outline of a bug - must adhere to the bug report template. label Nov 7, 2024
@che-bot che-bot added the status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. label Nov 7, 2024
@dkwon17 dkwon17 added severity/P1 Has a major impact to usage or development of the system. severity/P2 Has a minor but important impact to the usage or development of the system. and removed status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. severity/P1 Has a major impact to usage or development of the system. labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devworkspace-operator kind/bug Outline of a bug - must adhere to the bug report template. severity/P2 Has a minor but important impact to the usage or development of the system.
Projects
None yet
Development

No branches or pull requests

4 participants