Search in sources :

Example 1 with CustomResourceDefinitionNames

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionNames in project stackgres by ongres.

the class CrdLoaderImplTest method scanDefinitions.

@Test
void scanDefinitions() {
    List<CustomResourceDefinition> definitions = crdLoader.scanDefinitions();
    assertEquals(crdFolder.list((file, name) -> name.endsWith(".yaml")).length, definitions.size());
    List<CustomResourceDefinition> customResourceDefinitions = Arrays.stream(crdFolder.listFiles((file, name) -> name.endsWith(".yaml"))).map(file -> {
        try {
            return mapper.readValue(file, CustomResourceDefinition.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    definitions.forEach(def -> {
        var customResourceDefinition = customResourceDefinitions.stream().filter(crd -> crd.getMetadata().getName().equals(def.getMetadata().getName())).findFirst().orElseThrow(() -> new RuntimeException("There is no definition with name " + def.getMetadata().getName()));
        final CustomResourceDefinitionNames names = customResourceDefinition.getSpec().getNames();
        assertEquals(names.getKind(), def.getSpec().getNames().getKind());
        assertEquals(names.getSingular(), def.getSpec().getNames().getSingular());
    });
}
Also used : Test(org.junit.jupiter.api.Test) Arrays(java.util.Arrays) List(java.util.List) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) IOException(java.io.IOException) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CrdUtils(io.stackgres.testutil.CrdUtils) Collectors(java.util.stream.Collectors) File(java.io.File) CustomResourceDefinitionNames(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionNames) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) IOException(java.io.IOException) CustomResourceDefinitionNames(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionNames) Test(org.junit.jupiter.api.Test)

Example 2 with CustomResourceDefinitionNames

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

the class CustomResourceDefinitionContextTest method v1beta1CRDFromCustomResourceType.

@Test
@DisplayName("v1beta1CRDFromCustomResourceType correctly generates CRD builder for v1beta1 version")
void v1beta1CRDFromCustomResourceType() {
    final CustomResourceDefinition crd = CustomResourceDefinitionContext.v1beta1CRDFromCustomResourceType(Good.class).build();
    final CustomResourceDefinitionSpec spec = crd.getSpec();
    final CustomResourceDefinitionNames names = spec.getNames();
    final String plural = "goods";
    Assertions.assertEquals(plural, names.getPlural());
    Assertions.assertEquals("good", names.getSingular());
    Assertions.assertEquals("Good", names.getKind());
    Assertions.assertEquals(plural + "." + Good.GROUP, crd.getMetadata().getName());
    Assertions.assertEquals(Good.VERSION, spec.getVersion());
    Assertions.assertEquals(Good.VERSION, spec.getVersions().get(0).getName());
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) Good(io.fabric8.kubernetes.client.Good) CustomResourceDefinitionSpec(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionSpec) CustomResourceDefinitionNames(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionNames) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Test (org.junit.jupiter.api.Test)2 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)1 CustomResourceDefinitionNames (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionNames)1 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition)1 CustomResourceDefinitionNames (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionNames)1 CustomResourceDefinitionSpec (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionSpec)1 Good (io.fabric8.kubernetes.client.Good)1 CrdUtils (io.stackgres.testutil.CrdUtils)1 File (java.io.File)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 DisplayName (org.junit.jupiter.api.DisplayName)1