From 6a3ea1a084bf7cf844c9330a42b425f2cb927760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Muzik=C3=A1=C5=99?= Date: Tue, 11 Jul 2023 17:43:52 +0200 Subject: [PATCH] `keycloakCRName` and `realm` are no longer marked as required in KeycloakRealmImport CRD Closes #21607 --- .../realmimport/KeycloakRealmImportSpec.java | 7 +++---- .../operator/testsuite/integration/CRDTest.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java b/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java index 11a2a1846d..22507736cb 100644 --- a/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java +++ b/operator/src/main/java/org/keycloak/operator/crds/v2alpha1/realmimport/KeycloakRealmImportSpec.java @@ -17,16 +17,15 @@ package org.keycloak.operator.crds.v2alpha1.realmimport; import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import io.fabric8.generator.annotation.Required; import org.keycloak.representations.idm.RealmRepresentation; -import jakarta.validation.constraints.NotNull; - public class KeycloakRealmImportSpec { - @NotNull + @Required @JsonPropertyDescription("The name of the Keycloak CR to reference, in the same namespace.") private String keycloakCRName; - @NotNull + @Required @JsonPropertyDescription("The RealmRepresentation to import into Keycloak.") private RealmRepresentation realm; 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 f75d3bb54d..58feb08a26 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 @@ -20,6 +20,7 @@ package org.keycloak.operator.testsuite.integration; import io.fabric8.junit.jupiter.api.KubernetesTest; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.Resource; import org.junit.jupiter.api.BeforeAll; @@ -30,8 +31,10 @@ import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport; import java.io.FileNotFoundException; 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.junit.jupiter.api.Assertions.assertThrows; @KubernetesTest public class CRDTest { @@ -50,6 +53,20 @@ public class CRDTest { 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 public void testKeycloak() { roundTrip("/test-serialization-keycloak-cr.yml", Keycloak.class);