Search in sources :

Example 1 with NoClusterException

use of io.strimzi.test.k8s.exceptions.NoClusterException in project strimzi by strimzi.

the class KubeCluster method bootstrap.

/**
 * Returns the cluster named by the TEST_CLUSTER environment variable, if set, otherwise finds a cluster that's
 * both installed and running.
 * @return The cluster.
 * @throws NoClusterException If no running cluster was found.
 */
static KubeCluster bootstrap() throws NoClusterException {
    Logger logger = LogManager.getLogger(KubeCluster.class);
    KubeCluster[] clusters = null;
    String clusterName = System.getenv(ENV_VAR_TEST_CLUSTER);
    if (clusterName != null) {
        switch(clusterName.toLowerCase(Locale.ENGLISH)) {
            case "oc":
                clusters = new KubeCluster[] { new OpenShift() };
                break;
            case "minikube":
                clusters = new KubeCluster[] { new Minikube() };
                break;
            case "kubernetes":
                clusters = new KubeCluster[] { new Kubernetes() };
                break;
            default:
                throw new IllegalArgumentException(ENV_VAR_TEST_CLUSTER + "=" + clusterName + " is not a supported cluster type");
        }
    }
    if (clusters == null) {
        clusters = new KubeCluster[] { new Minikube(), new Kubernetes(), new OpenShift() };
    }
    KubeCluster cluster = null;
    for (KubeCluster kc : clusters) {
        if (kc.isAvailable()) {
            logger.debug("Cluster {} is installed", kc);
            if (kc.isClusterUp()) {
                logger.debug("Cluster {} is running", kc);
                cluster = kc;
                break;
            } else {
                logger.debug("Cluster {} is not running!", kc);
            }
        } else {
            logger.debug("Cluster {} is not installed!", kc);
        }
    }
    if (cluster == null) {
        throw new NoClusterException("Unable to find a cluster; tried " + Arrays.toString(clusters));
    }
    logger.info("Using cluster: {}", cluster);
    return cluster;
}
Also used : NoClusterException(io.strimzi.test.k8s.exceptions.NoClusterException) Logger(org.apache.logging.log4j.Logger)

Example 2 with NoClusterException

use of io.strimzi.test.k8s.exceptions.NoClusterException in project strimzi by strimzi.

the class TopicOperatorBaseIT method setupKubeCluster.

public static void setupKubeCluster() throws IOException {
    cluster = getInstance();
    VertxOptions options = new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setEnabled(true));
    vertx = Vertx.vertx(options);
    try {
        KubeCluster.bootstrap();
    } catch (NoClusterException e) {
        assumeTrue(false, e.getMessage());
    }
    cmdKubeClient().createNamespace(NAMESPACE);
    oldNamespace = cluster.setNamespace(NAMESPACE);
    LOGGER.info("#### Creating " + "../packaging/install/topic-operator/02-Role-strimzi-topic-operator.yaml");
    cmdKubeClient().create(TestUtils.USER_PATH + "/../packaging/install/topic-operator/02-Role-strimzi-topic-operator.yaml");
    LOGGER.info("#### Creating " + TestUtils.CRD_TOPIC);
    cmdKubeClient().create(TestUtils.CRD_TOPIC);
    LOGGER.info("#### Creating " + TestUtils.USER_PATH + "/src/test/resources/TopicOperatorIT-rbac.yaml");
    cmdKubeClient().create(TestUtils.USER_PATH + "/src/test/resources/TopicOperatorIT-rbac.yaml");
}
Also used : VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) NoClusterException(io.strimzi.test.k8s.exceptions.NoClusterException) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions)

Example 3 with NoClusterException

use of io.strimzi.test.k8s.exceptions.NoClusterException in project strimzi-kafka-operator by strimzi.

the class KubeCluster method bootstrap.

/**
 * Returns the cluster named by the TEST_CLUSTER environment variable, if set, otherwise finds a cluster that's
 * both installed and running.
 * @return The cluster.
 * @throws NoClusterException If no running cluster was found.
 */
static KubeCluster bootstrap() throws NoClusterException {
    Logger logger = LogManager.getLogger(KubeCluster.class);
    KubeCluster[] clusters = null;
    String clusterName = System.getenv(ENV_VAR_TEST_CLUSTER);
    if (clusterName != null) {
        switch(clusterName.toLowerCase(Locale.ENGLISH)) {
            case "oc":
                clusters = new KubeCluster[] { new OpenShift() };
                break;
            case "minikube":
                clusters = new KubeCluster[] { new Minikube() };
                break;
            case "kubernetes":
                clusters = new KubeCluster[] { new Kubernetes() };
                break;
            default:
                throw new IllegalArgumentException(ENV_VAR_TEST_CLUSTER + "=" + clusterName + " is not a supported cluster type");
        }
    }
    if (clusters == null) {
        clusters = new KubeCluster[] { new Minikube(), new Kubernetes(), new OpenShift() };
    }
    KubeCluster cluster = null;
    for (KubeCluster kc : clusters) {
        if (kc.isAvailable()) {
            logger.debug("Cluster {} is installed", kc);
            if (kc.isClusterUp()) {
                logger.debug("Cluster {} is running", kc);
                cluster = kc;
                break;
            } else {
                logger.debug("Cluster {} is not running!", kc);
            }
        } else {
            logger.debug("Cluster {} is not installed!", kc);
        }
    }
    if (cluster == null) {
        throw new NoClusterException("Unable to find a cluster; tried " + Arrays.toString(clusters));
    }
    logger.info("Using cluster: {}", cluster);
    return cluster;
}
Also used : NoClusterException(io.strimzi.test.k8s.exceptions.NoClusterException) Logger(org.apache.logging.log4j.Logger)

Example 4 with NoClusterException

use of io.strimzi.test.k8s.exceptions.NoClusterException in project strimzi-kafka-operator by strimzi.

the class TopicOperatorBaseIT method setupKubeCluster.

public static void setupKubeCluster() throws IOException {
    cluster = getInstance();
    VertxOptions options = new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setEnabled(true));
    vertx = Vertx.vertx(options);
    try {
        KubeCluster.bootstrap();
    } catch (NoClusterException e) {
        assumeTrue(false, e.getMessage());
    }
    cmdKubeClient().createNamespace(NAMESPACE);
    oldNamespace = cluster.setNamespace(NAMESPACE);
    LOGGER.info("#### Creating " + "../packaging/install/topic-operator/02-Role-strimzi-topic-operator.yaml");
    cmdKubeClient().create(TestUtils.USER_PATH + "/../packaging/install/topic-operator/02-Role-strimzi-topic-operator.yaml");
    LOGGER.info("#### Creating " + TestUtils.CRD_TOPIC);
    cmdKubeClient().create(TestUtils.CRD_TOPIC);
    LOGGER.info("#### Creating " + TestUtils.USER_PATH + "/src/test/resources/TopicOperatorIT-rbac.yaml");
    cmdKubeClient().create(TestUtils.USER_PATH + "/src/test/resources/TopicOperatorIT-rbac.yaml");
}
Also used : VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) NoClusterException(io.strimzi.test.k8s.exceptions.NoClusterException) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions)

Aggregations

NoClusterException (io.strimzi.test.k8s.exceptions.NoClusterException)4 VertxOptions (io.vertx.core.VertxOptions)2 MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)2 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)2 Logger (org.apache.logging.log4j.Logger)2