use of org.entando.kubernetes.test.common.KeycloakTestCapabilityProvider 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));
});
}
Aggregations