kompose icon indicating copy to clipboard operation
kompose copied to clipboard

$ in command is to aggressively replaced with $()

Open mihaichitic opened this issue 1 year ago • 10 comments

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 avatar May 08 '23 11:05 mihaichitic

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

SBD580 avatar Jun 03 '23 22:06 SBD580

I'm not sure escaping variables for bash is the best way to handle the initial issue presented here: https://github.com/kubernetes/kompose/issues/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.

sfdumi avatar Jul 11 '23 16:07 sfdumi

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

AhmedGrati avatar Jul 18 '23 15:07 AhmedGrati

Sure.

sfdumi avatar Jul 19 '23 06:07 sfdumi

/assign sfdumi

AhmedGrati avatar Jul 19 '23 07:07 AhmedGrati

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-triage-robot avatar Jan 24 '24 20:01 k8s-triage-robot

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-triage-robot avatar Feb 23 '24 20:02 k8s-triage-robot

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-triage-robot avatar Mar 24 '24 20:03 k8s-triage-robot

@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 avatar Mar 24 '24 20:03 k8s-ci-robot

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 avatar Apr 09 '24 14:04 fresh2dev

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-triage-robot avatar May 09 '24 19:05 k8s-triage-robot

@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.

k8s-ci-robot avatar May 09 '24 19:05 k8s-ci-robot