Search in sources :

Example 51 with Watch

use of io.fabric8.kubernetes.client.Watch in project zeppelin by apache.

the class PodPhaseWatcherTest method testPhaseWithError.

@Test
@Ignore("Reamer - ZEPPELIN-5403")
public void testPhaseWithError() throws InterruptedException {
    KubernetesClient client = server.getClient();
    // CREATE
    client.pods().inNamespace("ns1").create(new PodBuilder().withNewMetadata().withName("pod1").endMetadata().build());
    // READ
    PodList podList = client.pods().inNamespace("ns1").list();
    assertNotNull(podList);
    assertEquals(1, podList.getItems().size());
    // WATCH
    PodPhaseWatcher podWatcher = new PodPhaseWatcher(phase -> StringUtils.equalsAnyIgnoreCase(phase, "Succeeded", "Failed", "Running"));
    Watch watch = client.pods().inNamespace("ns1").withName("pod1").watch(podWatcher);
    // In the case of close, we do not block thread execution
    watch.close();
    assertTrue(podWatcher.getCountDownLatch().await(1, TimeUnit.SECONDS));
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodList(io.fabric8.kubernetes.api.model.PodList) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Watch(io.fabric8.kubernetes.client.Watch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 52 with Watch

use of io.fabric8.kubernetes.client.Watch in project fabric8 by fabric8io.

the class KubernetesConfigAdminBridgeTest method testAndOr.

@Test
public void testAndOr() {
    System.setProperty("fabric8.pid.filters", "appName=A;B,database.name=my.oracle.datasource");
    KubernetesMockServer plainServer = new KubernetesMockServer(false);
    plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A,B),database.name%20in%20(my.oracle.datasource)&watch=true").andReturnChunked(200).always();
    plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A,B),database.name%20in%20(my.oracle.datasource)").andReturn(200, cmEmptyList).once();
    KubernetesConfigAdminBridge kcab = new KubernetesConfigAdminBridge();
    kcab.bindConfigAdmin(caService);
    kcab.bindKubernetesClient(plainServer.createClient());
    kcab.activate();
}
Also used : KubernetesMockServer(io.fabric8.kubernetes.client.server.mock.KubernetesMockServer) Test(org.junit.Test)

Example 53 with Watch

use of io.fabric8.kubernetes.client.Watch in project fabric8 by fabric8io.

the class KubernetesConfigAdminBridgeTest method testAand.

@Test
public void testAand() {
    System.setProperty("fabric8.pid.filters", "appName=A,database.name=my.oracle.datasource");
    KubernetesMockServer plainServer = new KubernetesMockServer(false);
    plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A),database.name%20in%20(my.oracle.datasource)&watch=true").andReturnChunked(200).always();
    plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A),database.name%20in%20(my.oracle.datasource)").andReturn(200, cmEmptyList).once();
    KubernetesConfigAdminBridge kcab = new KubernetesConfigAdminBridge();
    kcab.bindConfigAdmin(caService);
    kcab.bindKubernetesClient(plainServer.createClient());
    kcab.activate();
}
Also used : KubernetesMockServer(io.fabric8.kubernetes.client.server.mock.KubernetesMockServer) Test(org.junit.Test)

Example 54 with Watch

use of io.fabric8.kubernetes.client.Watch in project fabric8 by fabric8io.

the class PodSelectionAssert method isPodReadyForPeriod.

/**
 * Asserts that a pod is ready for this deployment all become ready within the given time and that each one keeps being ready for the given time
 */
public PodSelectionAssert isPodReadyForPeriod(long notReadyTimeoutMS, long readyPeriodMS) {
    if (replicas.intValue() <= 0) {
        LOG.warn("Not that the pod selection for: " + description + " has no replicas defined so we cannot assert there is a pod ready");
        return this;
    }
    try (PodWatcher podWatcher = new PodWatcher(this, notReadyTimeoutMS, readyPeriodMS);
        Watch watch = client.pods().withLabels(matchLabels).watch(podWatcher)) {
        podWatcher.loadCurrentPods();
        podWatcher.waitForPodReady();
    }
    return this;
}
Also used : Watch(io.fabric8.kubernetes.client.Watch) PodWatcher(io.fabric8.kubernetes.assertions.support.PodWatcher)

Example 55 with Watch

use of io.fabric8.kubernetes.client.Watch in project fabric8 by fabric8io.

the class WatchPodsExample method main.

public static void main(String... args) throws Exception {
    KubernetesClient client = new DefaultKubernetesClient();
    client.pods().watch(new io.fabric8.kubernetes.client.Watcher<Pod>() {

        @Override
        public void eventReceived(Action action, Pod pod) {
            System.out.println(action + ": " + pod);
        }

        @Override
        public void onClose(KubernetesClientException e) {
            System.out.println("Closed: " + e);
        }
    });
    client.close();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

Watch (io.fabric8.kubernetes.client.Watch)19 Pod (io.fabric8.kubernetes.api.model.Pod)16 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)16 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)13 Watcher (io.fabric8.kubernetes.client.Watcher)11 Test (org.junit.Test)10 PodList (io.fabric8.kubernetes.api.model.PodList)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 KubernetesMockServer (io.fabric8.kubernetes.client.server.mock.KubernetesMockServer)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 PodListBuilder (io.fabric8.kubernetes.api.model.PodListBuilder)4 Service (io.fabric8.kubernetes.api.model.Service)4