Search in sources :

Example 71 with CustomResourceDefinition

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

the class ChildCRDTest method testCrd.

@Test
void testCrd() {
    CustomResourceDefinition d = Serialization.unmarshal(getClass().getClassLoader().getResourceAsStream("META-INF/fabric8/children.acme.com-v1.yml"), CustomResourceDefinition.class);
    assertNotNull(d);
    assertEquals("Child", d.getSpec().getNames().getKind());
    assertEquals("children", d.getSpec().getNames().getPlural());
    assertEquals("Namespaced", d.getSpec().getScope());
    assertTrue(d.getSpec().getVersions().stream().anyMatch(v -> v.getSubresources() != null));
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Serialization(io.fabric8.kubernetes.client.utils.Serialization) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Example 72 with CustomResourceDefinition

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

the class ZookeeperCustomResourceTest method testCrd.

@Test
void testCrd() {
    CustomResourceDefinition d = Serialization.unmarshal(getClass().getClassLoader().getResourceAsStream("META-INF/fabric8/zookeepers.io.zookeeper-v1beta1.yml"), CustomResourceDefinition.class);
    assertNotNull(d);
    assertEquals("Zookeeper", d.getSpec().getNames().getKind());
    assertEquals("zookeepers", d.getSpec().getNames().getPlural());
    assertEquals("Namespaced", d.getSpec().getScope());
    assertNotNull(d.getSpec().getSubresources());
    assertEquals(".status.size", d.getSpec().getSubresources().getScale().getStatusReplicasPath());
    assertEquals(".spec.size", d.getSpec().getSubresources().getScale().getSpecReplicasPath());
    assertNotNull(d.getSpec().getSubresources().getStatus());
    Optional<CustomResourceDefinitionVersion> v1 = d.getSpec().getVersions().stream().filter(v -> v.getName().equals("v1")).findFirst();
    assertTrue(v1.isPresent());
    v1.ifPresent(v -> {
        // Let's check that version is marked as required
        Object spec = v.getSchema().getOpenAPIV3Schema().getProperties().get("spec");
        assertNotNull(spec);
        JSONSchemaProps props = (JSONSchemaProps) spec;
        List<String> required = props.getRequired();
        assertTrue(required.contains("version"));
    });
    Optional<CustomResourceDefinitionVersion> v1alpha1 = d.getSpec().getVersions().stream().filter(v -> v.getName().equals("v1alpha1")).findFirst();
    assertTrue(v1alpha1.isPresent());
    v1.ifPresent(v -> {
        // Let's check that version is marked as required
        Object spec = v.getSchema().getOpenAPIV3Schema().getProperties().get("spec");
        assertNotNull(spec);
        JSONSchemaProps props = (JSONSchemaProps) spec;
        List<String> required = props.getRequired();
        assertTrue(required.contains("version"));
    });
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JSONSchemaProps(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.JSONSchemaProps) List(java.util.List) Serialization(io.fabric8.kubernetes.client.utils.Serialization) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersion) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) JSONSchemaProps(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.JSONSchemaProps) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersion) Test(org.junit.jupiter.api.Test)

Example 73 with CustomResourceDefinition

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

the class CustomResourceV1Example method main.

@SuppressWarnings("java:S106")
public static void main(String... args) {
    try (KubernetesClient kc = new KubernetesClientBuilder().build()) {
        // @formatter:off
        final CustomResourceDefinition crd = CustomResourceDefinitionContext.v1CRDFromCustomResourceType(Show.class).editSpec().editVersion(0).withNewSchema().withNewOpenAPIV3Schema().withTitle("Shows").withType("object").addToRequired("spec").addToProperties("spec", new JSONSchemaPropsBuilder().withType("object").addToProperties("name", new JSONSchemaPropsBuilder().withType("string").build()).addToProperties("score", new JSONSchemaPropsBuilder().withType("number").build()).build()).endOpenAPIV3Schema().endSchema().endVersion().endSpec().build();
        // @formatter:on
        kc.apiextensions().v1().customResourceDefinitions().createOrReplace(crd);
        System.out.println("Created custom shows.example.com Kubernetes API");
        final NonNamespaceOperation<Show, ShowList, Resource<Show>> shows = kc.customResources(Show.class, ShowList.class).inNamespace("default");
        shows.list();
        shows.createOrReplace(new Show("breaking-bad", new ShowSpec("Breaking Bad", 10)));
        shows.createOrReplace(new Show("better-call-saul", new ShowSpec("Better call Saul", 8)));
        shows.createOrReplace(new Show("the-wire", new ShowSpec("The Wire", 10)));
        System.out.println("Added three shows");
        shows.list().getItems().forEach(s -> System.out.printf(" - %s%n", s.getSpec().name));
        final Show theWire = shows.withName("the-wire").fromServer().get();
        System.out.printf("The Wire Score is: %s%n", theWire.getSpec().score);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) JSONSchemaPropsBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaPropsBuilder) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Resource(io.fabric8.kubernetes.client.dsl.Resource) CustomResource(io.fabric8.kubernetes.client.CustomResource)

Example 74 with CustomResourceDefinition

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

the class CRDLoadExample method main.

public static void main(String[] args) {
    try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
        // List all Custom resources.
        logger.info("Listing all current Custom Resource Definitions :");
        CustomResourceDefinitionList crdList = client.apiextensions().v1beta1().customResourceDefinitions().list();
        crdList.getItems().forEach(crd -> logger.info(crd.getMetadata().getName()));
        // Creating a custom resource from yaml
        CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1beta1().customResourceDefinitions().load(CRDLoadExample.class.getResourceAsStream("/crd.yml")).get();
        logger.info("Creating CRD...");
        client.apiextensions().v1beta1().customResourceDefinitions().create(aCustomResourceDefinition);
        logger.info("Updated Custom Resource Definitions: ");
        client.apiextensions().v1beta1().customResourceDefinitions().list().getItems().forEach(crd -> logger.info(crd.getMetadata().getName()));
    }
}
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)

Example 75 with CustomResourceDefinition

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

the class ApprovalTest method testKeycloakCrd.

@Test
void testKeycloakCrd() {
    // Arrange
    CustomResourceDefinition crd = getCRD("keycloak-crd.yml");
    // Act
    List<WritableCRCompilationUnit> writables = runner.generate(crd, runner.getPackage("test.org"));
    // Assert
    assertEquals(1, writables.size());
    assertThat(writables.size()).isEqualTo(1);
    WritableCRCompilationUnit writable = writables.get(0);
    List<String> underTest = new ArrayList<>();
    List<GeneratorResult.ClassResult> crl = writable.getClassResults();
    underTest.add(getJavaClass(crl, "Keycloak"));
    underTest.add(getJavaClass(crl, "KeycloakSpec"));
    underTest.add(getJavaClass(crl, "KeycloakStatus"));
    Approvals.verifyAll("KeycloakJavaCr", underTest);
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) ArrayList(java.util.ArrayList) 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