Skip to content

Commit

Permalink
Merge pull request #27681 from Sgitario/kubernetes_allow_envvar_optional
Browse files Browse the repository at this point in the history
Support empty env var values in Kubernetes/Knative/OpenShift extensions
  • Loading branch information
geoand authored Sep 2, 2022
2 parents 14dbf86 + 002af34 commit 86a212c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static List<Env> convert(EnvVarsConfig e) {
e.secrets.ifPresent(sl -> sl.forEach(s -> envs.add(new EnvBuilder().withName(convertName(s)).withSecret(s).build())));
e.configmaps
.ifPresent(cl -> cl.forEach(c -> envs.add(new EnvBuilder().withName(convertName(c)).withConfigmap(c).build())));
e.vars.forEach((k, v) -> envs.add(new EnvBuilder().withName(convertName(k)).withValue(v).build()));
e.vars.forEach((k, v) -> envs.add(new EnvBuilder().withName(convertName(k)).withValue(v.orElse("")).build()));
e.fields.forEach((k, v) -> {
// env vars from fields need to have their name set in addition to their field field :)
final String field = convertName(k);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ default Collection<KubernetesEnvBuildItem> convertToBuildItems() {

// override old-style with newer versions if present
final EnvVarsConfig c = getEnv();
c.vars.forEach((k, v) -> validator.process(KubernetesEnvBuildItem.createSimpleVar(k, v, target)));
c.vars.forEach((k, v) -> validator.process(KubernetesEnvBuildItem.createSimpleVar(k, v.orElse(""), target)));
c.fields.forEach((k, v) -> validator.process(KubernetesEnvBuildItem.createFromField(k, v, target)));
c.configmaps
.ifPresent(cl -> cl.forEach(cm -> validator.process(KubernetesEnvBuildItem.createFromConfigMap(cm, target))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class EnvVarsConfig {
* The map associating environment name to its associated value.
*/
@ConfigItem
Map<String, String> vars;
Map<String, Optional<String>> vars;

/**
* The map recording the configuration of environment variable taking their value from resource (Secret or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void assertGeneratedResources() throws IOException {
assertThat(container.getEnv())
.filteredOn(env -> "ENVVAR".equals(env.getName()))
.singleElement().satisfies(env -> assertThat(env.getValue()).isEqualTo("value"));
assertThat(container.getEnv())
.filteredOn(env -> "EMPTYVAR".equals(env.getName()))
.singleElement().satisfies(env -> assertThat(env.getValue()).isNullOrEmpty());
assertThat(container.getEnv())
.filteredOn(env -> "QUARKUS_KUBERNETES_CONFIG_ENABLED".equals(env.getName()))
.singleElement().satisfies(env -> assertThat(env.getValue()).isEqualTo("true"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
quarkus.kubernetes.env.fields.fromfield=metadata.name
quarkus.kubernetes.env.vars.envvar=value
quarkus.kubernetes.env.vars.emptyvar=
quarkus.kubernetes.env.vars."quarkus.kubernetes-config.enabled"=true
quarkus.kubernetes.env.configmaps=configName
quarkus.kubernetes.env.secrets=secretName
Expand Down

0 comments on commit 86a212c

Please sign in to comment.