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();
}
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;
};
}
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();
}
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();
}
Aggregations