Search in sources :

Example 86 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project jkube by eclipse.

the class ApplyService method doCreateCustomResourceDefinition.

private void doCreateCustomResourceDefinition(CustomResourceDefinition entity, String sourceName) {
    log.info("Creating a Custom Resource Definition from " + sourceName + " name " + getName(entity));
    try {
        CustomResourceDefinition answer = kubernetesClient.apiextensions().v1().customResourceDefinitions().create(entity);
        log.info("Created Custom Resource Definition result: %s", answer.getMetadata().getName());
    } catch (Exception e) {
        onApplyError("Failed to create Custom Resource Definition from " + sourceName + ". " + e + ". " + entity, e);
    }
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 87 with CustomResourceDefinition

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

the class CrdInstallerImplTest method installCrd_shouldInstallTheResourceIfDoesNotExists.

@Test
void installCrd_shouldInstallTheResourceIfDoesNotExists() {
    CustomResourceDefinition definition = crdLoader.scanDefinitions().get(0);
    when(customResourceDefinitionFinder.findByName(definition.getMetadata().getName())).thenReturn(Optional.empty());
    when(customResourceDefinitionWriter.create(any(CustomResourceDefinition.class))).thenReturn(definition);
    crdInstaller.installCrd(definition.getMetadata().getName(), definition.getSpec().getNames().getKind());
    verify(customResourceDefinitionFinder).findByName(definition.getMetadata().getName());
    verify(customResourceDefinitionWriter).create(any(CustomResourceDefinition.class));
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Example 88 with CustomResourceDefinition

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

the class CrdInstallerImplTest method installCrd_shouldPatchTheResourceIfExists.

@Test
void installCrd_shouldPatchTheResourceIfExists() {
    CustomResourceDefinition definition = crdLoader.scanDefinitions().get(0);
    when(customResourceDefinitionFinder.findByName(definition.getMetadata().getName())).thenAnswer((Answer<Optional<CustomResourceDefinition>>) invocationOnMock -> Optional.of(crdLoader.load(definition.getSpec().getNames().getKind())));
    when(customResourceDefinitionWriter.update(any(CustomResourceDefinition.class))).thenReturn(definition);
    crdInstaller.installCrd(definition.getMetadata().getName(), definition.getSpec().getNames().getKind());
    verify(customResourceDefinitionFinder).findByName(definition.getMetadata().getName());
    verify(customResourceDefinitionWriter).update(any(CustomResourceDefinition.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) Mockito.when(org.mockito.Mockito.when) ResourceWriter(io.stackgres.common.resource.ResourceWriter) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Answer(org.mockito.stubbing.Answer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Optional(java.util.Optional) ResourceFinder(io.stackgres.common.resource.ResourceFinder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Optional(java.util.Optional) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Test(org.junit.jupiter.api.Test)

Example 89 with CustomResourceDefinition

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

the class WebhookConfiguratorImpl method configureWebhook.

protected void configureWebhook(String name, String webhookCaCert) {
    CustomResourceDefinition customResourceDefinition = crdFinder.findByName(name).orElseThrow(() -> new RuntimeException("Custom Resource Definition " + name + " not found"));
    customResourceDefinition.getSpec().setPreserveUnknownFields(false);
    String conversionPath = "/stackgres/conversion/" + customResourceDefinition.getSpec().getNames().getSingular();
    customResourceDefinition.getSpec().setConversion(new CustomResourceConversionBuilder().withStrategy("Webhook").withWebhook(new WebhookConversionBuilder().withClientConfig(new WebhookClientConfigBuilder().withCaBundle(webhookCaCert).withService(new ServiceReferenceBuilder().withNamespace(operatorNamespace).withName(operatorName).withPath(conversionPath).build()).build()).withConversionReviewVersions("v1", "v1beta1").build()).build());
    crdWriter.update(customResourceDefinition);
}
Also used : ServiceReferenceBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.ServiceReferenceBuilder) WebhookConversionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.WebhookConversionBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) CustomResourceConversionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceConversionBuilder) WebhookClientConfigBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.WebhookClientConfigBuilder)

Example 90 with CustomResourceDefinition

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

the class CrdInstallerImpl method installCrd.

protected void installCrd(@NotNull String name, @NotNull String kind) {
    Optional<CustomResourceDefinition> installedCrdOpt = customResourceDefinitionResourceFinder.findByName(name);
    CustomResourceDefinition currentCrd = getDefinition(kind);
    if (installedCrdOpt.isPresent()) {
        LOGGER.info("CRD {} is present, patching it", name);
        CustomResourceDefinition installedCrd = installedCrdOpt.get();
        if (!isCurrentCrdInstalled(currentCrd, installedCrd)) {
            upgradeCrd(currentCrd, installedCrd);
        }
        updateAlreadyInstalledVersions(currentCrd, installedCrd);
        customResourceDefinitionResourceWriter.update(installedCrd);
        LOGGER.info("CRD {}. Patched", name);
    } else {
        LOGGER.info("CRD {} is not present, installing it", name);
        customResourceDefinitionResourceWriter.create(currentCrd);
        LOGGER.info("CRD {} . Installed", name);
    }
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)

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