Search in sources :

Example 1 with ListOptions

use of io.fabric8.kubernetes.api.model.ListOptions in project kubernetes-client by fabric8io.

the class CustomResourceTest method testWatchWithListOptions.

@Test
@DisplayName("Should be able to test watch with ListOptions provided")
void testWatchWithListOptions() throws IOException, InterruptedException {
    // Given
    server.expect().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos?resourceVersion=1003&timeoutSeconds=30&allowWatchBookmarks=true&watch=true").andUpgradeToWebSocket().open().waitFor(WATCH_EVENT_PERIOD).andEmit("{\"type\":\"ADDED\", \"object\":{\"kind\": \"Hello\", \"metadata\": {\"resourceVersion\": 1003}}}").done().always();
    CountDownLatch anyEventReceived = new CountDownLatch(1);
    // When
    Watch watch = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").watch(new ListOptionsBuilder().withTimeoutSeconds(30L).withResourceVersion("1003").withAllowWatchBookmarks(true).build(), new Watcher<GenericKubernetesResource>() {

        @Override
        public void eventReceived(Action action, GenericKubernetesResource resource) {
            anyEventReceived.countDown();
        }

        @Override
        public void onClose(WatcherException cause) {
        }
    });
    // Then
    assertTrue(anyEventReceived.await(1, TimeUnit.SECONDS));
    watch.close();
}
Also used : Watch(io.fabric8.kubernetes.client.Watch) ListOptionsBuilder(io.fabric8.kubernetes.api.model.ListOptionsBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) WatcherException(io.fabric8.kubernetes.client.WatcherException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with ListOptions

use of io.fabric8.kubernetes.api.model.ListOptions in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaResourceType method readiness.

@Override
public Predicate<ManagedKafka> readiness(KubeClient client) {
    AtomicInteger count = new AtomicInteger();
    Set<String> messages = Collections.synchronizedSet(new LinkedHashSet<>());
    return mk -> {
        if (mk == null) {
            throw new IllegalStateException("ManagedKafka is null");
        }
        ManagedKafkaCondition mkc = getCondition(mk.getStatus(), ManagedKafkaCondition.Type.Ready).orElse(null);
        if (mkc == null) {
            return false;
        }
        if (ManagedKafkaCondition.Status.True.name().equals(mkc.getStatus())) {
            return true;
        }
        if (ManagedKafkaCondition.Reason.Error.name().equals(mkc.getReason())) {
            if (messages.add(mkc.getMessage())) {
                LOGGER.warn("ManagedKafka {} in error state {}", mk.getMetadata().getName(), mkc.getMessage());
            }
        // throw new IllegalStateException(String.format("ManagedKafka %s in error state %s", mk.getMetadata().getName(), mkc.getMessage()));
        }
        if (count.getAndIncrement() % 15 == 0) {
            ListOptions opts = new ListOptionsBuilder().withFieldSelector("status.phase=Pending").build();
            client.client().pods().inNamespace(mk.getMetadata().getNamespace()).withLabel("strimzi.io/cluster").list(opts).getItems().forEach(ManagedKafkaResourceType::checkUnschedulablePod);
        }
        return false;
    };
}
Also used : KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) ListOptionsBuilder(io.fabric8.kubernetes.api.model.ListOptionsBuilder) ListOptions(io.fabric8.kubernetes.api.model.ListOptions) Resource(io.fabric8.kubernetes.client.dsl.Resource) KubeClient(org.bf2.test.k8s.KubeClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedKafkaStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus) LinkedHashSet(java.util.LinkedHashSet) KeycloakInstance(org.bf2.systemtest.framework.KeycloakInstance) SecurityUtils(org.bf2.systemtest.framework.SecurityUtils) Predicate(java.util.function.Predicate) TestUtils(org.bf2.test.TestUtils) Pod(io.fabric8.kubernetes.api.model.Pod) SystemTestEnvironment(org.bf2.systemtest.framework.SystemTestEnvironment) Set(java.util.Set) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) Optional(java.util.Optional) Kafka(io.strimzi.api.kafka.model.Kafka) LogManager(org.apache.logging.log4j.LogManager) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ListOptions(io.fabric8.kubernetes.api.model.ListOptions) ListOptionsBuilder(io.fabric8.kubernetes.api.model.ListOptionsBuilder) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)

