diff --git a/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/KubernetesClientSerializationCustomizerTest.java b/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/KubernetesClientSerializationCustomizerTest.java index 869dda60..996b70a3 100644 --- a/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/KubernetesClientSerializationCustomizerTest.java +++ b/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/KubernetesClientSerializationCustomizerTest.java @@ -11,39 +11,62 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; -import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.client.KubernetesClient; import io.quarkiverse.operatorsdk.runtime.KubernetesClientSerializationCustomizer; +import io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService; +import io.quarkiverse.operatorsdk.test.sources.SimpleCR; +import io.quarkiverse.operatorsdk.test.sources.SimpleSpec; +import io.quarkiverse.operatorsdk.test.sources.SimpleStatus; import io.quarkus.jackson.ObjectMapperCustomizer; +import io.quarkus.kubernetes.client.KubernetesClientObjectMapperCustomizer; import io.quarkus.test.QuarkusUnitTest; public class KubernetesClientSerializationCustomizerTest { @Inject KubernetesClient kubernetesClient; + @Inject + QuarkusConfigurationService service; @Test public void kubernetesClientUsesCustomizedObjectMapper() { - final var result = kubernetesClient.getKubernetesSerialization() - .unmarshal("{\"quarkusName\":\"the-name\"}", ObjectMeta.class); - assertEquals("the-name", result.getName()); + assertEquals(service.getKubernetesClient(), kubernetesClient); + var serialization = kubernetesClient.getKubernetesSerialization(); + var result = serialization + .unmarshal("{\"spec\": {\"mixin\": \"fromMixin\"},\"status\":{\"mixin\": \"fromMixin\"}}", SimpleCR.class); + assertEquals("fromMixin", result.getSpec().value); + assertEquals("fromMixin", result.getStatus().value); + + serialization = service.getKubernetesClient().getKubernetesSerialization(); + result = serialization + .unmarshal("{\"spec\": {\"mixin\": \"fromMixin\"},\"status\":{\"mixin\": \"fromMixin\"}}", SimpleCR.class); + assertEquals("fromMixin", result.getSpec().value); + assertEquals("fromMixin", result.getStatus().value); } @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() - .withApplicationRoot(jar -> jar.addClasses(Customizer.class)); + .withApplicationRoot(jar -> jar.addClasses(Customizer.class, Customizer2.class, ValueMixIn.class, SimpleCR.class, + SimpleSpec.class, SimpleStatus.class)); @Singleton @KubernetesClientSerializationCustomizer public static class Customizer implements ObjectMapperCustomizer { @Override public void customize(ObjectMapper objectMapper) { - objectMapper.addMixIn(ObjectMeta.class, ObjectMetaMixin.class); + objectMapper.addMixIn(SimpleSpec.class, ValueMixIn.class); } + } - private static final class ObjectMetaMixin { - @JsonProperty("quarkusName") - String name; + private static final class ValueMixIn { + @JsonProperty("mixin") + String value; + } + + @Singleton + public static class Customizer2 implements KubernetesClientObjectMapperCustomizer { + public void customize(ObjectMapper objectMapper) { + objectMapper.addMixIn(SimpleStatus.class, ValueMixIn.class); } } } diff --git a/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleSpec.java b/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleSpec.java index b3b482db..f5b97fc2 100644 --- a/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleSpec.java +++ b/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleSpec.java @@ -1,5 +1,5 @@ package io.quarkiverse.operatorsdk.test.sources; public class SimpleSpec { - + public String value; } diff --git a/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleStatus.java b/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleStatus.java index 6733de39..19468e4f 100644 --- a/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleStatus.java +++ b/core/deployment/src/test/java/io/quarkiverse/operatorsdk/test/sources/SimpleStatus.java @@ -1,5 +1,5 @@ package io.quarkiverse.operatorsdk.test.sources; public class SimpleStatus { - + public String value; } diff --git a/core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/BuildTimeControllerConfiguration.java b/core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/BuildTimeControllerConfiguration.java index 6a70ab28..5e233717 100644 --- a/core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/BuildTimeControllerConfiguration.java +++ b/core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/BuildTimeControllerConfiguration.java @@ -22,9 +22,8 @@ public class BuildTimeControllerConfiguration { *

* Note that this is provided as a means to quickly deploy a specific controller to test it by applying the generated * manifests to the target cluster. If empty, no manifests will be generated. The namespace in which the controller will be - * deployed will - * be the currently configured namespace as specified by your {@code .kube/config} file, unless you specify the target - * deployment namespace using the {@code quarkus.kubernetes.namespace} property. + * deployed will be the currently configured namespace as specified by your {@code .kube/config} file, unless you specify + * the target deployment namespace using the {@code quarkus.kubernetes.namespace} property. *

* *