Search in sources :

Example 1 with ProvidedCapability

use of org.entando.kubernetes.model.capability.ProvidedCapability in project entando-k8s-controller-coordinator by entando-k8s.

the class ControllerCoordinatorSmokeTest method smokeTest.

@Test
@Description("Should deploy all the capabilities required for an EntandoApp")
void smokeTest() {
    // NB!!! Wildcard certs can't have more than 1 segment before the defaultRoutingSuffix: https://datatracker.ietf.org/doc/html/rfc2818#section-3.1
    String ingressHostname = MY_APP + "-" + NAMESPACE + "." + EntandoOperatorConfig.getDefaultRoutingSuffix().orElse("apps.serv.run");
    // TODO migrate this to TestResource and create a really simple Controller for it to execute. However, keep in mind
    // that the operator service account doesn't have access to TestResources
    step("Given that the entando-k8s-controller-coordinator has been deployed along with the entando-k8s-service", () -> {
        final Service k8sSvc = fabric8Client.services().inNamespace(NAMESPACE).withName("entando-k8s-service").get();
        attachment("EntandoK8SService", objectMapper.writeValueAsString(k8sSvc));
        assertThat(k8sSvc).isNotNull();
        final Optional<Deployment> operatorDeployment = fabric8Client.apps().deployments().inNamespace(NAMESPACE).list().getItems().stream().filter(deployment -> deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage().contains("entando-k8s-controller-coordinator")).findFirst();
        assertThat(operatorDeployment).isPresent();
        attachment("OperatorDeployment", objectMapper.writeValueAsString(operatorDeployment.get()));
        await().atMost(1, TimeUnit.MINUTES).ignoreExceptions().until(() -> fabric8Client.apps().deployments().inNamespace(NAMESPACE).withName(operatorDeployment.get().getMetadata().getName()).isReady());
    });
    step("And I have created an externally provisioned Keycloak SSO capability and waited for it to become available", () -> {
        final KeycloakTestCapabilityProvider keycloakProvider = new KeycloakTestCapabilityProvider(new DefaultSimpleK8SClient(fabric8Client), NAMESPACE);
        final ProvidedCapability keycloakCapability = keycloakProvider.createKeycloakCapability();
        await().atMost(2, TimeUnit.MINUTES).ignoreExceptions().until(() -> fabric8Client.customResources(ProvidedCapability.class).inNamespace(NAMESPACE).withName(keycloakCapability.getMetadata().getName()).fromServer().get().getStatus().getPhase() == EntandoDeploymentPhase.SUCCESSFUL);
        keycloakProvider.deleteTestRealms(keycloakCapability, NAMESPACE);
        attachment("Keycloak Capability", objectMapper.writeValueAsString(keycloakCapability));
    });
    step("When I create an EntandoApp that requires SSO and a PostgreSQL DBMS capability", () -> {
        EntandoApp entandoApp = fabric8Client.customResources(EntandoApp.class).inNamespace(NAMESPACE).create(new EntandoAppBuilder().withNewMetadata().withNamespace(NAMESPACE).withName("my-app").endMetadata().withNewSpec().withDbms(DbmsVendor.POSTGRESQL).withIngressHostName(ingressHostname).endSpec().build());
        attachment("Keycloak Capability", objectMapper.writeValueAsString(entandoApp));
    });
    step("Then I expect to see a PostgreSQL database capability that has been made available", () -> {
        await().atMost(2, TimeUnit.MINUTES).ignoreExceptions().until(() -> fabric8Client.customResources(ProvidedCapability.class).inNamespace(NAMESPACE).list().getItems().stream().anyMatch(providedCapability -> providedCapability.getSpec().getImplementation().isPresent() && providedCapability.getSpec().getImplementation().get().equals(StandardCapabilityImplementation.POSTGRESQL) && providedCapability.getStatus().getPhase() == EntandoDeploymentPhase.SUCCESSFUL));
    });
    step("And a deployment for the Entando App", () -> {
        await().atMost(5, TimeUnit.MINUTES).ignoreExceptions().until(() -> fabric8Client.apps().deployments().inNamespace(NAMESPACE).list().getItems().stream().filter(d -> d.getSpec().getTemplate().getSpec().getContainers().get(0).getImage().contains("de-app")).findFirst().get().getStatus().getReadyReplicas() >= 1);
    });
    step("And an Ingress for the Entando App", () -> {
        Optional<Ingress> ingress = fabric8Client.extensions().ingresses().inNamespace(NAMESPACE).list().getItems().stream().filter(d -> d.getSpec().getRules().get(0).getHost().equals(ingressHostname)).findFirst();
        assertThat(ingress).isPresent();
    });
    step("And I can connect to the EntandoApp's health check path", () -> {
        final String strUrl = HttpTestHelper.getDefaultProtocol() + "://" + ingressHostname + "/entando-de-app/api/health";
        System.out.println("Attempting to connect to " + strUrl);
        await().atMost(2, TimeUnit.MINUTES).ignoreExceptions().until(() -> HttpTestHelper.statusOk(strUrl));
    });
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Allure.attachment(io.qameta.allure.Allure.attachment) DbmsVendor(org.entando.kubernetes.model.common.DbmsVendor) EntandoAppBuilder(org.entando.kubernetes.model.app.EntandoAppBuilder) EntandoOperatorSpiConfigProperty(org.entando.kubernetes.controller.spi.common.EntandoOperatorSpiConfigProperty) SupportProducer(org.entando.kubernetes.controller.support.client.impl.SupportProducer) EntandoOperatorConfig(org.entando.kubernetes.controller.support.common.EntandoOperatorConfig) EntandoOperatorConfigProperty(org.entando.kubernetes.controller.support.common.EntandoOperatorConfigProperty) Feature(io.qameta.allure.Feature) EntandoKeycloakServer(org.entando.kubernetes.model.keycloakserver.EntandoKeycloakServer) EntandoApp(org.entando.kubernetes.model.app.EntandoApp) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) DefaultSimpleK8SClient(org.entando.kubernetes.controller.support.client.impl.DefaultSimpleK8SClient) Service(io.fabric8.kubernetes.api.model.Service) Tag(org.junit.jupiter.api.Tag) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Issue(io.qameta.allure.Issue) EntandoDatabaseService(org.entando.kubernetes.model.externaldatabase.EntandoDatabaseService) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) Awaitility.await(org.awaitility.Awaitility.await) ProvidedCapability(org.entando.kubernetes.model.capability.ProvidedCapability) Optional.ofNullable(java.util.Optional.ofNullable) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpTestHelper(org.entando.kubernetes.controller.support.client.impl.integrationtesthelpers.HttpTestHelper) KeycloakTestCapabilityProvider(org.entando.kubernetes.test.common.KeycloakTestCapabilityProvider) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) StandardCapabilityImplementation(org.entando.kubernetes.model.capability.StandardCapabilityImplementation) Allure.step(io.qameta.allure.Allure.step) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) TrustStoreHelper(org.entando.kubernetes.controller.spi.common.TrustStoreHelper) Tags(org.junit.jupiter.api.Tags) EntandoOperatorTestConfig(org.entando.kubernetes.controller.support.client.impl.EntandoOperatorTestConfig) Description(io.qameta.allure.Description) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EntandoDeploymentPhase(org.entando.kubernetes.model.common.EntandoDeploymentPhase) EntandoAppBuilder(org.entando.kubernetes.model.app.EntandoAppBuilder) ProvidedCapability(org.entando.kubernetes.model.capability.ProvidedCapability) Service(io.fabric8.kubernetes.api.model.Service) EntandoDatabaseService(org.entando.kubernetes.model.externaldatabase.EntandoDatabaseService) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) KeycloakTestCapabilityProvider(org.entando.kubernetes.test.common.KeycloakTestCapabilityProvider) DefaultSimpleK8SClient(org.entando.kubernetes.controller.support.client.impl.DefaultSimpleK8SClient) EntandoApp(org.entando.kubernetes.model.app.EntandoApp) Description(io.qameta.allure.Description) Test(org.junit.jupiter.api.Test)

