8000 switches the workaround to JsonNode, which produces a cleaner crd by shawkins · Pull Request #21788 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
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>
Expand All @@ -37,7 +39,7 @@ public enum Status {
}

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;
Expand All @@ -52,11 +54,11 @@ public void setType(String type) {

@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;
Expand All @@ -70,22 +72,25 @@ public Boolean getStatus() {

@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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -70,6 +71,15 @@ public void testRealmImportWithoutRequiredFields() {
@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) {
Expand Down
0