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

$ in command is to aggressively replaced with $() #1636

Open
mihaichitic opened this issue May 8, 2023 · 14 comments
Open

$ in command is to aggressively replaced with $() #1636

mihaichitic opened this issue May 8, 2023 · 14 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@mihaichitic
Copy link

Expected Behavior

it should translate to:

spec:
      containers:
        - args:
            - /bin/sh
            - -c
            - |
              echo '$$variable'
              echo $${VAR:+--flag "$$VAR"}
          env:
            - name: VAR
              value: flagValue
            - name: variable
              value: 'should not be interpolated'
          image: alpine
          name: app

which results in kubernetes the following output:

$variable
--flag flagValue

Actual Behavior

it translates to

spec:
      containers:
        - args:
            - /bin/sh
            - -c
            - |
              echo '$()$(variable)'
              echo $()$(){VAR:+--flag "$()$(VAR)"}
          env:
            - name: VAR
              value: flagValue
            - name: variable
              value: 'should not be interpolated'
          image: alpine
          name: app

which in kubernetes will result the following output

$()should not be interpolated
{VAR:+--flag flagValue}

Steps To Reproduce

No response

Kompose Version

1.28

Docker-Compose file

services:
  app:
    image: alpine
    command:
        - /bin/sh
        - -c
        - |
          echo '$$variable'
          echo $${VAR:+--flag "$$VAR"}
    environment:
        variable: 'should not be interpolated'
        VAR: 'flagValue'

Anything else?

No response

@mihaichitic mihaichitic added the kind/bug Categorizes issue or PR as related to a bug. label May 8, 2023
@SBD580
Copy link

SBD580 commented Jun 3, 2023

Also, seems like underscores are not treated property: $A_B -> $(A)_B

@sfdumi
Copy link

sfdumi commented Jul 11, 2023

I'm not sure escaping variables for bash is the best way to handle the initial issue presented here: #1497

One of the many possible counter-examples is to use a script / config file from command args, in a language other than bash/sh.

In this case, the code to be executed (PHP, but it can be any language) must remain unchanged.

services:
  php:
    image: php:8-cli
    command:
      - -r
      - |
       var_dump($$_ENV['FILE']);
       $$file = $$_ENV['FILE'];
       echo file_get_contents($$_ENV['FILE']);
       echo file_get_contents($$file);
    environment:
      FILE: /usr/local/bin/docker-php-entrypoint

However, I get the initial simple case that led to this change, it is fairly common.

If escaping must remain in place, at least the regex should be changed to allow more complex cases:

  • to include underscores (as @SBD580 pointed out), and also
  • curly branches and handle more complex expressions, as the one already provided by @mihaichitic .

I think it should be somewhere along the lines of \$(\{?([a-zA-Z0-9_]+)(:[+-]?[^}]*)?\}?).

  • \$(\{? matches a dollar sign followed by an optional opening brace.
  • ([a-zA-Z0-9_]+) matches one or more alphanumeric characters or underscores. This is the variable name.
  • (:[+-]?[^}]*)? matches an optional colon, followed by an optional plus or minus sign, followed by any number of characters that are not a closing brace. This is the optional modifier and value in expressions like ${VAR:+--flag "$VAR”}.
  • \}?) matches an optional closing brace.

I will try to open a PR in the coming period, as soon as I can test the changes.

@AhmedGrati
Copy link
Contributor

@sfdumi I can assign it to you if you want to open a PR for this issue.

@sfdumi
Copy link

sfdumi commented Jul 19, 2023

Sure.

@AhmedGrati
Copy link
Contributor

/assign sfdumi

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 24, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 23, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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.

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2024
@TessaIO TessaIO reopened this Mar 25, 2024
@fresh2dev
Copy link

fresh2dev commented Apr 9, 2024

The docker-compose CLI offers this flag:

--no-interpolate          Don't interpolate environment variables

The user could work around this issue if kompose offered the same.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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-sigs/prow repository.

@jvitor83
Copy link
Contributor

The docker-compose CLI offers this flag:

--no-interpolate          Don't interpolate environment variables

The user could work around this issue if kompose offered the same.

@fresh2dev #1953

@jvitor83
Copy link
Contributor

Don't know why this is closed. The issue still there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

9 participants