-
Notifications
You must be signed in to change notification settings - Fork 40
Add support for environment variable substitution #300
Conversation
9633160
to
7d9d267
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also works for YAML fields and not only values, is that the expected behavior?
e.g.
name: httpd
containers:
- [[ KFIELD ]]: centos/httpd
services:
- name: httpd
type: NodePort
ports:
- port: 8080
targetPort: 80
and this works - KFIELD=image kedge generate -f docs/examples/simplest/httpd.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works perfectly for me, code LGTM, feel free to merge 🎉
pkg/cmd/util.go
Outdated
} | ||
|
||
// replaceWithEnv is used with regexp.ReplaceAllFunc to replace variable | ||
// with value from envrironment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo fixed, thx
Yep, that is a side effect of the way how it is implemented. I wouldn't suggest doing it anywhere but it is possible. |
You can use environment variables in you Kedge files. Expression is [[ variable_name ]].
@kadel @containscafeine Am I doing anything wrong? $ kedge version
0.2.0 (f9c6b37)
$ cat file.yaml
name: httpd
containers:
- image: [[ imagename ]]
$ imagename=foo
$ echo $imagename
foo
$ kedge generate -f .
failed to replace variables: undefined variable(s): imagename |
This worked alright: $ export imagename=foo
$ echo $imagename
foo
$ kedge generate -f .
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: httpd
name: httpd
spec:
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: httpd
name: httpd
spec:
containers:
- image: foo
name: httpd
resources: {}
status: {} |
$ imagename=foo kedge generate -f .
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: httpd
name: httpd
spec:
... This also worked fine! |
This is OK it shouldn't work. This is how env variables work in bash. If you don't export it the variable is not passed to any child processes of given shell.
Above works because In this case variable is directly passed to kedge process.
Above is also working because export is used and that means that any child process of given shell will also see this variable But following doesn't work as kedge process is a new child process of given shell, and it doesn't receive unexported variables.
it works with echo, because echo is build in bash function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kadel thanks for that explanation!
This LGTM!
You can use environment variables in you Kedge files. Expression is
[[ variable_name ]]
.fixes #224
TODO:
move variable substitution logic from pkg/cmd/util.go to its own packageI'm keeping this as it is, for now. We need clean up whole
pkg/cmd
package. Created #301