Skip to content

Commit

Permalink
Update(testsuite): Wait for existence of operator CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
rkubis committed Jan 29, 2025
1 parent 55cf321 commit f82a9d6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
public class Constants {
public static final String CATALOG_NAME = "testsuite-operators";
public static final String CATALOG_NAMESPACE = "openshift-marketplace";
public static final String REGISTRY_CRD_NAME = "apicurioregistries3.registry.apicur.io";
public static final String KAFKA_CONNECT = "kafka-connect-for-registry";
public static final String KAFKA = "kafka-for-registry";
public static final String KAFKA_USER = "kafka-user-for-registry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@ public static void waitCatalogSourceExists(String namespace, String name, Timeou

}

public static void waitCustomResourceDefinitionExists(String name, TimeoutBudget timeout) {
while (!timeout.timeoutExpired()) {
if (Kubernetes.getCustomServiceDefinition(name) != null) {
return;
}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();

return;
}
}

if (Kubernetes.getCustomServiceDefinition(name) == null) {
LOGGER.error("CustomServiceDefinition with name {} failed existence check.", name);

}

}

public static void waitCatalogSourceExists(String namespace, String name) {
waitCatalogSourceExists(namespace, name, TimeoutBudget.ofDuration(Duration.ofMinutes(3)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package io.apicurio.registry.systemtests.operator.types;

import io.apicurio.registry.systemtests.framework.Constants;
import io.apicurio.registry.systemtests.framework.Environment;
import io.apicurio.registry.systemtests.framework.LoggerUtils;
import io.apicurio.registry.systemtests.framework.OperatorUtils;
import io.apicurio.registry.systemtests.framework.ResourceUtils;
import io.apicurio.registry.systemtests.platform.Kubernetes;
import io.apicurio.registry.systemtests.time.TimeoutBudget;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentSpec;
import io.fabric8.kubernetes.api.model.apps.DeploymentStatus;
import org.slf4j.Logger;

import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;

Expand Down Expand Up @@ -104,20 +107,18 @@ public Deployment getDeployment() {
public void install() {
Collection<HasMetadata> resources = getResources();
String namespace = getNamespace();
int timeoutInMinutes = 3;
TimeoutBudget timeoutBudget = TimeoutBudget.ofDuration(Duration.ofMinutes(timeoutInMinutes));

for (HasMetadata resource : resources) {
LOGGER.info("Creating {}...", resource.getKind());

Kubernetes.createOrReplaceResource(namespace, resource);

if (resource.getKind().equals("CustomResourceDefinition")) {
try {
LOGGER.info("Waiting for 5 seconds for CustomResourceDefinition creation...");
LOGGER.info("Waiting for {} minutes for CustomResourceDefinition existence...", timeoutInMinutes);

Thread.sleep(5_000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
OperatorUtils.waitCustomResourceDefinitionExists(Constants.REGISTRY_CRD_NAME, timeoutBudget);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSetStatus;
Expand Down Expand Up @@ -408,6 +409,15 @@ public static void deleteSubscription(String namespace, String name) {
.delete();
}

public static CustomResourceDefinition getCustomServiceDefinition(String name) {
return getClient()
.apiextensions()
.v1()
.customResourceDefinitions()
.withName(name)
.get();
}

public static ClusterServiceVersion getClusterServiceVersion(String namespace, String name) {
return ((OpenShiftClient) getClient())
.operatorHub()
Expand Down

0 comments on commit f82a9d6

Please sign in to comment.