Skip to content

Commit f6eef0f

Browse files
ricardozaniniSaumya Singh
authored and
Saumya Singh
committed
Fix kie-issues-1909: Review usage of Fabric8 and tests, remove deprecated APIs (apache#3880)
* Fix kie-issues-1909: Review usage of Fabric8 and tests, remove deprecated APIs Signed-off-by: Ricardo Zanini <[email protected]> * Disable kubernetes test devservices Signed-off-by: Ricardo Zanini <[email protected]> * Add default namespace; align fabric8 version Signed-off-by: Ricardo Zanini <[email protected]> --------- Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 16fbce3 commit f6eef0f

File tree

42 files changed

+634
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+634
-522
lines changed

addons/common/kubernetes-service-catalog/src/test/java/org/kie/kogito/addons/k8s/resource/catalog/KubernetesServiceCatalogTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
*/
3737
public abstract class KubernetesServiceCatalogTest {
3838

39-
private static final String EXPECTED_KNATIVE_URI = "http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io";
39+
private static final String EXPECTED_KNATIVE_URI = "http://serverless-workflow-greeting-quarkus.default.10.99.154.147.sslip.io";
4040

41-
private static final String EXPECTED_KUBERNETES_URI = "http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io";
41+
private static final String EXPECTED_KUBERNETES_URI = "http://serverless-workflow-greeting-quarkus-kubernetes.default.10.99.154.147.sslip.io";
4242

43-
private static final String EXPECTED_OPENSHIFT_URI = "http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io";
43+
private static final String EXPECTED_OPENSHIFT_URI = "http://serverless-workflow-greeting-quarkus-openshift.default.10.99.154.147.sslip.io";
4444

45-
private static final String NAMESPACE = "test";
45+
private static final String NAMESPACE = "default";
4646

4747
private static final String KNATIVE_SERVICENAME = "serverless-workflow-greeting-quarkus";
4848

kogito-bom/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,12 @@
465465
</dependency>
466466
<dependency>
467467
<groupId>org.kie</groupId>
468-
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog-test-utils</artifactId>
468+
<artifactId>kie-addons-quarkus-kubernetes-test-utils</artifactId>
469469
<version>${project.version}</version>
470470
</dependency>
471471
<dependency>
472472
<groupId>org.kie</groupId>
473-
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog-test-utils</artifactId>
473+
<artifactId>kie-addons-quarkus-kubernetes-test-utils</artifactId>
474474
<version>${project.version}</version>
475475
<classifier>sources</classifier>
476476
</dependency>

kogito-build/kogito-dependencies-bom/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
Don't add as a management dependency because it will break SpringBoot and Quarkus
8282
Kubernetes addons since they use a different version.
8383
-->
84-
<version.io.fabric8.kubernetes-client>6.13.3</version.io.fabric8.kubernetes-client>
84+
<version.io.fabric8.kubernetes-client>6.13.4</version.io.fabric8.kubernetes-client>
8585
<version.io.micrometer>1.12.2</version.io.micrometer>
8686
<version.org.flywaydb>10.17.3</version.org.flywaydb>
8787
<version.org.postgresql>42.7.4</version.org.postgresql>

quarkus/addons/fabric8-kubernetes-service-catalog/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@
3636
<modules>
3737
<module>deployment</module>
3838
<module>runtime</module>
39-
<module>test-utils</module>
4039
</modules>
4140
</project>

quarkus/addons/fabric8-kubernetes-service-catalog/runtime/pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@
6565
<type>test-jar</type>
6666
<scope>test</scope>
6767
</dependency>
68+
<dependency>
69+
<groupId>org.kie</groupId>
70+
<artifactId>kie-addons-quarkus-kubernetes-test-utils</artifactId>
71+
<scope>test</scope>
72+
</dependency>
6873
<dependency>
6974
<groupId>io.quarkus</groupId>
7075
<artifactId>quarkus-test-kubernetes-client</artifactId>
7176
<scope>test</scope>
7277
</dependency>
7378
<dependency>
74-
<groupId>io.quarkus</groupId>
75-
<artifactId>quarkus-test-openshift-client</artifactId>
79+
<groupId>io.fabric8</groupId>
80+
<artifactId>openshift-server-mock</artifactId>
7681
<scope>test</scope>
7782
</dependency>
7883
<dependency>
@@ -90,11 +95,6 @@
9095
<artifactId>assertj-core</artifactId>
9196
<scope>test</scope>
9297
</dependency>
93-
<dependency>
94-
<groupId>org.kie</groupId>
95-
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog-test-utils</artifactId>
96-
<scope>test</scope>
97-
</dependency>
9898
</dependencies>
9999

100100
<build>

quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/KubernetesResourceDiscovery.java

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Optional<URI> query(KubernetesResourceUri resourceUri) {
7878
private KubernetesResourceUri resolveNamespace(KubernetesResourceUri uri, Supplier<String> defaultNamespaceSupplier) {
7979
if (uri.getNamespace() == null) {
8080
String defaultNamespace = defaultNamespaceSupplier.get();
81+
if (defaultNamespace == null || defaultNamespace.isEmpty()) {
82+
throw new IllegalArgumentException("Can't resolve namespace for uri " + uri + " using the default namespace supplier: " + defaultNamespaceSupplier.get());
83+
}
8184

8285
logDefaultNamespace(defaultNamespace);
8386

quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/DeploymentUtilsTest.java

+59-64
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.Optional;
2323

2424
import org.junit.jupiter.api.Test;
25+
import org.kie.kogito.addons.quarkus.k8s.test.utils.KubeTestUtils;
26+
import org.kie.kogito.addons.quarkus.k8s.test.utils.OpenShiftMockServerTestResource;
2527

2628
import io.fabric8.kubernetes.api.model.ContainerPortBuilder;
2729
import io.fabric8.kubernetes.api.model.IntOrString;
@@ -30,38 +32,33 @@
3032
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
3133
import io.fabric8.kubernetes.api.model.apps.Deployment;
3234
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
33-
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
35+
import io.fabric8.openshift.client.OpenShiftClient;
36+
import io.quarkus.test.common.QuarkusTestResource;
3437
import io.quarkus.test.junit.QuarkusTest;
35-
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
36-
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
3738

3839
import jakarta.inject.Inject;
3940

4041
import static org.junit.jupiter.api.Assertions.assertEquals;
4142
import static org.junit.jupiter.api.Assertions.assertTrue;
4243

43-
/**
44-
* This tests also covers the queryServiceByLabelOrSelector method from {@link ServiceUtils}
45-
* and queryPodByOwnerReference from {@link PodUtils}
46-
*/
4744
@QuarkusTest
48-
@WithKubernetesTestServer
45+
@QuarkusTestResource(OpenShiftMockServerTestResource.class)
4946
public class DeploymentUtilsTest {
5047

51-
@KubernetesTestServer
52-
KubernetesServer mockServer;
53-
48+
private final String namespace = "serverless-workflow-greeting-quarkus";
49+
@Inject
50+
OpenShiftClient client;
5451
@Inject
5552
KubernetesResourceDiscovery discovery;
5653

57-
private final String namespace = "serverless-workflow-greeting-quarkus";
58-
5954
@Test
6055
public void testNotFoundDeployment() {
61-
Deployment deployment = mockServer.getClient().apps().deployments().inNamespace(namespace)
62-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment.yaml")).item();
56+
Deployment deployment = client.apps().deployments().inNamespace(namespace)
57+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment.yaml")).item();
6358
deployment.getMetadata().setName("test");
64-
mockServer.getClient().resource(deployment).inNamespace(namespace).createOrReplace();
59+
60+
KubeTestUtils.createWithStatusPreserved(client, deployment, namespace, Deployment.class);
61+
6562
assertEquals(Optional.empty(),
6663
discovery.query(KubernetesResourceUri.parse("deployments.v1.apps/" + namespace + "/invalid")));
6764
}
@@ -70,13 +67,13 @@ public void testNotFoundDeployment() {
7067
public void testDeploymentWithService() {
7168
var kubeURI = KubernetesResourceUri.parse("deployments.v1.apps/" + namespace + "/example-deployment-with-service");
7269

73-
Deployment deployment = mockServer.getClient().apps().deployments().inNamespace(namespace)
74-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment.yaml")).item();
75-
mockServer.getClient().resource(deployment).inNamespace(namespace).createOrReplace();
70+
Deployment deployment = client.apps().deployments().inNamespace(namespace)
71+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment.yaml")).item();
72+
KubeTestUtils.createWithStatusPreserved(client, deployment, namespace, Deployment.class);
7673

77-
Service service = mockServer.getClient().services().inNamespace(namespace)
78-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment-service.yaml")).item();
79-
mockServer.getClient().resource(service).inNamespace(namespace).createOrReplace();
74+
Service service = client.services().inNamespace(namespace)
75+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment-service.yaml")).item();
76+
KubeTestUtils.createWithStatusPreserved(client, service, namespace, Service.class);
8077

8178
Optional<String> url = discovery.query(kubeURI).map(URI::toString);
8279
assertEquals("http://10.10.10.11:80", url.get());
@@ -86,21 +83,21 @@ public void testDeploymentWithService() {
8683
public void testDeploymentWithServiceWithCustomPortName() {
8784
var kubeURI = KubernetesResourceUri.parse("deployments.v1.apps/" + namespace + "/custom-port-deployment?port-name=my-custom-port");
8885

89-
Deployment deployment = mockServer.getClient().apps().deployments().inNamespace(namespace)
90-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment.yaml")).item();
86+
Deployment deployment = client.apps().deployments().inNamespace(namespace)
87+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment.yaml")).item();
9188
deployment.getMetadata().setName("custom-port-deployment");
9289
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts()
9390
.add(new ContainerPortBuilder().withName("test-port").withContainerPort(4000).build());
94-
mockServer.getClient().resource(deployment).inNamespace(namespace).createOrReplace();
91+
KubeTestUtils.createWithStatusPreserved(client, deployment, namespace, Deployment.class);
9592

96-
Service service = mockServer.getClient().services().inNamespace(namespace)
97-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment-service.yaml")).item();
93+
Service service = client.services().inNamespace(namespace)
94+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment-service.yaml")).item();
9895
service.getMetadata().setName("custom-port-name-service");
9996
service.getSpec().getPorts().add(new ServicePortBuilder()
10097
.withName("my-custom-port")
10198
.withTargetPort(new IntOrString("test-port"))
10299
.withPort(4009).build());
103-
mockServer.getClient().resource(service).inNamespace(namespace).createOrReplace();
100+
KubeTestUtils.createWithStatusPreserved(client, service, namespace, Service.class);
104101

105102
Optional<String> url = discovery.query(kubeURI).map(URI::toString);
106103
assertEquals("http://10.10.10.11:4009", url.get());
@@ -110,20 +107,20 @@ public void testDeploymentWithServiceWithCustomPortName() {
110107
public void testDeploymentNoService() {
111108
var kubeURI = KubernetesResourceUri.parse("deployments.v1.apps/" + namespace + "/example-deployment-no-service");
112109

113-
Deployment deployment = mockServer.getClient().apps().deployments().inNamespace(namespace)
114-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment-no-service.yaml")).item();
115-
Deployment createdDeployment = mockServer.getClient().resource(deployment).inNamespace(namespace).createOrReplace();
110+
Deployment deployment = client.apps().deployments().inNamespace(namespace)
111+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment-no-service.yaml")).item();
112+
deployment = KubeTestUtils.createWithStatusPreserved(client, deployment, namespace, Deployment.class);
116113

117-
ReplicaSet rs = mockServer.getClient().apps().replicaSets().inNamespace(namespace)
118-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/replica-set-deployment-no-service.yaml")).item();
119-
rs.getMetadata().getOwnerReferences().get(0).setUid(createdDeployment.getMetadata().getUid());
120-
ReplicaSet createdRs = mockServer.getClient().resource(rs).inNamespace(namespace).createOrReplace();
114+
ReplicaSet rs = client.apps().replicaSets().inNamespace(namespace)
115+
.load(getClass().getClassLoader().getResourceAsStream("deployment/replica-set-deployment-no-service.yaml")).item();
116+
rs.getMetadata().getOwnerReferences().get(0).setUid(deployment.getMetadata().getUid());
117+
rs = KubeTestUtils.createWithStatusPreserved(client, rs, namespace, ReplicaSet.class);
121118

122-
Pod pod = mockServer.getClient().pods().inNamespace(namespace)
123-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/pod-deployment-no-service.yaml")).item();
119+
Pod pod = client.pods().inNamespace(namespace)
120+
.load(getClass().getClassLoader().getResourceAsStream("deployment/pod-deployment-no-service.yaml")).item();
124121
pod.getMetadata().setName("pod-deployment-no-service");
125-
pod.getMetadata().getOwnerReferences().get(0).setUid(createdRs.getMetadata().getUid());
126-
mockServer.getClient().resource(pod).inNamespace(namespace).createOrReplace();
122+
pod.getMetadata().getOwnerReferences().get(0).setUid(rs.getMetadata().getUid());
123+
KubeTestUtils.createWithStatusPreserved(client, pod, namespace, Pod.class);
127124

128125
Optional<String> url = discovery.query(kubeURI).map(URI::toString);
129126
assertEquals("http://172.17.0.11:8080", url.get());
@@ -133,23 +130,23 @@ public void testDeploymentNoService() {
133130
public void testDeploymentNoService2Replicas() {
134131
var kubeURI = KubernetesResourceUri.parse("deployments.v1.apps/" + namespace + "/example-deployment-no-service-2-replicas");
135132

136-
Deployment deployment = mockServer.getClient().apps().deployments().inNamespace(namespace)
137-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment-no-service.yaml")).item();
133+
Deployment deployment = client.apps().deployments().inNamespace(namespace)
134+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment-no-service.yaml")).item();
138135
deployment.getMetadata().setName("example-deployment-no-service-2-replicas");
139136
deployment.getStatus().setReplicas(2);
140-
Deployment createdDeployment = mockServer.getClient().resource(deployment).inNamespace(namespace).createOrReplace();
137+
KubeTestUtils.createWithStatusPreserved(client, deployment, namespace, Deployment.class);
141138

142-
ReplicaSet rs = mockServer.getClient().apps().replicaSets().inNamespace(namespace)
143-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/replica-set-deployment-no-service.yaml")).item();
139+
ReplicaSet rs = client.apps().replicaSets().inNamespace(namespace)
140+
.load(getClass().getClassLoader().getResourceAsStream("deployment/replica-set-deployment-no-service.yaml")).item();
144141
rs.getMetadata().setName("rs-2-replicas");
145-
rs.getMetadata().getOwnerReferences().get(0).setUid(createdDeployment.getMetadata().getUid());
146-
ReplicaSet createdRs = mockServer.getClient().resource(rs).inNamespace(namespace).createOrReplace();
142+
rs.getMetadata().getOwnerReferences().get(0).setUid(deployment.getMetadata().getUid());
143+
KubeTestUtils.createWithStatusPreserved(client, rs, namespace, ReplicaSet.class);
147144

148-
Pod pod = mockServer.getClient().pods().inNamespace(namespace)
149-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/pod-deployment-no-service.yaml")).item();
145+
Pod pod = client.pods().inNamespace(namespace)
146+
.load(getClass().getClassLoader().getResourceAsStream("deployment/pod-deployment-no-service.yaml")).item();
150147
pod.getMetadata().setName("pod-2-replicas");
151-
pod.getMetadata().getOwnerReferences().get(0).setUid(createdRs.getMetadata().getUid());
152-
mockServer.getClient().resource(pod).inNamespace(namespace).createOrReplace();
148+
pod.getMetadata().getOwnerReferences().get(0).setUid(rs.getMetadata().getUid());
149+
KubeTestUtils.createWithStatusPreserved(client, pod, namespace, Pod.class);
153150

154151
Optional<String> url = discovery.query(kubeURI).map(URI::toString);
155152
assertTrue(url.isEmpty());
@@ -159,27 +156,25 @@ public void testDeploymentNoService2Replicas() {
159156
public void testDeploymentNoServiceCustomPortName() {
160157
var kubeURI = KubernetesResourceUri.parse("deployments.v1.apps/" + namespace + "/custom-port-deployment-1?port-name=my-custom-port");
161158

162-
Deployment deployment = mockServer.getClient().apps().deployments().inNamespace(namespace)
163-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/deployment-no-service.yaml")).item();
159+
Deployment deployment = client.apps().deployments().inNamespace(namespace)
160+
.load(getClass().getClassLoader().getResourceAsStream("deployment/deployment-no-service.yaml")).item();
164161
deployment.getMetadata().setName("custom-port-deployment-1");
165162
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts()
166163
.add(new ContainerPortBuilder().withName("test-port").withContainerPort(4000).build());
167-
Deployment createdDeployment = mockServer.getClient().resource(deployment).inNamespace(namespace).createOrReplace();
164+
deployment = KubeTestUtils.createWithStatusPreserved(client, deployment, namespace, Deployment.class);
168165

169-
ReplicaSet rs = mockServer.getClient().apps().replicaSets().inNamespace(namespace)
170-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/replica-set-deployment-no-service.yaml")).item();
166+
ReplicaSet rs = client.apps().replicaSets().inNamespace(namespace)
167+
.load(getClass().getClassLoader().getResourceAsStream("deployment/replica-set-deployment-no-service.yaml")).item();
171168
rs.getMetadata().setName("custom-port-rs");
172-
rs.getMetadata().getOwnerReferences().get(0).setUid(createdDeployment.getMetadata().getUid());
173-
ReplicaSet createdRs = mockServer.getClient().resource(rs).inNamespace(namespace).createOrReplace();
169+
rs.getMetadata().getOwnerReferences().get(0).setUid(deployment.getMetadata().getUid());
170+
rs = KubeTestUtils.createWithStatusPreserved(client, rs, namespace, ReplicaSet.class);
174171

175-
Pod pod = mockServer.getClient().pods().inNamespace(namespace)
176-
.load(this.getClass().getClassLoader().getResourceAsStream("deployment/pod-deployment-no-service.yaml")).item();
177-
pod.getMetadata().getOwnerReferences().get(0).setUid(createdRs.getMetadata().getUid());
172+
Pod pod = client.pods().inNamespace(namespace)
173+
.load(getClass().getClassLoader().getResourceAsStream("deployment/pod-deployment-no-service.yaml")).item();
174+
pod.getMetadata().getOwnerReferences().get(0).setUid(rs.getMetadata().getUid());
178175
pod.getSpec().getContainers().get(0).getPorts()
179-
.add(new ContainerPortBuilder()
180-
.withName("my-custom-port")
181-
.withContainerPort(4009).build());
182-
mockServer.getClient().resource(pod).inNamespace(namespace).createOrReplace();
176+
.add(new ContainerPortBuilder().withName("my-custom-port").withContainerPort(4009).build());
177+
KubeTestUtils.createWithStatusPreserved(client, pod, namespace, Pod.class);
183178

184179
Optional<String> url = discovery.query(kubeURI).map(URI::toString);
185180
assertEquals("http://172.17.0.11:4009", url.get());

0 commit comments

Comments
 (0)