io.fabric8.kubernetes.api.model.extensions.Ingress Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.extensions.Ingress.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IngressTlsProvisioner.java From che with Eclipse Public License 2.0 | 6 votes |
@Override public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws KubernetesInfrastructureException { if (!isTlsEnabled) { return; } String wsTlsSecretName = tlsSecretName; if (!isNullOrEmpty(tlsCert) && !isNullOrEmpty(tlsKey)) { wsTlsSecretName = identity.getWorkspaceId() + '-' + tlsSecretName; provisionTlsSecret(k8sEnv, wsTlsSecretName); } Collection<Ingress> ingresses = k8sEnv.getIngresses().values(); for (Ingress ingress : ingresses) { useSecureProtocolForServers(ingress); enableTLS(ingress, wsTlsSecretName); } }
Example #2
Source File: Sample2Test.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@BeforeClass public void compileSample() throws IOException, InterruptedException { Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s_config.bal"), 0); File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "hello_world_k8s_config.yaml"); Assert.assertTrue(yamlFile.exists()); List<HasMetadata> k8sItems = KubernetesTestUtils.loadYaml(yamlFile); for (HasMetadata data : k8sItems) { switch (data.getKind()) { case "Deployment": deployment = (Deployment) data; break; case "Service": service = (Service) data; break; case "Ingress": ingress = (Ingress) data; break; default: break; } } }
Example #3
Source File: K8sIngressWatcher.java From onos with Apache License 2.0 | 6 votes |
@Override public void eventReceived(Action action, Ingress ingress) { switch (action) { case ADDED: eventExecutor.execute(() -> processAddition(ingress)); break; case MODIFIED: eventExecutor.execute(() -> processModification(ingress)); break; case DELETED: eventExecutor.execute(() -> processDeletion(ingress)); break; case ERROR: log.warn("Failures processing ingress manipulation."); break; default: break; } }
Example #4
Source File: Sample14Test.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@BeforeClass public void compileSample() throws IOException, InterruptedException { Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s_namespace.bal"), 0); File yamlFile = KUBERNETES_TARGET_PATH.resolve("hello_world_k8s_namespace.yaml").toFile(); Assert.assertTrue(yamlFile.exists()); List<HasMetadata> k8sItems = KubernetesTestUtils.loadYaml(yamlFile); for (HasMetadata data : k8sItems) { switch (data.getKind()) { case "Deployment": deployment = (Deployment) data; break; case "Service": service = (Service) data; break; case "Ingress": ingress = (Ingress) data; break; default: break; } } }
Example #5
Source File: KubernetesServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsRelative() { Ingress ingress = createIngress( "matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "api", ATTRIBUTES_MAP))); KubernetesServerResolver serverResolver = new KubernetesServerResolver( new NoopPathTransformInverter(), emptyList(), singletonList(ingress)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/api/") .withStatus(ServerStatus.UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #6
Source File: ExternalServerIngressBuilderTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldCreateIngress() { // given final String path = "/path/to/server"; final String host = "host-to-server"; // when Ingress ingress = externalServerIngressBuilder .withPath(path) .withHost(host) .withAnnotations(ANNOTATIONS) .withMachineName(MACHINE_NAME) .withName(NAME) .withServers(SERVERS) .withServiceName(SERVICE_NAME) .withServicePort(SERVICE_PORT) .build(); // then assertIngressSpec(path, host, ingress); }
Example #7
Source File: ExternalServerIngressBuilderTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldCreateIngressWithNoPath() { // given final String host = "host-to-server"; // when Ingress ingress = externalServerIngressBuilder .withHost(host) .withAnnotations(ANNOTATIONS) .withMachineName(MACHINE_NAME) .withName(NAME) .withServers(SERVERS) .withServiceName(SERVICE_NAME) .withServicePort(SERVICE_PORT) .build(); // then assertIngressSpec(null, host, ingress); }
Example #8
Source File: ExternalServerIngressBuilderTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldCreateIngressWithNoHost() { // given final String path = "/path/to/server"; // when Ingress ingress = externalServerIngressBuilder .withPath(path) .withAnnotations(ANNOTATIONS) .withMachineName(MACHINE_NAME) .withName(NAME) .withServers(SERVERS) .withServiceName(SERVICE_NAME) .withServicePort(SERVICE_PORT) .build(); // then assertIngressSpec(path, null, ingress); }
Example #9
Source File: ExternalServerIngressBuilderTest.java From che with Eclipse Public License 2.0 | 6 votes |
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.getBackend().getServiceName(), SERVICE_NAME); assertEquals(httpIngressPath.getBackend().getServicePort().getStrVal(), SERVICE_PORT); 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); }
Example #10
Source File: IngressEnricherTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void testCreate() { // Given new Expectations() {{ // Enable creation of Ingress for Service of type LoadBalancer context.getProperty(CREATE_EXTERNAL_URLS); result = "true"; }}; Service providedService = getTestService().build(); KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService); IngressEnricher ingressEnricher = new IngressEnricher(context); // When ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder); // Then Ingress ingress = (Ingress) kubernetesListBuilder.buildLastItem(); assertEquals(2, kubernetesListBuilder.buildItems().size()); assertNotNull(ingress); assertEquals(providedService.getMetadata().getName(), ingress.getMetadata().getName()); assertNotNull(ingress.getSpec()); assertEquals(providedService.getMetadata().getName(), ingress.getSpec().getBackend().getServiceName()); assertEquals(providedService.getSpec().getPorts().get(0).getTargetPort(), ingress.getSpec().getBackend().getServicePort()); }
Example #11
Source File: IngressEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, final KubernetesListBuilder listBuilder) { ResourceConfig resourceConfig = getConfiguration().getResource(); Boolean shouldCreateIngress = getValueFromConfig(CREATE_EXTERNAL_URLS, false); if (shouldCreateIngress.equals(Boolean.FALSE)) { return; } if (platformMode == PlatformMode.kubernetes) { listBuilder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { Ingress ingress = addIngress(listBuilder, serviceBuilder, getRouteDomain(resourceConfig), log); if (ingress != null) { listBuilder.addToItems(ingress); } } }); } }
Example #12
Source File: Sample4Test.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@BeforeClass public void compileSample() throws IOException, InterruptedException { Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_ssl_k8s.bal"), 0); File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_ssl_k8s.yaml").toFile(); Assert.assertTrue(artifactYaml.exists()); KubernetesClient client = new DefaultKubernetesClient(); List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get(); for (HasMetadata data : k8sItems) { switch (data.getKind()) { case "Deployment": deployment = (Deployment) data; break; case "Secret": secret = (Secret) data; break; case "Ingress": ingress = (Ingress) data; break; case "Service": break; default: Assert.fail("Unexpected k8s resource found: " + data.getKind()); break; } } }
Example #13
Source File: KubernetesServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsEmpty() { Ingress ingress = createIngress( "matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "", ATTRIBUTES_MAP))); KubernetesServerResolver serverResolver = new KubernetesServerResolver( new NoopPathTransformInverter(), emptyList(), singletonList(ingress)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/") .withStatus(ServerStatus.UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #14
Source File: KubernetesServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsNull() { Ingress ingress = createIngress( "matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", null, ATTRIBUTES_MAP))); KubernetesServerResolver serverResolver = new KubernetesServerResolver( new NoopPathTransformInverter(), emptyList(), singletonList(ingress)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/") .withStatus(ServerStatus.UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #15
Source File: KubernetesServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@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))); KubernetesServerResolver serverResolver = new KubernetesServerResolver( new NoopPathTransformInverter(), singletonList(nonMatchedByPodService), singletonList(ingress)); // when Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); // then assertTrue(resolved.isEmpty()); }
Example #16
Source File: IngressTlsProvisioner.java From che with Eclipse Public License 2.0 | 6 votes |
private void enableTLS(Ingress ingress, String wsTlsSecretName) { String host = ingress.getSpec().getRules().get(0).getHost(); IngressTLSBuilder ingressTLSBuilder = new IngressTLSBuilder().withHosts(host); // according to ingress tls spec, secret name is optional // when working in single-host mode, nginx controller wil reuse the che-master secret // https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/api/extensions/v1beta1/types.go if (!isNullOrEmpty(wsTlsSecretName)) { ingressTLSBuilder.withSecretName(wsTlsSecretName); } IngressTLS ingressTLS = ingressTLSBuilder.build(); List<IngressTLS> ingressTLSList = new ArrayList<>(Collections.singletonList(ingressTLS)); ingress.getSpec().setTls(ingressTLSList); }
Example #17
Source File: KubernetesEnvironment.java From che with Eclipse Public License 2.0 | 6 votes |
protected KubernetesEnvironment( InternalEnvironment internalEnvironment, Map<String, Pod> pods, Map<String, Deployment> deployments, Map<String, Service> services, Map<String, Ingress> ingresses, Map<String, PersistentVolumeClaim> persistentVolumeClaims, Map<String, Secret> secrets, Map<String, ConfigMap> configMaps) { super(internalEnvironment); setType(TYPE); this.pods = new HashMap<>(pods); this.deployments = new HashMap<>(deployments); this.services = services; this.ingresses = ingresses; this.persistentVolumeClaims = persistentVolumeClaims; this.secrets = secrets; this.configMaps = configMaps; this.podData = new HashMap<>(); this.injectablePods = new HashMap<>(); pods.forEach((name, pod) -> podData.put(name, new PodData(pod))); deployments.forEach((name, deployment) -> podData.put(name, new PodData(deployment))); }
Example #18
Source File: IngressTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testDeleteMulti() { Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build(); Ingress ingress2 = new IngressBuilder().withNewMetadata().withName("ingress2").withNamespace("ns1").and().build(); Ingress ingress3 = new IngressBuilder().withNewMetadata().withName("ingress3").withNamespace("any").and().build(); server.expect().withPath("/apis/extensions/v1beta1/namespaces/test/ingresses/ingress1").andReturn(200, ingress1).once(); server.expect().withPath("/apis/extensions/v1beta1/namespaces/ns1/ingresses/ingress2").andReturn(200, ingress2).once(); KubernetesClient client = server.getClient(); Boolean deleted = client.extensions().ingress().inAnyNamespace().delete(ingress1, ingress2); assertTrue(deleted); deleted = client.extensions().ingress().inAnyNamespace().delete(ingress3); assertFalse(deleted); }
Example #19
Source File: ExternalServerExposer.java From che with Eclipse Public License 2.0 | 6 votes |
/** * Exposes service port on given service externally (outside kubernetes cluster). The exposed * service port is associated with a specific Server configuration. Server configuration should be * encoded in the exposing object's annotations, to be used by {@link KubernetesServerResolver}. * * @param k8sEnv Kubernetes environment * @param machineName machine containing servers * @param serviceName service associated with machine, mapping all machine server ports * @param serverId non-null for a unique server, null for a compound set of servers that should be * exposed together. * @param servicePort specific service port to be exposed externally * @param externalServers server configs of servers to be exposed externally */ 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); }
Example #20
Source File: K8sIngressManager.java From onos with Apache License 2.0 | 6 votes |
@Override public void removeIngress(String uid) { checkArgument(!Strings.isNullOrEmpty(uid), ERR_NULL_INGRESS_UID); synchronized (this) { if (isIngressInUse(uid)) { final String error = String.format(MSG_INGRESS, uid, ERR_IN_USE); throw new IllegalStateException(error); } Ingress ingress = k8sIngressStore.removeIngress(uid); if (ingress != null) { log.info(String.format(MSG_INGRESS, ingress.getMetadata().getName(), MSG_REMOVED)); } } }
Example #21
Source File: IngressTlsProvisionerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void provisionTlsForIngressesWhenTlsEnabledAndSecretProvided() throws Exception { // given IngressTlsProvisioner ingressTlsProvisioner = new IngressTlsProvisioner(true, "secretname", "", ""); Map<String, Ingress> ingresses = new HashMap<>(); ingresses.put("ingress", ingress); when(k8sEnv.getIngresses()).thenReturn(ingresses); // when ingressTlsProvisioner.provision(k8sEnv, runtimeIdentity); // then assertEquals(ingress.getSpec().getTls().size(), 1); assertEquals(ingress.getSpec().getTls().get(0).getHosts().size(), 1); assertEquals(ingress.getSpec().getTls().get(0).getHosts().get(0), host); assertEquals(ingress.getSpec().getTls().get(0).getSecretName(), "secretname"); verifyIngressAndServersTLS(); }
Example #22
Source File: IngressTlsProvisionerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void provisionTlsForIngressesWhenTlsEnabledAndSecretEmpty() throws Exception { // given IngressTlsProvisioner ingressTlsProvisioner = new IngressTlsProvisioner(true, "", "", ""); Map<String, Ingress> ingresses = new HashMap<>(); ingresses.put("ingress", ingress); when(k8sEnv.getIngresses()).thenReturn(ingresses); // when ingressTlsProvisioner.provision(k8sEnv, runtimeIdentity); // then assertEquals(ingress.getSpec().getTls().size(), 1); assertEquals(ingress.getSpec().getTls().get(0).getHosts().size(), 1); assertEquals(ingress.getSpec().getTls().get(0).getHosts().get(0), host); assertEquals(ingress.getSpec().getTls().get(0).getSecretName(), null); verifyIngressAndServersTLS(); }
Example #23
Source File: KubernetesInternalRuntimeTest.java From che with Eclipse Public License 2.0 | 6 votes |
private static Ingress mockIngress() { final Ingress ingress = mock(Ingress.class); mockName(INGRESS_NAME, ingress); final IngressSpec spec = mock(IngressSpec.class); final IngressBackend backend = mock(IngressBackend.class); when(backend.getServiceName()).thenReturn(SERVICE_NAME); when(backend.getServicePort()).thenReturn(new IntOrString(EXPOSED_PORT_1)); when(spec.getBackend()).thenReturn(backend); final IngressRule rule = mock(IngressRule.class); when(rule.getHost()).thenReturn(INGRESS_HOST); when(spec.getRules()).thenReturn(singletonList(rule)); when(ingress.getSpec()).thenReturn(spec); when(ingress.getMetadata().getLabels()) .thenReturn(ImmutableMap.of(CHE_ORIGINAL_NAME_LABEL, INGRESS_NAME)); return ingress; }
Example #24
Source File: KafkaAssemblyOperator.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
Future<ReconciliationState> kafkaBootstrapIngress() { if (kafkaCluster.isExposedWithIngress()) { Ingress ingress = kafkaCluster.generateExternalBootstrapIngress(); if (kafkaCluster.getExternalListenerBootstrapOverride() != null && kafkaCluster.getExternalListenerBootstrapOverride().getAddress() != null) { log.debug("{}: Adding address {} from overrides to certificate DNS names", reconciliation, kafkaCluster.getExternalListenerBootstrapOverride().getAddress()); this.kafkaExternalBootstrapDnsName.add(kafkaCluster.getExternalListenerBootstrapOverride().getAddress()); } this.kafkaExternalBootstrapDnsName.add(ingress.getSpec().getRules().get(0).getHost()); return withVoid(ingressOperations.reconcile(namespace, KafkaCluster.serviceName(name), ingress)); } else { return withVoid(Future.succeededFuture()); } }
Example #25
Source File: ApolloToKubernetes.java From apollo with Apache License 2.0 | 6 votes |
public Ingress getKubernetesIngress() throws ApolloParseException { try { // Update the deployment, as it could have changed since (Status) apolloDeployment = deploymentDao.getDeployment(apolloDeployment.getId()); // Ingress are allowed to be null if (apolloService.getIngressYaml() == null) { return null; } // Convert the ingress object to fabric8 model Ingress ingress = getClassFromYamlWithParameters(apolloService.getIngressYaml(), jsonToMap(apolloEnvironment.getAdditionalParams()), Ingress.class); // Programmatically access to change all the stuff we need logger.debug("About to run {} transformations on the ingress yaml of deployment id {}", ingressTransformers.size(), apolloDeployment.getId()); ingressTransformers.forEach(transformer -> transformer.transform(ingress, apolloDeployment, apolloService, apolloEnvironment)); return ingress; } catch (IOException e) { throw new ApolloParseException("Could not parse ingress YAML from DB", e); } }
Example #26
Source File: IngressTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testGet() { server.expect().withPath("/apis/extensions/v1beta1/namespaces/test/ingresses/ingress1").andReturn(200, new IngressBuilder().build()).once(); server.expect().withPath("/apis/extensions/v1beta1/namespaces/ns1/ingresses/ingress2").andReturn(200, new IngressBuilder().build()).once(); KubernetesClient client = server.getClient(); Ingress ingress = client.extensions().ingress().withName("ingress1").get(); assertNotNull(ingress); ingress = client.extensions().ingress().withName("ingress2").get(); assertNull(ingress); ingress = client.extensions().ingress().inNamespace("ns1").withName("ingress2").get(); assertNotNull(ingress); }
Example #27
Source File: DefaultHostExternalServiceExposureStrategyTest.java From che with Eclipse Public License 2.0 | 5 votes |
@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.getServiceName())) { assertEquals(backend.getServicePort().getStrVal(), 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)); }
Example #28
Source File: K8sIngressManagerTest.java From onos with Apache License 2.0 | 5 votes |
private static Ingress createK8sIngress(String uid, String name) { ObjectMeta meta = new ObjectMeta(); meta.setUid(uid); meta.setName(name); Ingress ingress = new Ingress(); ingress.setApiVersion("v1"); ingress.setKind("Ingress"); ingress.setMetadata(meta); return ingress; }
Example #29
Source File: PreviewUrlExposerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldProvisionServiceAndIngressWhenNotFound() 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; CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()); KubernetesEnvironment env = KubernetesEnvironment.builder() .setCommands(singletonList(new CommandImpl(command))) .setIngresses(new HashMap<>()) .setServices(new HashMap<>()) .build(); previewUrlExposer.expose(env); assertEquals(env.getIngresses().size(), 1); assertEquals(env.getServices().size(), 1); Service provisionedService = env.getServices().values().iterator().next(); ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0); assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME); assertEquals(provisionedServicePort.getPort().intValue(), PORT); Ingress provisionedIngress = env.getIngresses().values().iterator().next(); IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend(); assertEquals(provisionedIngressBackend.getServicePort().getStrVal(), SERVER_PORT_NAME); assertEquals( provisionedIngressBackend.getServiceName(), provisionedService.getMetadata().getName()); }
Example #30
Source File: KubernetesInternalRuntime.java From che with Eclipse Public License 2.0 | 5 votes |
@Traced @SuppressWarnings("WeakerAccess") // package-private so that interception is possible List<Ingress> createIngresses(KubernetesEnvironment env, String workspaceId) throws InfrastructureException { TracingTags.WORKSPACE_ID.set(workspaceId); return createAndWaitReady(env.getIngresses().values()); }