Search in sources :

Example 76 with CustomResourceDefinition

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

the class ApprovalTest method testCrontabCrd.

@Test
void testCrontabCrd() {
    // Arrange
    CustomResourceDefinition crd = getCRD("crontab-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, "CronTab"));
    underTest.add(getJavaClass(crl, "CronTabSpec"));
    underTest.add(getJavaClass(crl, "CronTabStatus"));
    Approvals.verifyAll("CrontabJavaCr", underTest);
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 77 with CustomResourceDefinition

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

the class ApprovalTest method testJokeCrd.

@Test
void testJokeCrd() {
    // Arrange
    CustomResourceDefinition crd = getCRD("jokerequests-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, "JokeRequest"));
    underTest.add(getJavaClass(crl, "JokeRequestSpec"));
    underTest.add(getJavaClass(crl, "JokeRequestStatus"));
    Approvals.verifyAll("JokeRequestJavaCr", underTest);
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 78 with CustomResourceDefinition

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

the class CRGeneratorRunner method runOnSingleSource.

private void runOnSingleSource(File source, File basePath) {
    try (FileInputStream fis = new FileInputStream(source)) {
        List<HasMetadata> resources = new ArrayList<>();
        Object deserialized = Serialization.unmarshal(fis, Collections.emptyMap());
        if (deserialized instanceof List) {
            resources.addAll((List<HasMetadata>) deserialized);
        } else {
            resources.add((CustomResourceDefinition) deserialized);
        }
        resources.parallelStream().forEach(resource -> {
            if (resource.getKind().toLowerCase(Locale.ROOT).equals("customresourcedefinition")) {
                CustomResourceDefinition crd = (CustomResourceDefinition) resource;
                String pkg = getPackage(crd.getSpec().getGroup());
                List<WritableCRCompilationUnit> writables = generate(crd, pkg);
                writables.parallelStream().forEach(w -> w.writeAllJavaClasses(basePath, pkg));
            } else {
                LOGGER.warn("Not generating nothing for resource of kind: " + resource.getKind());
            }
        });
    } catch (FileNotFoundException e) {
        throw new JavaGeneratorException("File " + source.getAbsolutePath() + " not found", e);
    } catch (IOException e) {
        throw new JavaGeneratorException("Exception reading " + source.getAbsolutePath(), e);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) JCRObject(io.fabric8.java.generator.nodes.JCRObject) JavaGeneratorException(io.fabric8.java.generator.exceptions.JavaGeneratorException)

Example 79 with CustomResourceDefinition

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

the class GenericResourceIT method testGenericCustomResourceWithoutMetadata.

@Test
public void testGenericCustomResourceWithoutMetadata() {
    CustomResourceDefinition crd1 = client.apiextensions().v1().customResourceDefinitions().createOrReplace(createCRD());
    assertThat(crd1).isNotNull();
    Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> client.getApiResources("examples.fabric8.io/v1") != null);
    GenericKubernetesResource itest = new GenericKubernetesResource();
    itest.setKind("Itest");
    itest.setApiVersion("examples.fabric8.io/v1");
    itest.setMetadata(new ObjectMetaBuilder().withName("my-itest").build());
    NamespaceableResource<GenericKubernetesResource> resource = client.resource(itest);
    GenericKubernetesResource result = resource.createOrReplace();
    assertNotNull(result);
    // ensure the namespace can be manipulated
    client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("x").endMetadata().build());
    result = resource.inNamespace("x").createOrReplace();
    assertEquals("x", result.getMetadata().getNamespace());
    // ensure it can be loaded as a list
    List<HasMetadata> created = client.load(new ByteArrayInputStream(Serialization.asYaml(itest).getBytes(StandardCharsets.UTF_8))).createOrReplace();
    assertEquals(1, created.size());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.Test)

Example 80 with CustomResourceDefinition

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

the class CustomResourceDefinitionIT method update.

@Test
public void update() {
    // When
    final CustomResourceDefinition result = client.apiextensions().v1().customResourceDefinitions().withName(name).edit(c -> new CustomResourceDefinitionBuilder(c).editSpec().editOrNewNames().addToShortNames("its").endNames().endSpec().build());
    // Then
    assertThat(result.getSpec().getNames().getShortNames()).containsExactlyInAnyOrder("its");
}
Also used : CustomResourceDefinitionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Test(org.junit.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