Update Operator SDK version
Co-Authored-By: andreaTP <andrea.peruffo1982@gmail.com>
This commit is contained in:
parent
5f0e27a792
commit
046935b9e1
9 changed files with 48 additions and 50 deletions
|
@ -33,7 +33,7 @@
|
|||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<quarkus.operator.sdk.version>3.0.6</quarkus.operator.sdk.version>
|
||||
<quarkus.operator.sdk.version>3.0.7</quarkus.operator.sdk.version>
|
||||
<quarkus.version>2.7.5.Final</quarkus.version>
|
||||
<quarkus.container-image.group>keycloak</quarkus.container-image.group>
|
||||
<quarkus.jib.base-jvm-image>registry.access.redhat.com/ubi8/openjdk-11-runtime</quarkus.jib.base-jvm-image>
|
||||
|
|
|
@ -26,6 +26,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment;
|
|||
import io.fabric8.kubernetes.api.model.batch.v1.Job;
|
||||
import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.client.ResourceNotFoundException;
|
||||
import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil;
|
||||
import io.quarkus.logging.Log;
|
||||
import org.keycloak.operator.OperatorManagedResource;
|
||||
|
@ -55,7 +56,9 @@ public class KeycloakRealmImportJob extends OperatorManagedResource {
|
|||
|
||||
@Override
|
||||
protected Optional<HasMetadata> getReconciledResource() {
|
||||
if (existingJob == null) {
|
||||
if (existingDeployment == null) {
|
||||
throw new ResourceNotFoundException("Keycloak Deployment not found: " + getKeycloakName());
|
||||
} else if (existingJob == null) {
|
||||
Log.info("Creating a new Job");
|
||||
return Optional.of(createImportJob());
|
||||
} else {
|
||||
|
|
8
operator/src/main/resources/example-db-secret.yaml
Normal file
8
operator/src/main/resources/example-db-secret.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: keycloak-db-secret
|
||||
data:
|
||||
username: cG9zdGdyZXM= # postgres
|
||||
password: dGVzdHBhc3N3b3Jk # testpassword
|
||||
type: Opaque
|
21
operator/src/main/resources/example-keycloak.yaml
Normal file
21
operator/src/main/resources/example-keycloak.yaml
Normal file
|
@ -0,0 +1,21 @@
|
|||
apiVersion: k8s.keycloak.org/v2alpha1
|
||||
kind: Keycloak
|
||||
metadata:
|
||||
name: example-kc
|
||||
spec:
|
||||
instances: 1
|
||||
serverConfiguration:
|
||||
- name: db
|
||||
value: postgres
|
||||
- name: db-url-host
|
||||
value: postgres-db
|
||||
- name: db-username
|
||||
secret:
|
||||
name: keycloak-db-secret
|
||||
key: username
|
||||
- name: db-password
|
||||
secret:
|
||||
name: keycloak-db-secret
|
||||
key: password
|
||||
hostname: example.com
|
||||
tlsSecret: example-tls-secret
|
|
@ -1,34 +1,3 @@
|
|||
apiVersion: k8s.keycloak.org/v2alpha1
|
||||
kind: Keycloak
|
||||
metadata:
|
||||
name: example-kc
|
||||
spec:
|
||||
instances: 1
|
||||
serverConfiguration:
|
||||
- name: db
|
||||
value: postgres
|
||||
- name: db-url-host
|
||||
value: postgres-db
|
||||
- name: db-username
|
||||
secret:
|
||||
name: keycloak-db-secret
|
||||
key: username
|
||||
- name: db-password
|
||||
secret:
|
||||
name: keycloak-db-secret
|
||||
key: password
|
||||
hostname: example.com
|
||||
tlsSecret: example-tls-secret
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: keycloak-db-secret
|
||||
data:
|
||||
username: cG9zdGdyZXM= # postgres
|
||||
password: dGVzdHBhc3N3b3Jk # testpassword
|
||||
type: Opaque
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
|
@ -34,7 +34,7 @@ import java.util.UUID;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.keycloak.operator.utils.K8sUtils.getResourceFromMultiResourceFile;
|
||||
import static org.keycloak.operator.utils.K8sUtils.getResourceFromFile;
|
||||
|
||||
public abstract class ClusterOperatorTest {
|
||||
|
||||
|
@ -171,7 +171,7 @@ public abstract class ClusterOperatorTest {
|
|||
}
|
||||
|
||||
protected static void deployDBSecret() {
|
||||
k8sclient.secrets().inNamespace(namespace).createOrReplace((Secret) getResourceFromMultiResourceFile("example-keycloak.yml", 1));
|
||||
k8sclient.secrets().inNamespace(namespace).createOrReplace(getResourceFromFile("example-db-secret.yaml", Secret.class));
|
||||
}
|
||||
|
||||
protected static void deleteDB() {
|
||||
|
|
|
@ -12,11 +12,12 @@ import static java.util.concurrent.TimeUnit.MINUTES;
|
|||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.keycloak.operator.Constants.KEYCLOAK_HTTPS_PORT;
|
||||
import static org.keycloak.operator.utils.K8sUtils.deployKeycloak;
|
||||
import static org.keycloak.operator.utils.K8sUtils.getDefaultKeycloakDeployment;
|
||||
import static org.keycloak.operator.utils.K8sUtils.inClusterCurl;
|
||||
import static org.keycloak.operator.v2alpha1.crds.KeycloakRealmImportStatusCondition.DONE;
|
||||
import static org.keycloak.operator.v2alpha1.crds.KeycloakRealmImportStatusCondition.STARTED;
|
||||
import static org.keycloak.operator.v2alpha1.crds.KeycloakRealmImportStatusCondition.HAS_ERRORS;
|
||||
import static org.keycloak.operator.v2alpha1.crds.KeycloakRealmImportStatusCondition.STARTED;
|
||||
|
||||
@QuarkusTest
|
||||
public class RealmImportE2EIT extends ClusterOperatorTest {
|
||||
|
@ -24,7 +25,7 @@ public class RealmImportE2EIT extends ClusterOperatorTest {
|
|||
@Test
|
||||
public void testWorkingRealmImport() {
|
||||
// Arrange
|
||||
k8sclient.load(getClass().getResourceAsStream("/example-keycloak.yml")).inNamespace(namespace).createOrReplace();
|
||||
deployKeycloak(k8sclient, getDefaultKeycloakDeployment(), false);
|
||||
|
||||
// Act
|
||||
k8sclient.load(getClass().getResourceAsStream("/example-realm.yaml")).inNamespace(namespace).createOrReplace();
|
||||
|
@ -69,7 +70,7 @@ public class RealmImportE2EIT extends ClusterOperatorTest {
|
|||
@Test
|
||||
public void testNotWorkingRealmImport() {
|
||||
// Arrange
|
||||
k8sclient.load(getClass().getResourceAsStream("/example-keycloak.yml")).inNamespace(namespace).createOrReplace();
|
||||
deployKeycloak(k8sclient, getDefaultKeycloakDeployment(), true); // make sure there are no errors due to missing KC Deployment
|
||||
|
||||
// Act
|
||||
k8sclient.load(getClass().getResourceAsStream("/incorrect-realm.yaml")).inNamespace(namespace).createOrReplace();
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.keycloak.operator.utils;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.HasMetadata;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.Secret;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
@ -29,9 +30,6 @@ import org.awaitility.Awaitility;
|
|||
import org.keycloak.operator.v2alpha1.crds.Keycloak;
|
||||
import org.keycloak.operator.v2alpha1.crds.KeycloakStatusCondition;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -40,21 +38,16 @@ import java.util.concurrent.TimeUnit;
|
|||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||
*/
|
||||
public final class K8sUtils {
|
||||
public static <T> T getResourceFromFile(String fileName) {
|
||||
return Serialization.unmarshal(Objects.requireNonNull(K8sUtils.class.getResourceAsStream("/" + fileName)), Collections.emptyMap());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getResourceFromMultiResourceFile(String fileName, int index) {
|
||||
return ((List<T>) getResourceFromFile(fileName)).get(index);
|
||||
public static <T extends HasMetadata> T getResourceFromFile(String fileName, Class<T> type) {
|
||||
return Serialization.unmarshal(Objects.requireNonNull(K8sUtils.class.getResourceAsStream("/" + fileName)), type);
|
||||
}
|
||||
|
||||
public static Keycloak getDefaultKeycloakDeployment() {
|
||||
return getResourceFromMultiResourceFile("example-keycloak.yml", 0);
|
||||
return getResourceFromFile("example-keycloak.yaml", Keycloak.class);
|
||||
}
|
||||
|
||||
public static Secret getDefaultTlsSecret() {
|
||||
return getResourceFromMultiResourceFile("example-keycloak.yml", 2);
|
||||
return getResourceFromFile("example-tls-secret.yaml", Secret.class);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
quarkus.test.hang-detection-timeout=30m
|
||||
|
||||
# we start operator manually during tests
|
||||
quarkus.operator-sdk.start-operator=false
|
Loading…
Reference in a new issue