Search in sources :

Example 26 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project jkube-integration-tests by jkubeio.

the class CustomResourceApp method assertFrameworkCustomResourceDefinitionApplied.

protected void assertFrameworkCustomResourceDefinitionApplied(JKubeCase jKubeCase) {
    CustomResourceDefinition crd = jKubeCase.getKubernetesClient().apiextensions().v1().customResourceDefinitions().withName(FRAMEWORKS_CRD).get();
    assertThat(crd, notNullValue());
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)

Example 27 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition 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 28 with CustomResourceDefinition

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

the class WebhookConfiguratorImplTest method configureWebhook_shouldNotFail.

@Test
void configureWebhook_shouldNotFail() {
    var definition = crdFinder.scanDefinitions().get(0);
    final String certificate = StringUtil.generateRandom();
    ArgumentCaptor<CustomResourceDefinition> crdCaptor = ArgumentCaptor.forClass(CustomResourceDefinition.class);
    when(crdWriter.update(crdCaptor.capture())).thenReturn(definition);
    webhookConfigurator.configureWebhook(definition.getMetadata().getName(), certificate);
    CustomResourceDefinition crd = crdCaptor.getValue();
    final CustomResourceDefinitionSpec spec = crd.getSpec();
    final CustomResourceConversion conversion = spec.getConversion();
    final WebhookClientConfig clientConfig = conversion.getWebhook().getClientConfig();
    final ServiceReference service = clientConfig.getService();
    assertEquals("Webhook", conversion.getStrategy());
    assertEquals(OPERATOR_NAME, service.getName());
    assertEquals(OPERATOR_NAMESPACE, service.getNamespace());
    assertEquals("/stackgres/conversion/" + definition.getSpec().getNames().getSingular(), service.getPath());
    assertEquals(certificate, clientConfig.getCaBundle());
    assertFalse(spec.getPreserveUnknownFields());
}
Also used : CustomResourceConversion(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceConversion) WebhookClientConfig(io.fabric8.kubernetes.api.model.apiextensions.v1.WebhookClientConfig) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) CustomResourceDefinitionSpec(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpec) ServiceReference(io.fabric8.kubernetes.api.model.apiextensions.v1.ServiceReference) Test(org.junit.jupiter.api.Test)

Example 29 with CustomResourceDefinition

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

the class KubernetesServerSupplier method get.

@Override
public synchronized KubernetesServer get() {
    if (server == null) {
        server = new KubernetesServer(true, true);
        server.before();
        final NamespacedKubernetesClient client = server.getClient();
        File file = CrdUtils.getCrdsFolder();
        for (File crdFile : Optional.ofNullable(file.listFiles()).orElse(new File[0])) {
            if (!crdFile.getName().endsWith(".yaml")) {
                continue;
            }
            CustomResourceDefinition crd = client.apiextensions().v1().customResourceDefinitions().load(crdFile).get();
            client.apiextensions().v1().customResourceDefinitions().create(crd);
        }
    }
    return server;
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) NamespacedKubernetesClient(io.fabric8.kubernetes.client.NamespacedKubernetesClient) File(java.io.File)

Example 30 with CustomResourceDefinition

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

the class CrdMatchTest method customResourcesYamlMetadataName_ShouldMatchWithNameInJavaDefinition.

@Test
void customResourcesYamlMetadataName_ShouldMatchWithNameInJavaDefinition() throws IOException {
    withEveryYaml(crdTree -> {
        JsonNode metadataName = crdTree.get("metadata").get("name");
        CustomResourceDefinition definition = getDefinition(crdTree);
        assertEquals(metadataName.asText(), definition.getMetadata().getName());
        Class<? extends CustomResource> clazz = getCustomResourceClass(crdTree);
        String name = CustomResource.getCRDName(clazz);
        assertEquals(metadataName.asText(), name, "Kind : " + HasMetadata.getKind(clazz));
    });
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) 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