switches the workaround to JsonNode, which produces a cleaner crd (#21788)

Closes #21739
This commit is contained in:
Steven Hawkins 2023-07-19 02:12:44 -04:00 committed by GitHub
parent bab224d0ca
commit ebe6e6c965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View file

@ -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 <vmuzikar@redhat.com>
@ -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());
}
}

View file

@ -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 <T extends HasMetadata> void roundTrip(String resourceFile, Class<T> type) {