Search in sources :

Example 11 with Ingress

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

the class IngressServerExposer method expose.

/**
 * Exposes service port on given service externally (outside kubernetes cluster) using {@link
 * Ingress}.
 *
 * @see ExternalServerExposer#expose(KubernetesEnvironment, String, String, String, ServicePort,
 *     Map)
 */
@Override
public void expose(T k8sEnv, @Nullable String machineName, String serviceName, String serverId, ServicePort servicePort, Map<String, ServerConfig> externalServers) {
    if (serverId == null) {
        // this is the ID for non-unique servers
        serverId = servicePort.getName();
    }
    Ingress ingress = generateIngress(machineName, serviceName, serverId, servicePort, externalServers);
    k8sEnv.getIngresses().put(ingress.getMetadata().getName(), ingress);
}
Also used : Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 12 with Ingress

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

the class IngressesTest method findHostWhenPortDefinedByInt.

@Test
public void findHostWhenPortDefinedByInt() {
    final String SERVER_PORT_NAME = "server-8080";
    final int PORT = 8080;
    Service service = createService(SERVER_PORT_NAME, PORT);
    Ingress ingress = createIngress(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT))));
    Optional<IngressRule> foundRule = Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
    assertTrue(foundRule.isPresent());
    assertEquals(foundRule.get().getHost(), "ingresshost");
}
Also used : ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Test(org.testng.annotations.Test)

Example 13 with Ingress

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

the class IngressesTest method findHostWhenPortDefinedByString.

@Test
public void findHostWhenPortDefinedByString() {
    final String SERVER_PORT_NAME = "server-8080";
    final int PORT = 8080;
    Service service = createService(SERVER_PORT_NAME, PORT);
    Ingress ingress = createIngress(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT))));
    Optional<IngressRule> foundRule = Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
    assertTrue(foundRule.isPresent());
    assertEquals(foundRule.get().getHost(), "ingresshost");
}
Also used : ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Test(org.testng.annotations.Test)

Example 14 with Ingress

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

the class KubernetesInternalRuntimeTest method setup.

@BeforeMethod
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    runtimeStatesCache = new MapBasedRuntimeStateCache();
    machinesCache = new MapBasedMachinesCache();
    eventPublisher = new RuntimeEventsPublisher(eventService);
    serverResolverFactory = new KubernetesServerResolverFactory(pathTransformInverter, "che-host", MULTI_HOST_STRATEGY, WorkspaceExposureType.NATIVE.getConfigValue());
    startSynchronizer = spy(new StartSynchronizer(eventService, 5, IDENTITY));
    when(startSynchronizerFactory.create(any())).thenReturn(startSynchronizer);
    internalRuntime = new KubernetesInternalRuntime<>(13, 5, new URLRewriter.NoOpURLRewriter(), unrecoverablePodEventListenerFactory, serverCheckerFactory, volumesStrategy, probesScheduler, workspaceProbesFactory, eventPublisher, new KubernetesSharedPool(new NoopExecutorServiceWrapper()), runtimeStatesCache, machinesCache, startSynchronizerFactory, ImmutableSet.of(internalEnvironmentProvisioner), kubernetesEnvironmentProvisioner, toolingProvisioner, runtimeHangingDetector, previewUrlCommandProvisioner, secretAsContainerResourceProvisioner, serverResolverFactory, runtimeCleaner, cheNamespace, tracer, context, namespace);
    when(context.getEnvironment()).thenReturn(k8sEnv);
    when(context.getRuntime()).thenReturn(internalRuntime);
    when(serverCheckerFactory.create(any(), anyString(), any())).thenReturn(serversChecker);
    when(context.getIdentity()).thenReturn(IDENTITY);
    doNothing().when(namespace).cleanUp();
    when(namespace.services()).thenReturn(services);
    when(namespace.ingresses()).thenReturn(ingresses);
    when(namespace.deployments()).thenReturn(deployments);
    when(namespace.secrets()).thenReturn(secrets);
    when(namespace.configMaps()).thenReturn(configMaps);
    doReturn(ImmutableMap.of(M1_NAME, mock(InternalMachineConfig.class), M2_NAME, mock(InternalMachineConfig.class))).when(k8sEnv).getMachines();
    final Map<String, Service> allServices = ImmutableMap.of(SERVICE_NAME, mockService());
    final Ingress ingress = mockIngress();
    final Map<String, Ingress> allIngresses = ImmutableMap.of(INGRESS_NAME, ingress);
    when(services.create(any())).thenAnswer(a -> a.getArguments()[0]);
    when(ingresses.create(any())).thenAnswer(a -> a.getArguments()[0]);
    when(ingresses.wait(anyString(), anyLong(), any(), any())).thenReturn(ingress);
    when(deployments.deploy(any(Pod.class))).thenAnswer(inv -> inv.getArgument(0));
    when(deployments.deploy(any(Deployment.class))).thenAnswer(inv -> {
        Deployment d = inv.getArgument(0);
        Pod pod = new Pod();
        pod.setSpec(d.getSpec().getTemplate().getSpec());
        pod.setMetadata(d.getSpec().getTemplate().getMetadata());
        return pod;
    });
    when(k8sEnv.getServices()).thenReturn(allServices);
    when(k8sEnv.getIngresses()).thenReturn(allIngresses);
    when(k8sEnv.getPodsCopy()).thenReturn(podsMap);
    when(k8sEnv.getCommands()).thenReturn(new ArrayList<>(singletonList(envCommand)));
    when(deployments.waitRunningAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
    when(serversChecker.startAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
}
Also used : KubernetesServerResolverFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory) Pod(io.fabric8.kubernetes.api.model.Pod) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) EventService(org.eclipse.che.api.core.notification.EventService) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesSharedPool(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 15 with Ingress

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

the class IngressServerResolverTest method testResolvingServersWhenThereIsNoTheCorrespondingServiceAndIngressForTheSpecifiedMachine.

@Test
public void testResolvingServersWhenThereIsNoTheCorrespondingServiceAndIngressForTheSpecifiedMachine() {
    // given
    Service nonMatchedByPodService = createService("nonMatched", "foreignMachine", CONTAINER_PORT, null);
    Ingress ingress = createIngress("nonMatched", "foreignMachine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "/api", ATTRIBUTES_MAP)));
    ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), singletonList(nonMatchedByPodService), singletonList(ingress));
    // when
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    // then
    assertTrue(resolved.isEmpty());
}
Also used : IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) Test(org.testng.annotations.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