keycloakCRName and realm are no longer marked as required in KeycloakRealmImport CRD

Closes #21607
This commit is contained in:
Václav Muzikář 2023-07-11 17:43:52 +02:00 committed by Pedro Igor
parent 539eddc5cd
commit 6a3ea1a084
2 changed files with 20 additions and 4 deletions

View file

@ -17,16 +17,15 @@
package org.keycloak.operator.crds.v2alpha1.realmimport; package org.keycloak.operator.crds.v2alpha1.realmimport;
import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import io.fabric8.generator.annotation.Required;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import jakarta.validation.constraints.NotNull;
public class KeycloakRealmImportSpec { public class KeycloakRealmImportSpec {
@NotNull @Required
@JsonPropertyDescription("The name of the Keycloak CR to reference, in the same namespace.") @JsonPropertyDescription("The name of the Keycloak CR to reference, in the same namespace.")
private String keycloakCRName; private String keycloakCRName;
@NotNull @Required
@JsonPropertyDescription("The RealmRepresentation to import into Keycloak.") @JsonPropertyDescription("The RealmRepresentation to import into Keycloak.")
private RealmRepresentation realm; private RealmRepresentation realm;

View file

@ -20,6 +20,7 @@ package org.keycloak.operator.testsuite.integration;
import io.fabric8.junit.jupiter.api.KubernetesTest; import io.fabric8.junit.jupiter.api.KubernetesTest;
import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.Resource;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -30,8 +31,10 @@ import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImportBuilder;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@KubernetesTest @KubernetesTest
public class CRDTest { public class CRDTest {
@ -50,6 +53,20 @@ public class CRDTest {
roundTrip("/test-serialization-realmimport-cr.yml", KeycloakRealmImport.class); roundTrip("/test-serialization-realmimport-cr.yml", KeycloakRealmImport.class);
} }
@Test
public void testRealmImportWithoutRequiredFields() {
KeycloakRealmImport cr = new KeycloakRealmImportBuilder()
.withNewMetadata()
.withName("invalid-realm")
.endMetadata()
.withNewSpec()
.endSpec()
.build();
var eMsg = assertThrows(KubernetesClientException.class, () -> client.resource(cr).create()).getMessage();
assertThat(eMsg).contains("spec.keycloakCRName: Required value", "spec.realm: Required value");
}
@Test @Test
public void testKeycloak() { public void testKeycloak() {
roundTrip("/test-serialization-keycloak-cr.yml", Keycloak.class); roundTrip("/test-serialization-keycloak-cr.yml", Keycloak.class);