Skip to content

Commit

Permalink
Merge pull request #34259 from metacosm/fix-openshift-client
Browse files Browse the repository at this point in the history
Properly configure KubernetesSerialization for OpenShiftClient
  • Loading branch information
geoand authored Jun 23, 2023
2 parents 342251c + 4b96820 commit 970fc3b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public void kubernetesClientUsesCustomizedObjectMapper() {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(KubernetesClientCDITest.Customizer.class))
.overrideConfigKey("quarkus.kubernetes-client.devservices.enabled", "false");

@Singleton
Expand Down
5 changes: 5 additions & 0 deletions extensions/openshift-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>quarkus-kubernetes-client-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.quarkus.openshift.client.deployment;

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.openshift.client.OpenShiftClient;
import io.quarkus.kubernetes.client.KubernetesClientObjectMapper;
import io.quarkus.kubernetes.client.KubernetesClientObjectMapperCustomizer;
import io.quarkus.test.QuarkusUnitTest;

public class OpenShiftClientObjectMapperCDITest {

@Inject
OpenShiftClient client;

@Inject
@KubernetesClientObjectMapper
ObjectMapper objectMapper;

@Test
public void kubernetesClientObjectMapperCustomizer() throws JsonProcessingException {
final var result = objectMapper.readValue("{\"quarkusName\":\"the-name\"}", ObjectMeta.class);
assertEquals("the-name", result.getName());
}

@Test
public void kubernetesClientUsesCustomizedObjectMapper() {
final var result = client.getKubernetesSerialization()
.unmarshal("{\"quarkusName\":\"the-name\"}", ObjectMeta.class);
assertEquals("the-name", result.getName());
}

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.overrideConfigKey("quarkus.kubernetes-client.devservices.enabled", "false");

@Singleton
public static class Customizer implements KubernetesClientObjectMapperCustomizer {
@Override
public void customize(ObjectMapper objectMapper) {
objectMapper.addMixIn(ObjectMeta.class, ObjectMetaMixin.class);
}

private static final class ObjectMetaMixin {
@JsonProperty("quarkusName")
String name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import org.jboss.logging.Logger;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.openshift.client.DefaultOpenShiftClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.utils.KubernetesSerialization;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.OpenShiftConfig;
import io.quarkus.arc.DefaultBean;
Expand All @@ -22,11 +23,18 @@ public class OpenShiftClientProducer {
@DefaultBean
@Singleton
@Produces
public OpenShiftClient openShiftClient(Config config) {
public OpenShiftClient openShiftClient(KubernetesSerialization kubernetesSerialization,
Config config) {
// TODO - Temporary fix for https://github.com/fabric8io/kubernetes-client/pull/3347 + WithOpenShiftTestServer
final OpenShiftConfig openShiftConfig = new OpenShiftConfig(config);
openShiftConfig.setHttp2Disable(config.isHttp2Disable());
client = new DefaultOpenShiftClient(openShiftConfig);

client = new KubernetesClientBuilder()
.withConfig(openShiftConfig)
.withKubernetesSerialization(kubernetesSerialization)
.build()
.adapt(OpenShiftClient.class);

return client;
}

Expand Down

0 comments on commit 970fc3b

Please sign in to comment.