From ebe6e6c965f656fa6d2138bc74fcc498cbc6af89 Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Wed, 19 Jul 2023 02:12:44 -0400 Subject: [PATCH] switches the workaround to JsonNode, which produces a cleaner crd (#21788) Closes #21739 --- .../crds/v2alpha1/StatusCondition.java | 21 ++++++++++++------- .../testsuite/integration/CRDTest.java | 10 +++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/StatusCondition.java b/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/StatusCondition.java index b9ebc5b06f..2033256785 100644 --- a/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/StatusCondition.java +++ b/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/StatusCondition.java @@ -24,6 +24,8 @@ import java.util.Objects; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.TextNode; /** * @author Vaclav Muzikar @@ -37,7 +39,7 @@ public class StatusCondition { } private String type; - private AnyType status = new AnyType(Status.Unknown.name()); + private JsonNode status = TextNode.valueOf(Status.Unknown.name()); private String message; private String lastTransitionTime; private Long observedGeneration; @@ -52,11 +54,11 @@ public class StatusCondition { @JsonIgnore public Boolean getStatus() { - if (status == null || status.getValue() == null) { + if (status == null || status.isNull()) { return null; } // account for the legacy boolean string as well - switch ((String)status.getValue()) { + switch (status.asText()) { case "false": case "False": return false; @@ -70,22 +72,25 @@ public class StatusCondition { @JsonProperty("status") public String getStatusString() { - return (String)status.getValue(); + if (status == null || status.isNull()) { + return null; + } + return status.asText(); } @JsonProperty("status") public void setStatusString(String status) { - this.status = new AnyType(status); + this.status = TextNode.valueOf(status); } @JsonIgnore public void setStatus(Boolean status) { if (status == null) { - this.status = new AnyType(Status.Unknown.name()); + this.status = TextNode.valueOf(Status.Unknown.name()); } else if (status) { - this.status = new AnyType(Status.True.name()); + this.status = TextNode.valueOf(Status.True.name()); } else { - this.status = new AnyType(Status.False.name()); + this.status = TextNode.valueOf(Status.False.name()); } } diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/CRDTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/CRDTest.java index 58feb08a26..ccd8812ce4 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/CRDTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/CRDTest.java @@ -26,6 +26,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak; +import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatusAggregator; import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport; import java.io.FileNotFoundException; @@ -70,6 +71,15 @@ public class CRDTest { @Test public void testKeycloak() { roundTrip("/test-serialization-keycloak-cr.yml", Keycloak.class); + + // ensure that server side apply works + var kc = client.resources(Keycloak.class).withName("test-serialization-kc").get(); + kc.setStatus(new KeycloakStatusAggregator(1L).build()); + kc = client.resource(kc).updateStatus(); + kc.getMetadata().setManagedFields(null); + kc.getMetadata().getAnnotations().put("x", "y"); + kc = client.resource(kc).serverSideApply(); + assertThat(kc.getMetadata().getAnnotations()).containsEntry("x", "y"); } private void roundTrip(String resourceFile, Class type) {