Search in sources :

Example 1 with GenericKubernetesResource

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

the class SharedInformerFactoryImplTest method testSharedIndexInformerForCustomResourceNoType.

@Test
void testSharedIndexInformerForCustomResourceNoType() {
    // Given
    SharedInformerFactory sharedInformerFactory = new SharedInformerFactoryImpl(mockBaseClient, executorService);
    CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder().withKind("Dummy").withScope("Namespaced").withVersion("v1").withGroup("demos.fabric8.io").withPlural("dummies").build();
    // When
    SharedIndexInformer<GenericKubernetesResource> informer = sharedInformerFactory.inNamespace("ns1").sharedIndexInformerForCustomResource(context, 10 * 1000L);
    // Then
    assertThat(informer).isNotNull();
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) SharedInformerFactoryImpl(io.fabric8.kubernetes.client.informers.impl.SharedInformerFactoryImpl) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.jupiter.api.Test)

Example 2 with GenericKubernetesResource

use of io.fabric8.kubernetes.api.model.GenericKubernetesResource 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 3 with GenericKubernetesResource

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

the class CustomResourceTest method testListWithLabels.

@Test
void testListWithLabels() {
    String jsonObject = "{\"metadata\":{\"continue\":\"\",\"resourceVersion\":\"539617\",\"selfLink\":\"test.fabric8.io/v1alpha1/namespaces/ns1/hellos/\"},\"apiVersion\":\"test.fabric8.io/v1alpha1\",\"kind\":\"HelloList\",\"items\":[{\"apiVersion\": \"test.fabric8.io/v1alpha1\",\"kind\": \"Hello\"," + "\"metadata\": {\"name\": \"example-hello\", \"labels\": {\"scope\":\"test\"}},\"spec\": {\"size\": 3},\"uid\":\"3525437a-6a56-11e9-8787-525400b18c1d\"}]}";
    server.expect().get().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos?labelSelector=org%3Dfabric8" + Utils.toUrlEncoded(",") + "scope%3Dtest").andReturn(HttpURLConnection.HTTP_CREATED, jsonObject).once();
    Map<String, String> labels = new HashMap<>();
    labels.put("org", "fabric8");
    labels.put("scope", "test");
    GenericKubernetesResourceList list = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").withLabels(labels).list();
    List<GenericKubernetesResource> items = list.getItems();
    assertNotNull(items);
    assertEquals(1, items.size());
}
Also used : HashMap(java.util.HashMap) GenericKubernetesResourceList(io.fabric8.kubernetes.api.model.GenericKubernetesResourceList) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.jupiter.api.Test)

Example 4 with GenericKubernetesResource

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

the class CustomResourceTest method testGet.

@Test
void testGet() {
    String jsonObject = "{\"apiVersion\": \"test.fabric8.io/v1alpha1\",\"kind\": \"Hello\"," + "\"metadata\": {\"name\": \"example-hello\"},\"spec\": {\"size\": 3}}";
    server.expect().get().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once();
    GenericKubernetesResource customResource = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").withName("example-hello").get();
    assertNotNull(customResource);
    assertEquals("example-hello", customResource.getMetadata().getName());
}
Also used : GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.jupiter.api.Test)

Example 5 with GenericKubernetesResource

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

the class CustomResourceTest method testCreateOrReplace.

@Test
void testCreateOrReplace() throws IOException {
    String jsonObject = "{\"apiVersion\": \"test.fabric8.io/v1alpha1\",\"kind\": \"Hello\"," + "\"metadata\": {\"resourceVersion\":\"1\", \"name\": \"example-hello\"},\"spec\": {\"size\": 3}}";
    server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_INTERNAL_ERROR, new StatusBuilder().build()).once();
    server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CREATED, jsonObject).once();
    server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CONFLICT, jsonObject).once();
    server.expect().put().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once();
    server.expect().get().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once();
    GenericKubernetesResource resource = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").createOrReplace(Serialization.unmarshal(jsonObject, GenericKubernetesResource.class));
    assertEquals("example-hello", resource.getMetadata().getName());
    resource = client.genericKubernetesResources(customResourceDefinitionContext).inNamespace("ns1").createOrReplace(Serialization.unmarshal(jsonObject, GenericKubernetesResource.class));
    assertEquals("example-hello", resource.getMetadata().getName());
}
Also used : StatusBuilder(io.fabric8.kubernetes.api.model.StatusBuilder) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.jupiter.api.Test)

Aggregations

GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)60 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)17 CountDownLatch (java.util.concurrent.CountDownLatch)16 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)12 WatcherException (io.fabric8.kubernetes.client.WatcherException)10 GenericKubernetesResourceList (io.fabric8.kubernetes.api.model.GenericKubernetesResourceList)9 DisplayName (org.junit.jupiter.api.DisplayName)9 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 Watch (io.fabric8.kubernetes.client.Watch)7 IOException (java.io.IOException)7 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)6 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)6 ResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext)6 File (java.io.File)5 Map (java.util.Map)5 GenericKubernetesResourceBuilder (io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3