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