Example 2 with ProvidedCapability

use of org.entando.kubernetes.model.capability.ProvidedCapability in project entando-k8s-controller-coordinator by entando-k8s.

the class CrdManagementTest method testCapabilityEvent.

@Test
@Description("Capabilities that my controller image supports should also result in my controller image to be executed against the " + "ProvidedCapability")
void testCapabilityEvent() throws IOException {
    step("Given I prepared a namespace scoped deployment of the EntandoOperator", () -> System.setProperty(EntandoOperatorConfigProperty.ENTANDO_NAMESPACES_TO_OBSERVE.getJvmSystemProperty(), MY_NAMESPACE));
    step("Given I have started the Entando Operator", () -> entandoControllerCoordinator.onStartup(new StartupEvent()));
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    final CustomResourceDefinition value = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResource("mycrds.test.org.crd.yaml"), CustomResourceDefinition.class);
    final MetadataNested<CustomResourceDefinitionBuilder> builder = new CustomResourceDefinitionBuilder(value).editMetadata();
    step("And I have a CustomResourceDefinition with", () -> {
        step(format("the %s label ", LabelNames.CRD_OF_INTEREST.getName()), () -> {
            builder.addToLabels(LabelNames.CRD_OF_INTEREST.getName(), "MyCRD");
        });
        step(format("and the %s annotation ", AnnotationNames.CONTROLLER_IMAGE.getName()), () -> {
            builder.addToAnnotations(AnnotationNames.CONTROLLER_IMAGE.getName(), "test/my-controller");
        });
        step(format("and the %s annotation ", AnnotationNames.SUPPORTED_CAPABILITIES), () -> {
            builder.addToAnnotations(AnnotationNames.SUPPORTED_CAPABILITIES.getName(), "mysql.dbms");
        });
    });
    step("And I have registered my custom resource definition", () -> {
        client.getCluster().putCustomResourceDefinition(builder.endMetadata().build());
    });
    final ProvidedCapability providedCapability = new ProvidedCapabilityBuilder().withNewMetadata().withName("my-capability").withNamespace(MY_NAMESPACE).endMetadata().withNewSpec().withCapability(StandardCapability.DBMS).withImplementation(StandardCapabilityImplementation.MYSQL).endSpec().build();
    step("When I create a new ProvidedCapability requiring the capability associated with my CustomResourceDefinition ", () -> client.createOrPatchEntandoResource(CoordinatorTestUtils.toSerializedResource(providedCapability)));
    step(format("Then a controller pod has been created with the image that I specified in the %s annotation", AnnotationNames.CONTROLLER_IMAGE.getName()), () -> {
        await().atMost(10, TimeUnit.SECONDS).ignoreExceptions().until(() -> client.loadPod(AbstractK8SClientDouble.CONTROLLER_NAMESPACE, CoordinatorUtils.podLabelsFor(providedCapability)) != null);
        assertThat(client.loadPod(AbstractK8SClientDouble.CONTROLLER_NAMESPACE, CoordinatorUtils.podLabelsFor(providedCapability)).getSpec().getContainers().get(0).getImage()).contains("test/my-controller");
    });
}
Also used : CustomResourceDefinitionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) StartupEvent(io.quarkus.runtime.StartupEvent) ProvidedCapability(org.entando.kubernetes.model.capability.ProvidedCapability) ProvidedCapabilityBuilder(org.entando.kubernetes.model.capability.ProvidedCapabilityBuilder) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Description(io.qameta.allure.Description) Test(org.junit.jupiter.api.Test)