Example 3 with ListOptions

use of io.fabric8.kubernetes.api.model.ListOptions in project kubernetes-client by fabric8io.

the class CustomResourceTest method testWatchWithNamespaceAndListOptions.

@Test
@DisplayName("Should be able to test watch with Namespace and ListOptions provided")
void testWatchWithNamespaceAndListOptions() throws IOException, InterruptedException {
    // Given
    server.expect().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos?resourceVersion=1003&timeoutSeconds=30&allowWatchBookmarks=true&watch=true").andUpgradeToWebSocket().open().waitFor(WATCH_EVENT_PERIOD).andEmit("{\"type\":\"ADDED\", \"object\":{\"kind\": \"Hello\", \"metadata\": {\"resourceVersion\": 1003}}}").done().always();
    CountDownLatch anyEventReceived = new CountDownLatch(1);
    // When
    Watch watch = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").watch(new ListOptionsBuilder().withTimeoutSeconds(30L).withResourceVersion("1003").withAllowWatchBookmarks(true).build(), new Watcher<GenericKubernetesResource>() {

        @Override
        public void eventReceived(Action action, GenericKubernetesResource resource) {
            anyEventReceived.countDown();
        }

        @Override
        public void onClose(WatcherException cause) {
        }
    });
    // Then
    assertTrue(anyEventReceived.await(1, TimeUnit.SECONDS));
    watch.close();
}
Also used : Watch(io.fabric8.kubernetes.client.Watch) ListOptionsBuilder(io.fabric8.kubernetes.api.model.ListOptionsBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) WatcherException(io.fabric8.kubernetes.client.WatcherException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with ListOptions

use of io.fabric8.kubernetes.api.model.ListOptions in project kubernetes-client by fabric8io.

the class CustomResourceTest method testWatchAllResource.

@Test
@DisplayName("Should be able to watch some resource in a namespace with null name, labelSelector and ListOptions")
void testWatchAllResource() throws IOException, InterruptedException {
    // Given
    server.expect().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos?allowWatchBookmarks=true&watch=true").andUpgradeToWebSocket().open().waitFor(WATCH_EVENT_PERIOD).andEmit("{\"type\":\"ADDED\", \"object\":{\"kind\": \"Hello\", \"metadata\": {\"resourceVersion\": 1003}}}").done().always();
    CountDownLatch anyEventReceived = new CountDownLatch(1);
    // When
    Watch watch = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").watch(new Watcher<GenericKubernetesResource>() {

        @Override
        public void eventReceived(Action action, GenericKubernetesResource resource) {
            anyEventReceived.countDown();
        }

        @Override
        public void onClose(WatcherException cause) {
        }
    });
    // Then
    assertTrue(anyEventReceived.await(1, TimeUnit.SECONDS));
    watch.close();
}
Also used : Watch(io.fabric8.kubernetes.client.Watch) CountDownLatch(java.util.concurrent.CountDownLatch) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) WatcherException(io.fabric8.kubernetes.client.WatcherException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)3 ListOptionsBuilder (io.fabric8.kubernetes.api.model.ListOptionsBuilder)3 Watch (io.fabric8.kubernetes.client.Watch)3 WatcherException (io.fabric8.kubernetes.client.WatcherException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 KubernetesResourceList (io.fabric8.kubernetes.api.model.KubernetesResourceList)1 ListOptions (io.fabric8.kubernetes.api.model.ListOptions)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 Kafka (io.strimzi.api.kafka.model.Kafka)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1