quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Kubernetes extension: Support env vars from secrets with a prefix

Open wpernath opened this issue 1 year ago • 6 comments

Description

Right now you can apply a Secret (or ConfigMap) as environment variables like this:

quarkus.kubernetes.env.secrets=my-secret

This would map all keys of the Secret (or ConfigMap) to the environment of the Kubernetes deployment manifest:

envFrom:
  - secretRef:
       name: my-secret

However, especially when you're dealing with more than - perhaps - one datasource, it would be great to specify also a prefix. Kubernetes supports adding a prefix to imported keys from Secret / ConfigMap.

envFrom:
  - secretRef:
    name: my-secret
  prefix: DB1_

If my-secret contains a key called user it would be mapped to DB1_user, which you then could use to specify your datasource properties in application.properties:

%prod.quarkus.datasource.username=${DB1_user:wanja}

It would be great if Quarkus could allow the specification of a prefix inapplication.properties for example by using this grammar:

quarkus.kubernetes.env.secrets=my-secret[DB1_],my-other-secret[DB2_]

Or by introducing another sub key of env called prefix:

quarkus.kubernetes.env.prefix.my-secret=DB1_

Implementation ideas

No response

wpernath avatar Feb 06 '24 11:02 wpernath

/cc @geoand (kubernetes), @iocanel (kubernetes)

quarkus-bot[bot] avatar Feb 06 '24 11:02 quarkus-bot[bot]

Seems reasonable to me! WDYT @iocanel?

geoand avatar Feb 06 '24 11:02 geoand

Hi @wpernath, can I get this one or do you want to work on this issue?

mcruzdev avatar Feb 07 '24 14:02 mcruzdev

@mcruzdev, please, please take it. -- Thank you!

wpernath avatar Feb 08 '24 18:02 wpernath

Thank you @wpernath!

mcruzdev avatar Feb 08 '24 21:02 mcruzdev

Hi @iocanel and @geoand , I am making some research before implement the solution. Looking the io.dekorate.kubernetes.config.EnvBuilder, there is no way to configure a prefix for envFrom property. I can be doing some mistakes, but if not there is a solution for this one?

mcruzdev avatar Feb 12 '24 19:02 mcruzdev

@mcruzdev: It's possible that this needs to be implemented in dekorate first. Would you like to give it a try?

iocanel avatar Mar 04 '24 09:03 iocanel

Hi @iocanel surely, I will try!

mcruzdev avatar Mar 04 '24 11:03 mcruzdev

Hi @iocanel, I created the issue on https://github.com/dekorateio/dekorate repo, I will start to work on this tomorrow, thank you!

mcruzdev avatar Mar 07 '24 04:03 mcruzdev

Hi @iocanel, @wpernath and @geoand I think that the #39782 is done, can you take a look?

mcruzdev avatar Apr 19 '24 14:04 mcruzdev