-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fallback specialized kubernetes config to vanilla kubernetes
- Loading branch information
Showing
6 changed files
with
74 additions
and
15 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
47 changes: 47 additions & 0 deletions
47
...ent/src/test/java/io/quarkus/openshift/deployment/config/OpenshiftConfigFallbackTest.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,47 @@ | ||
package io.quarkus.openshift.deployment.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.nio.file.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
import io.smallrye.config.source.yaml.YamlConfigSource; | ||
|
||
public class OpenshiftConfigFallbackTest { | ||
@RegisterExtension | ||
static final QuarkusProdModeTest TEST = new QuarkusProdModeTest() | ||
.setApplicationName("config") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.overrideConfigKey("quarkus.kubernetes.replicas", "10") | ||
.overrideConfigKey("quarkus.openshift.version", "999-SNAPSHOT") | ||
.overrideConfigKey("quarkus.openshift.labels.app", "openshift") | ||
.setRun(true); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
void configFallback() throws Exception { | ||
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
YamlConfigSource kubernetes = new YamlConfigSource(kubernetesDir.resolve("kubernetes.yml").toUri().toURL()); | ||
YamlConfigSource openshift = new YamlConfigSource(kubernetesDir.resolve("openshift.yml").toUri().toURL()); | ||
|
||
// Only in Kubernetes, must fallback to Openshift | ||
assertEquals("10", kubernetes.getValue("spec.replicas")); | ||
assertEquals("10", openshift.getValue("spec.replicas")); | ||
|
||
// In both, each should retain the value | ||
assertEquals("0.1-SNAPSHOT", kubernetes.getValue("spec.template.metadata.labels.\"app.kubernetes.io/version\"")); | ||
assertEquals("999-SNAPSHOT", openshift.getValue("spec.template.metadata.labels.\"app.kubernetes.io/version\"")); | ||
|
||
// Only in Openshift | ||
assertNull(kubernetes.getValue("spec.template.metadata.labels.app")); | ||
assertEquals("openshift", openshift.getValue("spec.template.metadata.labels.app")); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
.../runtime/src/main/java/io/quarkus/kubernetes/runtime/config/KubernetesConfigFallback.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,21 @@ | ||
package io.quarkus.kubernetes.runtime.config; | ||
|
||
import java.util.function.Function; | ||
|
||
import io.smallrye.config.FallbackConfigSourceInterceptor; | ||
|
||
public class KubernetesConfigFallback extends FallbackConfigSourceInterceptor { | ||
public KubernetesConfigFallback() { | ||
super(new Function<String, String>() { | ||
@Override | ||
public String apply(final String name) { | ||
if (name.startsWith("quarkus.openshift.")) { | ||
return "quarkus.kubernetes." + name.substring(18); | ||
} else if (name.startsWith("quarkus.knative.")) { | ||
return "quarkus.kubernetes." + name.substring(16); | ||
} | ||
return name; | ||
} | ||
}); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...a/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor
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 @@ | ||
io.quarkus.kubernetes.runtime.config.KubernetesConfigFallback |
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