use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.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);
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.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");
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.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");
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.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));
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.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());
}
Aggregations