kompose
kompose copied to clipboard
$ in command is to aggressively replaced with $()
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
Also, seems like underscores are not treated property: $A_B
-> $(A)_B
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 I can assign it to you if you want to open a PR for this issue.
Sure.
/assign sfdumi
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
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
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: 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 closedYou 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.
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.
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: 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 closedYou 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.