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

Issue when trying to configure env vars with annotations #2512

Closed
lburgazzoli opened this issue Jul 16, 2021 · 6 comments · Fixed by #2650
Closed

Issue when trying to configure env vars with annotations #2512

lburgazzoli opened this issue Jul 16, 2021 · 6 comments · Fixed by #2650
Assignees

Comments

@lburgazzoli
Copy link
Contributor

I have a KameletBinding with some traits configured using environment vars:

apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  annotations:
    trait.camel.apache.org/environment.ENV_1: 1vPDOtAJ1gsUvwX1m3hjUJzDpIS
    trait.camel.apache.org/environment.ENV_2: 1vPDOsYNIlNc6mRrd0dNXPGhsDJ

The generated integration fails with:

Events:
  Type     Reason            Age                 From                            Message
  ----     ------            ----                ----                            -------
  Warning  IntegrationError  15s (x15 over 98s)  camel-k-integration-controller  Cannot reconcile Integration cf486b3dc88234900bcc75d838f0ef948: error during trait customization: 1 error(s) decoding:

* '' has invalid keys: ENV_1, ENV_2
@squakez squakez self-assigned this Aug 18, 2021
@squakez
Copy link
Contributor

squakez commented Aug 18, 2021

According the trait documentation, the trait is in charge to inject certain well known env variables, not to create any new one. The actual way to have it working would be to specify via .spec.integration, such as:

metadata:
  name: timer-to-log
  namespace: default
spec:
  integration:
    configuration:
    - type: env
      value: X=1

Perhaps you're suggesting to enhance the trait to include the possibility to declare the env via annotation?

@lburgazzoli
Copy link
Contributor Author

@squakez yes you are right, I got confused by the description of the trait as it says:

environment.[key]=[value]

but then there's no reference to the key word in the table (it uses Properties) so I tough, that adding env vars would work.

BTW, I think it would be valuable to be able to set env vars using a trait instead of the configuration section. @nicolaferraro @astefanutti @squakez what do you think ?

@squakez
Copy link
Contributor

squakez commented Aug 18, 2021

I agree, we can probably move the --env logic into the environment trait.

squakez added a commit to squakez/camel-k that referenced this issue Aug 18, 2021
squakez added a commit that referenced this issue Aug 19, 2021
squakez added a commit to squakez/camel-k that referenced this issue Sep 20, 2021
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes apache#2512
squakez added a commit to squakez/camel-k that referenced this issue Sep 20, 2021
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes apache#2512
squakez added a commit to squakez/camel-k that referenced this issue Sep 20, 2021
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes apache#2512
squakez added a commit to squakez/camel-k that referenced this issue Sep 24, 2021
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes apache#2512
squakez added a commit that referenced this issue Sep 24, 2021
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes #2512
@haifzhan
Copy link

Can someone add an example here? It really confuses about environment.[key]=[value].

In my case, I have MYHOST and MYPORT in the environment variables and I tried
--trait environment.vars=["MYHOST = 10.112.130.81", "MYPORT = 8080"] but it failed, what is the right way to address the key and value pairs?

@squakez
Copy link
Contributor

squakez commented Oct 15, 2021

If you're running directly from the kamel CLI, it is advisable you keep using the --env parameter for all the variables you want to use. That will take care to transform to the proper trait. Usage of trait is advisable if you need to manipulate directly the Integration or a KameletBinding and will be available in version 1.7.

@astefanutti
Copy link
Member

@haifzhan, here is an example how to pass multiple environment variables with the environment trait:

$ kamel run -t environment.vars=MYHOST=10.112.130.81 -t environment.vars=MYPORT=8080

In general, values of multiple occurrences of the same trait option are aggregated into an array, to emulate POSIX conventions, so the syntax is:

$ kamel run -t <trait>.<property>=<value_1> ... -t <trait>.<property>=<value_N>

Or:

$ kamel run --trait <trait>.<property>=<value_1>,...,<trait>.<property>=<value_N>

astefanutti pushed a commit that referenced this issue Jan 21, 2022
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes #2512
astefanutti pushed a commit to jboss-fuse/camel-k that referenced this issue Feb 17, 2022
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes apache#2512
astefanutti pushed a commit to jboss-fuse/camel-k that referenced this issue Feb 21, 2022
Moved the logic to process environment variable to trait. It will simplify setting via annotations

Closes apache#2512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants