-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add prefix to envFrom configMap and secrets
- Loading branch information
Showing
4 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,6 @@ | |
String field() default ""; | ||
|
||
String resourceField() default ""; | ||
|
||
String prefix() default ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/test/java/io/dekorate/kubernetes/decorator/AddEnvVarDecoratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.dekorate.kubernetes.decorator; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.List; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.dekorate.kubernetes.config.EditableEnv; | ||
import io.dekorate.kubernetes.config.EnvBuilder; | ||
import io.fabric8.kubernetes.api.model.ContainerBuilder; | ||
import io.fabric8.kubernetes.api.model.EnvFromSource; | ||
|
||
class AddEnvVarDecoratorTest { | ||
|
||
@Test | ||
void shouldAddPrefixToContainerWhenUsingConfigMapRef() { | ||
|
||
EditableEnv editableEnv = new EnvBuilder() | ||
.withConfigmap("configs") | ||
.withPrefix("ALPHA") | ||
.build(); | ||
|
||
AddEnvVarDecorator addEnvVarDecorator = new AddEnvVarDecorator("jdeployment", "jcontainer", editableEnv); | ||
|
||
ContainerBuilder containerBuilder = new ContainerBuilder(); | ||
|
||
addEnvVarDecorator.andThenVisit(containerBuilder); | ||
|
||
List<EnvFromSource> envFromSources = containerBuilder.buildEnvFrom(); | ||
|
||
Assertions.assertThat(envFromSources.size()).isOne(); | ||
|
||
Assertions.assertThat(envFromSources) | ||
.filteredOn("prefix", "ALPHA") | ||
.extracting("configMapRef.name") | ||
.contains("configs") | ||
.isNotEmpty(); | ||
|
||
} | ||
|
||
@Test | ||
void shouldAddPrefixToContainerWhenUsingSecretRef() { | ||
|
||
EditableEnv editableEnv = new EnvBuilder() | ||
.withSecret("secrets") | ||
.withPrefix("ALPHA") | ||
.build(); | ||
|
||
AddEnvVarDecorator addEnvVarDecorator = new AddEnvVarDecorator("jdeployment", "jcontainer", editableEnv); | ||
|
||
ContainerBuilder containerBuilder = new ContainerBuilder(); | ||
|
||
addEnvVarDecorator.andThenVisit(containerBuilder); | ||
|
||
List<EnvFromSource> envFromSources = containerBuilder.buildEnvFrom(); | ||
|
||
Assertions.assertThat(envFromSources.size()).isOne(); | ||
|
||
Assertions.assertThat(envFromSources) | ||
.filteredOn("prefix", "ALPHA") | ||
.extracting("secretRef.name") | ||
.contains("secrets") | ||
.isNotEmpty(); | ||
} | ||
} |