Search in sources :

Example 1 with ListNamespacedService

use of com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedService in project yakc by manusa.

the class ServiceService method watch.

@Override
public Observable<WatchEvent<Service>> watch() throws IOException {
    final CoreV1Api api = kubernetesClient.create(CoreV1Api.class);
    return tryWithFallback(() -> {
        api.listServiceForAllNamespaces(new ListServiceForAllNamespaces().limit(1)).get();
        return api.listServiceForAllNamespaces().watch();
    }, () -> {
        final String ns = kubernetesClient.getConfiguration().getNamespace();
        api.listNamespacedService(ns, new ListNamespacedService().limit(1)).get();
        return api.listNamespacedService(ns).watch();
    });
}
Also used : ListNamespacedService(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedService) ListServiceForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListServiceForAllNamespaces) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api)

Example 2 with ListNamespacedService

use of com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedService in project yakc by manusa.

the class ServiceIT method awaitCreateWatch.

@Test
@DisplayName("listNamespacedService.watch, should await for notification of newly created Service")
void awaitCreateWatch() throws IOException {
    // Given
    final AtomicBoolean hasError = new AtomicBoolean(false);
    final AtomicBoolean hasCompleted = new AtomicBoolean(false);
    // When
    final Disposable d = KC.create(CoreV1Api.class).listNamespacedService(NAMESPACE).watch().filter(we -> we.getObject().getMetadata().getName().equals(serviceName)).takeUntil(we -> we.getType() == Type.ADDED).timeout(20, TimeUnit.SECONDS).subscribe(we -> hasCompleted.set(true), we -> hasError.set(true));
    // Then
    assertThat(d).isNotNull();
    assertThat(hasError.get()).as("Watch subscribe ended with an error").isFalse();
    assertThat(hasCompleted.get()).as("Watch subscribe did not complete").isTrue();
}
Also used : Disposable(io.reactivex.disposables.Disposable) BeforeEach(org.junit.jupiter.api.BeforeEach) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) ClusterVersion(com.marcnuri.yakc.ClusterExecutionCondition.ClusterVersion) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) UUID(java.util.UUID) DisplayName(org.junit.jupiter.api.DisplayName) ServicePort(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServicePort) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Disposable(io.reactivex.disposables.Disposable) AfterEach(org.junit.jupiter.api.AfterEach) DeleteOptions(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions) NotFoundException(com.marcnuri.yakc.api.NotFoundException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Service(com.marcnuri.yakc.model.io.k8s.api.core.v1.Service) Type(com.marcnuri.yakc.api.WatchEvent.Type) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with ListNamespacedService

use of com.marcnuri.yakc.api.core.v1.CoreV1Api.ListNamespacedService in project yakc by manusa.

the class ServiceLegacyIT method awaitCreateWatch.

@Test
@DisplayName("listNamespacedService.watch, should await for notification of newly created Service")
void awaitCreateWatch() throws IOException {
    // Given
    final AtomicBoolean hasError = new AtomicBoolean(false);
    final AtomicBoolean hasCompleted = new AtomicBoolean(false);
    // When
    final Disposable d = KC.create(CoreV1Api.class).listNamespacedService(NAMESPACE).watch().filter(we -> we.getObject().getMetadata().getName().equals(serviceName)).takeUntil(we -> we.getType() == Type.ADDED).timeout(20, TimeUnit.SECONDS).subscribe(we -> hasCompleted.set(true), we -> hasError.set(true));
    // Then
    assertThat(d).isNotNull();
    assertThat(hasError.get()).as("Watch subscribe ended with an error").isFalse();
    assertThat(hasCompleted.get()).as("Watch subscribe did not complete").isTrue();
}
Also used : Disposable(io.reactivex.disposables.Disposable) BeforeEach(org.junit.jupiter.api.BeforeEach) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) UUID(java.util.UUID) Status(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.Status) DisplayName(org.junit.jupiter.api.DisplayName) ServicePort(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServicePort) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Disposable(io.reactivex.disposables.Disposable) AfterEach(org.junit.jupiter.api.AfterEach) DeleteOptions(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions) NotFoundException(com.marcnuri.yakc.api.NotFoundException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Service(com.marcnuri.yakc.model.io.k8s.api.core.v1.Service) Type(com.marcnuri.yakc.api.WatchEvent.Type) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CoreV1Api (com.marcnuri.yakc.api.core.v1.CoreV1Api)3 KC (com.marcnuri.yakc.KubernetesClientExtension.KC)2 NotFoundException (com.marcnuri.yakc.api.NotFoundException)2 Type (com.marcnuri.yakc.api.WatchEvent.Type)2 Service (com.marcnuri.yakc.model.io.k8s.api.core.v1.Service)2 ServicePort (com.marcnuri.yakc.model.io.k8s.api.core.v1.ServicePort)2 ServiceSpec (com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceSpec)2 DeleteOptions (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions)2 ObjectMeta (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta)2 Disposable (io.reactivex.disposables.Disposable)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)2 AfterEach (org.junit.jupiter.api.AfterEach)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2