Skip to content

Commit

Permalink
Fixed interpolation
Browse files Browse the repository at this point in the history
Signed-off-by: Helber Belmiro <[email protected]>
  • Loading branch information
hbelmiro committed Aug 29, 2023
1 parent 87ba285 commit f087b5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package org.kie.kogito.addons.quarkus.k8s.config;

import java.util.Arrays;

import org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol;

import io.smallrye.config.ConfigValue;

class ConfigValueExpander {
Expand Down Expand Up @@ -51,9 +55,17 @@ static String extractServiceCoordinates(String rawValue) {
int endIndex = rawValue.indexOf("}", startIndex);

if (startIndex != -1 && endIndex != -1) {
return rawValue.substring(startIndex + 2, endIndex);
} else {
return null;
String substring = rawValue.substring(startIndex + 2, endIndex);

boolean isKubernetesServiceCoordinate = Arrays.stream(KubernetesProtocol.values())
.map(KubernetesProtocol::getValue)
.anyMatch(protocol -> substring.startsWith(protocol + ":"));

if (isKubernetesServiceCoordinate) {
return substring;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void expandable(String expandableValues) {
}

@ParameterizedTest
@ValueSource(strings = { "https://localhost/8080", "kubernetes:pods.v1/kie/kogito", "openshift:pods.v1/kie/kogito", "knative:kie/kogito" })
@ValueSource(strings = { "https://localhost/8080", "kubernetes:pods.v1/kie/kogito", "openshift:pods.v1/kie/kogito", "knative:kie/kogito", "${something}" })
void nonExpandable(String nonExpandableValue) {
ConfigValueExpander expander = new ConfigValueExpander(new FakeKubeDiscoveryConfigCache("should not be returned"));

Expand Down

0 comments on commit f087b5c

Please sign in to comment.