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);
}
}
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));
}
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));
}
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);
}
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);
}
}
Aggregations