use of io.fabric8.kubernetes.api.model.ListOptionsBuilder 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.ListOptionsBuilder in project kubernetes-client by fabric8io.
the class WatchTest method testTryWithResourcesConnectsThenReceivesEventBookmark.
@Test
@DisplayName("TryWithResources, connects and receives event then receives GONE, should receive first event and then close")
void testTryWithResourcesConnectsThenReceivesEventBookmark() throws InterruptedException {
// Given
server.expect().withPath("/api/v1/namespaces/test/pods?fieldSelector=metadata.name%3Dpod1&resourceVersion=1&allowWatchBookmarks=true&watch=true").andUpgradeToWebSocket().open().waitFor(EVENT_WAIT_PERIOD_MS).andEmit(new WatchEvent(pod1, "BOOKMARK")).waitFor(EVENT_WAIT_PERIOD_MS).andEmit(outdatedEvent()).done().once();
final CountDownLatch bookmarkLatch = new CountDownLatch(1);
final CountDownLatch closeLatch = new CountDownLatch(1);
final Watcher<Pod> watcher = new Watcher<Pod>() {
@Override
public void eventReceived(Action action, Pod resource) {
if (action != BOOKMARK) {
fail();
}
bookmarkLatch.countDown();
}
@Override
public void onClose(WatcherException cause) {
assertTrue(cause.isHttpGone());
closeLatch.countDown();
}
};
// When
try (Watch watch = client.pods().withName("pod1").withResourceVersion("1").watch(new ListOptionsBuilder().withAllowWatchBookmarks(true).build(), watcher)) {
// Then
assertNotNull(watch);
assertTrue(bookmarkLatch.await(10, TimeUnit.SECONDS));
assertTrue(closeLatch.await(10, TimeUnit.SECONDS));
}
}
use of io.fabric8.kubernetes.api.model.ListOptionsBuilder in project dubbo-spi-extensions by apache.
the class KubernetesMeshEnvListener method subscribeVs.
private void subscribeVs(String appName) {
if (vsAppWatch.containsKey(appName)) {
return;
}
try {
Watch watch = kubernetesClient.customResource(MeshConstant.getVsDefinition()).watch(namespace, appName, null, new ListOptionsBuilder().build(), new Watcher<String>() {
@Override
public void eventReceived(Action action, String resource) {
logger.info("Received VS Rule notification. AppName: " + appName + " Action:" + action + " Resource:" + resource);
if (action == Action.ADDED || action == Action.MODIFIED) {
Map drRuleMap = new Gson().fromJson(resource, Map.class);
String vsRule = new Yaml(new SafeConstructor()).dump(drRuleMap);
vsAppCache.put(appName, vsRule);
if (drAppCache.containsKey(appName)) {
notifyListener(vsRule, appName, drAppCache.get(appName));
}
} else {
appRuleListenerMap.get(appName).receiveConfigInfo("");
}
}
@Override
public void onClose(WatcherException cause) {
// ignore
}
});
vsAppWatch.put(appName, watch);
try {
Map<String, Object> vsRule = kubernetesClient.customResource(MeshConstant.getVsDefinition()).get(namespace, appName);
vsAppCache.put(appName, new Yaml(new SafeConstructor()).dump(vsRule));
} catch (Throwable ignore) {
}
} catch (IOException e) {
logger.error("Error occurred when listen kubernetes crd.", e);
}
}
use of io.fabric8.kubernetes.api.model.ListOptionsBuilder 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.ListOptionsBuilder 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();
}
Aggregations