Search in sources :

Example 16 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.

the class CustomResourceDefinitionTest method testGet.

@Test
void testGet() {
    server.expect().get().withPath("/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/sparkclusters.radanalytics.io").andReturn(200, customResourceDefinition).once();
    CustomResourceDefinition crd = client.apiextensions().v1beta1().customResourceDefinitions().withName("sparkclusters.radanalytics.io").get();
    assertNotNull(crd);
    assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName());
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Example 17 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.

the class SerializationTest method asYamlWithDeserializedCRD.

@Test
void asYamlWithDeserializedCRD() throws Exception {
    // Given
    final String input = readYamlToString("/serialization/test-crd-schema.yml");
    final CustomResourceDefinition crd = Serialization.unmarshal(input, CustomResourceDefinition.class);
    // When
    final String result = Serialization.asYaml(crd);
    // Then
    assertThat(result.trim()).isEqualTo(input.trim());
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Example 18 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.

the class GenericKubernetesResourceExample method main.

public static void main(String[] args) throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder();
    configBuilder.withWatchReconnectInterval(500);
    configBuilder.withWatchReconnectLimit(5);
    try (KubernetesClient client = new KubernetesClientBuilder().withConfig(configBuilder.build()).build()) {
        String namespace = "default";
        CustomResourceDefinition prometheousRuleCrd = client.apiextensions().v1beta1().customResourceDefinitions().load(GenericKubernetesResourceExample.class.getResourceAsStream("/prometheous-rule-crd.yml")).get();
        client.apiextensions().v1beta1().customResourceDefinitions().createOrReplace(prometheousRuleCrd);
        logger.info("Successfully created Prometheous custom resource definition");
        // Creating Custom Resources Now:
        ResourceDefinitionContext crdContext = CustomResourceDefinitionContext.fromCrd(prometheousRuleCrd);
        client.load(GenericKubernetesResourceExample.class.getResourceAsStream("/prometheous-rule-cr.yml")).inNamespace(namespace).createOrReplace();
        logger.info("Created Custom Resource successfully too");
        // Listing all custom resources in given namespace:
        NonNamespaceOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> resourcesInNamespace = client.genericKubernetesResources(crdContext).inNamespace(namespace);
        GenericKubernetesResourceList list = resourcesInNamespace.list();
        List<GenericKubernetesResource> items = list.getItems();
        logger.info("Custom Resources :- ");
        for (GenericKubernetesResource customResource : items) {
            ObjectMeta metadata = customResource.getMetadata();
            final String name = metadata.getName();
            logger.info(name);
        }
        // Watching custom resources now
        logger.info("Watching custom resources now");
        final CountDownLatch closeLatch = new CountDownLatch(1);
        resourcesInNamespace.watch(new Watcher<GenericKubernetesResource>() {

            @Override
            public void eventReceived(Action action, GenericKubernetesResource resource) {
                logger.info("{}: {}", action, resource);
            }

            @Override
            public void onClose(WatcherException e) {
                logger.debug("Watcher onClose");
                closeLatch.countDown();
                if (e != null) {
                    logger.error(e.getMessage(), e);
                }
            }
        });
        closeLatch.await(10, TimeUnit.MINUTES);
        // Cleanup
        logger.info("Deleting custom resources...");
        resourcesInNamespace.withName("prometheus-example-rules").delete();
        client.apiextensions().v1beta1().customResourceDefinitions().withName(prometheousRuleCrd.getMetadata().getName()).delete();
    } catch (KubernetesClientException e) {
        logger.error("Could not create resource: {}", e.getMessage(), e);
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Resource(io.fabric8.kubernetes.client.dsl.Resource) CountDownLatch(java.util.concurrent.CountDownLatch) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) WatcherException(io.fabric8.kubernetes.client.WatcherException) CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) ResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) GenericKubernetesResourceList(io.fabric8.kubernetes.api.model.GenericKubernetesResourceList) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 19 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.

the class ListCustomResourceDefinitions method main.

public static void main(String[] args) {
    try (KubernetesClient client = new KubernetesClientBuilder().build()) {
        if (!client.supportsApiPath("/apis/apiextensions.k8s.io/v1beta1") && !client.supportsApiPath("/apis/apiextensions.k8s.io/v1")) {
            System.out.println("WARNING this cluster does not support the API Group apiextensions.k8s.io");
            return;
        }
        CustomResourceDefinitionList list = client.apiextensions().v1beta1().customResourceDefinitions().list();
        if (list == null) {
            System.out.println("ERROR no list returned!");
            return;
        }
        List<CustomResourceDefinition> items = list.getItems();
        for (CustomResourceDefinition item : items) {
            System.out.println("CustomResourceDefinition " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
        }
    } catch (KubernetesClientException e) {
        System.out.println("Failed: " + e);
        e.printStackTrace();
    }
}
Also used : CustomResourceDefinitionList(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 20 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.

the class V1CustomResourceDefinitionTest method testGet.

@Test
void testGet() {
    server.expect().get().withPath("/apis/apiextensions.k8s.io/v1/customresourcedefinitions/sparkclusters.radanalytics.io").andReturn(HttpURLConnection.HTTP_OK, customResourceDefinition).once();
    CustomResourceDefinition crd = client.apiextensions().v1().customResourceDefinitions().withName("sparkclusters.radanalytics.io").get();
    assertNotNull(crd);
    assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName());
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)60 Test (org.junit.jupiter.api.Test)49 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition)30 Description (io.qameta.allure.Description)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11 IOException (java.io.IOException)11 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 CustomResourceDefinitionBuilder (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder)10 Resource (io.fabric8.kubernetes.client.dsl.Resource)10 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)10 ArrayList (java.util.ArrayList)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 CustomResource (io.fabric8.kubernetes.client.CustomResource)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)7 StartupEvent (io.quarkus.runtime.StartupEvent)7 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)6