Example 3 with ProvidedCapability

use of org.entando.kubernetes.model.capability.ProvidedCapability in project entando-k8s-controller-coordinator by entando-k8s.

the class CrdManagementTest method testCapabilityEventWithControllerImageOverride.

@Test
@Description("Capabilities that my controller image supports should also result in the image specified in the " + CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP + " ConfigMap to be executed against the ProvidedCapability")
void testCapabilityEventWithControllerImageOverride() throws IOException {
    step("Given I prepared a namespace scoped deployment of the EntandoOperator", () -> System.setProperty(EntandoOperatorConfigProperty.ENTANDO_NAMESPACES_TO_OBSERVE.getJvmSystemProperty(), MY_NAMESPACE));
    step("Given I have started the Entando Operator", () -> entandoControllerCoordinator.onStartup(new StartupEvent()));
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    final CustomResourceDefinition value = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResource("mycrds.test.org.crd.yaml"), CustomResourceDefinition.class);
    final MetadataNested<CustomResourceDefinitionBuilder> builder = new CustomResourceDefinitionBuilder(value).editMetadata();
    step("And I have a CustomResourceDefinition with", () -> {
        step(format("the %s label ", LabelNames.CRD_OF_INTEREST.getName()), () -> {
            builder.addToLabels(LabelNames.CRD_OF_INTEREST.getName(), "MyCRD");
        });
        step(format("and the %s annotation ", AnnotationNames.CONTROLLER_IMAGE.getName()), () -> {
            builder.addToAnnotations(AnnotationNames.CONTROLLER_IMAGE.getName(), "test/my-controller");
        });
        step(format("and the %s annotation ", AnnotationNames.SUPPORTED_CAPABILITIES), () -> {
            builder.addToAnnotations(AnnotationNames.SUPPORTED_CAPABILITIES.getName(), "mysql.dbms");
        });
    });
    step("And I have registered my custom resource definition", () -> {
        client.getCluster().putCustomResourceDefinition(builder.endMetadata().build());
    });
    final ProvidedCapability providedCapability = new ProvidedCapabilityBuilder().withNewMetadata().withName("my-capability").withNamespace(MY_NAMESPACE).endMetadata().withNewSpec().withCapability(StandardCapability.DBMS).withImplementation(StandardCapabilityImplementation.MYSQL).endSpec().build();
    step(format("But I have overridden the DBMS capability's image to 'test/image-override' in the %s ConfigMap", CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP), () -> {
        client.patchControllerConfigMap(new ConfigMapBuilder(client.findOrCreateControllerConfigMap(CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP)).addToData("dbms.capability.org", "test/image-override").build());
    });
    step("When I create a new ProvidedCapability requiring the capability associated with my CustomResourceDefinition ", () -> client.createOrPatchEntandoResource(CoordinatorTestUtils.toSerializedResource(providedCapability)));
    step(format("Then a controller pod has been created with the overriding image that I specified in the %s ConfigMap", CoordinatorUtils.CONTROLLER_IMAGE_OVERRIDES_CONFIGMAP), () -> {
        await().atMost(10, TimeUnit.SECONDS).ignoreExceptions().until(() -> client.loadPod(AbstractK8SClientDouble.CONTROLLER_NAMESPACE, CoordinatorUtils.podLabelsFor(providedCapability)) != null);
        assertThat(client.loadPod(AbstractK8SClientDouble.CONTROLLER_NAMESPACE, CoordinatorUtils.podLabelsFor(providedCapability)).getSpec().getContainers().get(0).getImage()).contains("test/image-override");
    });
}
Also used : CustomResourceDefinitionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) StartupEvent(io.quarkus.runtime.StartupEvent) ProvidedCapability(org.entando.kubernetes.model.capability.ProvidedCapability) ProvidedCapabilityBuilder(org.entando.kubernetes.model.capability.ProvidedCapabilityBuilder) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Description(io.qameta.allure.Description) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)3 Description (io.qameta.allure.Description)3 ProvidedCapability (org.entando.kubernetes.model.capability.ProvidedCapability)3 Test (org.junit.jupiter.api.Test)3 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition)2 CustomResourceDefinitionBuilder (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder)2 StartupEvent (io.quarkus.runtime.StartupEvent)2 ProvidedCapabilityBuilder (org.entando.kubernetes.model.capability.ProvidedCapabilityBuilder)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 Service (io.fabric8.kubernetes.api.model.Service)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 Allure.attachment (io.qameta.allure.Allure.attachment)1 Allure.step (io.qameta.allure.Allure.step)1 Feature (io.qameta.allure.Feature)1 Issue (io.qameta.allure.Issue)1 Arrays (java.util.Arrays)1