Search in sources :

Example 1 with KubernetesHelper

use of io.fabric8.maven.core.util.kubernetes.KubernetesHelper in project vertx-openshift-it by cescoffier.

the class Kube method setReplicasAndWait.

public static DeploymentConfig setReplicasAndWait(KubernetesClient client, String name, int number) {
    OpenShiftClient oc = oc(client);
    DeploymentConfig config = oc.deploymentConfigs().withName(name).get();
    if (config == null) {
        fail("Unable to find the deployment config " + name);
        return null;
    }
    if (config.getSpec().getReplicas() == number) {
        return config;
    }
    config = oc.deploymentConfigs().withName(name).edit().editSpec().withReplicas(number).endSpec().done();
    if (number == 0) {
        // Wait until no pods
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == 0);
    } else {
        // Wait until the right number of pods
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == number);
        // Wait for readiness
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).stream().filter(KubernetesHelper::isPodReady).count() == number);
    }
    return config;
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Aggregations

DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1