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

Allow to configure kamel CLI with env vars and configuration files #1133

Merged
merged 10 commits into from
Dec 18, 2019

Conversation

lburgazzoli
Copy link
Contributor

@lburgazzoli lburgazzoli commented Dec 10, 2019

Fixes #1108

You can now configure default values for any kamel command in a file named .kamel/config.yaml in the current working directory or in the user home like:

kamel:
  install:
    kits:
      - js
      - yaml
    maven-repositories:
      - http://repository.apache.org/snapshots@id=apache.snapshots@snapshots@noreleases
      - http://oss.sonatype.org/content/repositories/snapshots@id=oss.snapshots@snapshots@noreleases

Environment variables can be used to so the configuration below can be replaced by:

KAMEL_INSTALL_KITS="js,yaml"
KAMEL_INSTALL_MAVEN_REPOSITORIES="http://repository.apache.org/snapshots@id=apache.snapshots@snapshots@noreleases,http://oss.sonatype.org/content/repositories/snapshots@id=oss.snapshots@snapshots@noreleases"

You can of course mix command flags, environment variables and configuration files (in the given order of priority).

Note that inside a configuration file or environment variables, multi value flags are expressed through the plural for of the flag, as example:

kamel install --kit=js --kit=java

is equivalent to

KAMEL_INSTALL_KITS="js,java" kamel install

Release Note


Default values for the kamel CLI can now be configured through a configuration file and/or environment variables.

@lburgazzoli
Copy link
Contributor Author

I still need to work on proper unit test but that would require a major refactor of how we create commands so for the moment it would be nice if anyone can test this PR an report any misbehaviour.

@lburgazzoli lburgazzoli added the kind/feature New feature or request label Dec 10, 2019
@valdar
Copy link
Member

valdar commented Dec 11, 2019

@lburgazzoli Ah! actually I have that refactor almost done in some stashed commit locally... based on a years-old camel-k ...

@jamesnetherton
Copy link
Contributor

jamesnetherton commented Dec 11, 2019

Question about:

multi value flags are expressed through the plural for of the flag

Does that apply to everything? E.g if I want to apply a set of environment variables to my integration via the --env flag of kamel run.

The singular version works:

KAMEL_RUN_ENV="FOO=BAR,CHEESE=WINE" kamel run examples/Sample.java

The plural version does not:

KAMEL_RUN_ENVS="FOO=BAR,CHEESE=WINE" kamel run examples/Sample.java

That's seems a bug as it is supposed to be working. It may be an issue as the plural form is computed and maybe not working for that, will have a look. In any case the singular version is always there but does not look very nice for multi val flags

@nicolaferraro
Copy link
Member

Question about:

multi value flags are expressed through the plural for of the flag

Does that apply to everything? E.g if I want to apply a set of environment variables to my integration via the --env flag of kamel run.

The singular version works:

KAMEL_RUN_ENV="FOO=BAR,CHEESE=WINE" kamel run examples/Sample.java

The plural version does not:

KAMEL_RUN_ENVS="FOO=BAR,CHEESE=WINE" kamel run examples/Sample.java

That's seems a bug as it is supposed to be working. It may be an issue as the plural form is computed and maybe not working for that, will have a look. In any case the singular version is always there but does not look very nice for multi val flags

A different thing (nice to have?) would be to have a named config for each runnable integration, like:

kamel:
  install:
    kits:
      - js
      - yaml
  run:
    hello.groovy:
      dependencies:
      - "camel:jackson"

@lburgazzoli
Copy link
Contributor Author

A different thing (nice to have?) would be to have a named config for each runnable integration, like:

kamel:
  install:
    kits:
      - js
      - yaml
  run:
    hello.groovy:
      dependencies:
      - "camel:jackson"

that would be much more complex as you'd need to determine first the name of the integration which is itself something you can grab from env or file.

maybe I can add en env var to control a sort of prefix/profile

@lburgazzoli
Copy link
Contributor Author

@jamesnetherton your issues should be fixed now
@nicolaferraro you can not change the name of the configuration file with the env var KAMEL_CONFIG_NAME, this is not a full profile thing but helps a little

preventing testability and possibly causing some unwanted effects
in some scenarios like loading commands configs/flags from env vars and config files
Copy link
Member

@valdar valdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally LGTM!

@lburgazzoli lburgazzoli merged commit f217ed0 into apache:master Dec 18, 2019
@lburgazzoli lburgazzoli deleted the flags branch December 18, 2019 10:30
@nicolaferraro nicolaferraro mentioned this pull request Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to configure kamel CLI with env vars and configuration files
5 participants