Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KOGITO-9757 Changed property expansion to use ${property_name} #3188

Merged
merged 7 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions quarkus/addons/kubernetes/integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-kubernetes-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>kogito-addons-quarkus-kubernetes-integration-tests</artifactId>
<name>Kogito Add-On Kubernetes - Integration Tests</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-serverless-workflow</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-kubernetes</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog-test-utils</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-workflow-common-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-messaging-deployment</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<configuration>
<noDeps>true</noDeps>
<skip>${skipTests}</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.addons.quarkus.kubernetes;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("/foo")
@Produces(MediaType.TEXT_PLAIN)
public class Foo {

@Inject
@ConfigProperty(name = "my_service")
String service;

@GET
public String getWorkflowType() {
return service;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my_service=${knative:services.v1.serving.knative.dev/default/serverless-workflow-greeting-quarkus}/path
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.addons.quarkus.kubernetes;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.kie.kogito.addons.quarkus.k8s.test.utils.KnativeResourceDiscoveryTestUtil.createServiceIfNotExists;

@QuarkusIntegrationTest
@WithKubernetesTestServer
class ConfigValueExpanderIT {

private static final String NAMESPACE = "default";

private static final String SERVICENAME = "serverless-workflow-greeting-quarkus";

@KubernetesTestServer
KubernetesServer mockServer;

@BeforeEach
void beforeEach() {
createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", NAMESPACE, SERVICENAME);
}

@Test
void test() {
given().when()
.get("/foo")
.then()
.statusCode(200)
.body(is("http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io/path"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
annotations:
serving.knative.dev/creator: minikube-user
serving.knative.dev/lastModifier: minikube-user
creationTimestamp: '2022-08-17T13:58:53Z'
generation: 1
name: serverless-workflow-greeting-quarkus
resourceVersion: '43817'
uid: 98530cb6-3274-4d0c-b654-a82645cda058
spec:
template:
metadata:
annotations:
client.knative.dev/updateTimestamp: '2022-08-17T13:58:53Z'
client.knative.dev/user-image: kiegroup/serverless-workflow-greeting-quarkus:1.0
creationTimestamp:
spec:
containerConcurrency: 0
containers:
- image: kiegroup/serverless-workflow-greeting-quarkus:1.0
name: user-container
readinessProbe:
successThreshold: 1
tcpSocket:
port: 0
resources: { }
enableServiceLinks: false
timeoutSeconds: 300
traffic:
- latestRevision: true
percent: 100
status:
address:
url: http://serverless-workflow-greeting-quarkus.test.svc.cluster.local
conditions:
- lastTransitionTime: '2022-08-17T13:59:00Z'
status: 'True'
type: ConfigurationsReady
- lastTransitionTime: '2022-08-17T13:59:00Z'
status: 'True'
type: Ready
- lastTransitionTime: '2022-08-17T13:59:00Z'
status: 'True'
type: RoutesReady
latestCreatedRevisionName: serverless-workflow-greeting-quarkus-00001
latestReadyRevisionName: serverless-workflow-greeting-quarkus-00001
observedGeneration: 1
traffic:
- latestRevision: true
percent: 100
revisionName: serverless-workflow-greeting-quarkus-00001
url: http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
1 change: 1 addition & 0 deletions quarkus/addons/kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<modules>
<module>runtime</module>
<module>deployment</module>
<module>integration-tests</module>
</modules>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.kie.kogito.addons.quarkus.k8s.config;

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

import io.smallrye.config.ConfigValue;

class ConfigValueExpander {
Expand All @@ -28,22 +26,34 @@ class ConfigValueExpander {
}

ConfigValue expand(ConfigValue configValue) {
if (configValue == null || !valueContainsDiscovery(configValue)) {
return configValue;
if (configValue != null && configValue.getRawValue() != null) {
String serviceCoordinates = extractServiceCoordinates(configValue.getRawValue());
if (serviceCoordinates != null) {
return kubeDiscoveryConfigCache.get(configValue.getName(), serviceCoordinates)
.map(value -> interpolate(configValue.getRawValue(), value))
.map(configValue::withValue)
.orElse(configValue);
}
}

return kubeDiscoveryConfigCache.get(configValue.getName(), configValue.getValue())
.map(configValue::withValue)
.orElse(configValue);
return configValue;
}

private boolean valueContainsDiscovery(ConfigValue configValue) {
for (KubernetesProtocol protocol : KubernetesProtocol.values()) {
String value = configValue.getValue();
if (value != null && value.startsWith(protocol.getValue() + ":")) {
return true;
}
public static String interpolate(String input, String replacement) {
int startIndex = input.indexOf("${");
int endIndex = input.indexOf("}", startIndex);

return input.substring(0, startIndex) + replacement + input.substring(endIndex + 1);
}

static String extractServiceCoordinates(String rawValue) {
int startIndex = rawValue.indexOf("${");
int endIndex = rawValue.indexOf("}", startIndex);

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