Search in sources :

Example 21 with Ingress

use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project che-server by eclipse-che.

the class PreviewUrlExposerTest method shouldProvisionIngressWhenNotFound.

@Test
public void shouldProvisionIngressWhenNotFound() throws InternalInfrastructureException {
    Mockito.when(externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any())).thenReturn("some-server-path");
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    final String SERVICE_NAME = "servicename";
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName(SERVICE_NAME);
    service.setMetadata(serviceMeta);
    ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
    service.setSpec(serviceSpec);
    Map<String, Service> services = new HashMap<>();
    services.put(SERVICE_NAME, service);
    KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(new HashMap<>()).build();
    previewUrlExposer.expose(env);
    assertEquals(env.getIngresses().size(), 1);
    Ingress provisionedIngress = env.getIngresses().values().iterator().next();
    IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
    assertEquals(provisionedIngressBackend.getService().getPort().getName(), SERVER_PORT_NAME);
    assertEquals(provisionedIngressBackend.getService().getName(), SERVICE_NAME);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) Test(org.testng.annotations.Test)

Example 22 with Ingress

use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project che-server by eclipse-che.

the class DefaultHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.

@SuppressWarnings("SameParameterValue")
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, ServicePort servicePort, ServerConfigImpl expected) {
    // ensure that required ingress is created
    for (Ingress ingress : kubernetesEnvironment.getIngresses().values()) {
        IngressRule ingressRule = ingress.getSpec().getRules().get(0);
        IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
        if (serviceName.equals(backend.getService().getName())) {
            assertEquals(backend.getService().getPort().getName(), servicePort.getName());
            Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
            Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
            ServerConfig serverConfig = servers.get(serverNameRegex);
            if (serverConfig == null) {
                // ok, this ingress is not for this particular server
                continue;
            }
            assertEquals(serverConfig, expected);
            assertEquals(ingressAnnotations.machineName(), machineName);
            return;
        }
    }
    Assert.fail(format("Could not find an ingress for machine '%s' and service '%s'", machineName, serviceName));
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 23 with Ingress

use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project che-server by eclipse-che.

the class ExternalServerIngressBuilderTest method assertIngressSpec.

private void assertIngressSpec(String path, String host, Ingress ingress) {
    assertEquals(ingress.getSpec().getRules().get(0).getHost(), host);
    HTTPIngressPath httpIngressPath = ingress.getSpec().getRules().get(0).getHttp().getPaths().get(0);
    assertEquals(httpIngressPath.getPath(), path);
    assertEquals(httpIngressPath.getPathType(), INGRESS_PATH_TYPE);
    assertEquals(httpIngressPath.getBackend().getService().getName(), SERVICE_NAME);
    assertEquals(httpIngressPath.getBackend().getService().getPort().getName(), SERVICE_PORT_NAME);
    assertEquals(ingress.getMetadata().getName(), NAME);
    assertTrue(ingress.getMetadata().getAnnotations().containsKey("annotation-key"));
    assertEquals(ingress.getMetadata().getAnnotations().get("annotation-key"), "annotation-value");
    Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
    Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
    ServerConfig serverConfig = servers.get("http-server");
    assertEquals(serverConfig, SERVER_CONFIG);
    assertEquals(ingressAnnotations.machineName(), MACHINE_NAME);
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Example 24 with Ingress

use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project che-server by eclipse-che.

the class KubernetesInternalRuntime method createAndWaitReady.

private List<Ingress> createAndWaitReady(Collection<Ingress> ingresses) throws InfrastructureException {
    List<Ingress> createdIngresses = new ArrayList<>();
    for (Ingress ingress : ingresses) {
        createdIngresses.add(namespace.ingresses().create(ingress));
    }
    LOG.debug("Ingresses created for workspace '{}'. Wait them to be ready.", getContext().getIdentity().getWorkspaceId());
    // wait for LB ip
    List<Ingress> readyIngresses = new ArrayList<>();
    for (Ingress ingress : createdIngresses) {
        Ingress actualIngress = namespace.ingresses().wait(ingress.getMetadata().getName(), // Smaller value of ingress and start timeout should be used
        Math.min(ingressStartTimeoutMillis, startSynchronizer.getStartTimeoutMillis()), TimeUnit.MILLISECONDS, p -> (!p.getStatus().getLoadBalancer().getIngress().isEmpty()));
        readyIngresses.add(actualIngress);
    }
    LOG.debug("Ingresses creation for workspace '{}' done.", getContext().getIdentity().getWorkspaceId());
    return readyIngresses;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 25 with Ingress

use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress 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)

Aggregations

Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)158 Service (io.fabric8.kubernetes.api.model.Service)73 Test (org.junit.jupiter.api.Test)64 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)38 Test (org.testng.annotations.Test)38 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)37 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)36 ArrayList (java.util.ArrayList)35 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)33 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)32 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)32 HashMap (java.util.HashMap)31 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)28 Secret (io.fabric8.kubernetes.api.model.Secret)21 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)21 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)19 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)18 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)18 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)18 Reconciliation (io.strimzi.operator.common.Reconciliation)18