io.fabric8.kubernetes.api.model.ServiceSpec Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.ServiceSpec.
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: RouteEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
private RoutePort createRoutePort(ServiceBuilder serviceBuilder) { RoutePort routePort = null; ServiceSpec spec = serviceBuilder.buildSpec(); if (spec != null) { List<ServicePort> ports = spec.getPorts(); if (ports != null && !ports.isEmpty()) { ServicePort servicePort = ports.get(0); if (servicePort != null) { IntOrString targetPort = servicePort.getTargetPort(); if (targetPort != null) { routePort = new RoutePort(); routePort.setTargetPort(targetPort); } } } } return routePort; }
Example #2
Source File: IngressEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
private static Integer getServicePort(ServiceBuilder serviceBuilder) { ServiceSpec spec = serviceBuilder.buildSpec(); if (spec != null) { List<ServicePort> ports = spec.getPorts(); if (ports != null && !ports.isEmpty()) { for (ServicePort port : ports) { if (port.getName().equals("http") || port.getProtocol().equals("http")) { return port.getPort(); } } ServicePort servicePort = ports.get(0); if (servicePort != null) { return servicePort.getPort(); } } } return 0; }
Example #3
Source File: IngressEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
/** * Should we try to create an external URL for the given service? * <p> * By default lets ignore the kubernetes services and any service which does not expose ports 80 and 443 * * @return true if we should create an Ingress for this service. */ private static boolean shouldCreateExternalURLForService(ServiceBuilder service, KitLogger log) { String serviceName = service.buildMetadata().getName(); ServiceSpec spec = service.buildSpec(); if (spec != null && !isKuberentesSystemService(serviceName)) { List<ServicePort> ports = spec.getPorts(); log.debug("Service " + serviceName + " has ports: " + ports); if (ports.size() == 1) { String type = spec.getType(); if (Objects.equals(type, "LoadBalancer")) { return true; } log.info("Not generating Ingress for service " + serviceName + " type is not LoadBalancer: " + type); } else { log.info("Not generating Ingress for service " + serviceName + " as only single port services are supported. Has ports: " + ports); } } return false; }
Example #4
Source File: CustomServiceController.java From java-operator-sdk with Apache License 2.0 | 6 votes |
@Override public Optional<CustomService> createOrUpdateResource(CustomService resource) { log.info("Execution createOrUpdateResource for: {}", resource.getMetadata().getName()); ServicePort servicePort = new ServicePort(); servicePort.setPort(8080); ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts(Arrays.asList(servicePort)); kubernetesClient.services().inNamespace(resource.getMetadata().getNamespace()).createOrReplaceWithNew() .withNewMetadata() .withName(resource.getSpec().getName()) .addToLabels("testLabel", resource.getSpec().getLabel()) .endMetadata() .withSpec(serviceSpec) .done(); return Optional.of(resource); }
Example #5
Source File: MockKubernetesServerSupport.java From kogito-runtimes with Apache License 2.0 | 6 votes |
protected void createMockService(final String serviceName, final String ip, final Map<String, String> labels, final String namespace) { final ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080)))); serviceSpec.setClusterIP(ip); serviceSpec.setType("ClusterIP"); serviceSpec.setSessionAffinity("ClientIP"); final ObjectMeta metadata = new ObjectMeta(); metadata.setName(serviceName); metadata.setNamespace(MOCK_NAMESPACE); metadata.setLabels(labels); final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus())); if (namespace != null) { this.server.getClient().inNamespace(namespace).services().create(service); } else { this.server.getClient().services().create(service); } }
Example #6
Source File: KubernetesDiscoveredServiceWorkItemHandlerTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testGivenServiceExists() { final ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080)))); serviceSpec.setClusterIP("172.30.158.31"); serviceSpec.setType("ClusterIP"); serviceSpec.setSessionAffinity("ClientIP"); final ObjectMeta metadata = new ObjectMeta(); metadata.setName("test-kieserver"); metadata.setNamespace(MOCK_NAMESPACE); metadata.setLabels(Collections.singletonMap("test-kieserver", "service")); final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus())); getClient().services().create(service); final DiscoveredServiceWorkItemHandler handler = new TestDiscoveredServiceWorkItemHandler(this); final ServiceInfo serviceInfo = handler.findEndpoint(MOCK_NAMESPACE, "test-kieserver"); assertThat(serviceInfo, notNullValue()); assertThat(serviceInfo.getUrl(), is("http://172.30.158.31:8080/test-kieserver")); }
Example #7
Source File: KubernetesMockTest.java From vxms with Apache License 2.0 | 6 votes |
@Test public void findServices() { final ObjectMeta build = new ObjectMetaBuilder().addToLabels("test", "test").build(); final ServiceSpec spec = new ServiceSpecBuilder().addNewPort().and().withClusterIP("192.168.1.1").build(); final Service service = new ServiceBuilder().withMetadata(build).withSpec(spec).build(); server .expect() .withPath("/api/v1/namespaces/default/services") .andReturn(200, new ServiceListBuilder().addToItems().addToItems(service).build()) .once(); KubernetesClient client = this.client; final ServiceList list = client.services().inNamespace("default").list(); assertNotNull(list); assertEquals("test", list.getItems().get(0).getMetadata().getLabels().get("test")); System.out.println(list.getItems().get(0).getSpec().getClusterIP()); }
Example #8
Source File: OpenShiftPreviewUrlCommandProvisionerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldDoNothingWhenCantFindRouteForPreviewUrl() throws InfrastructureException { int port = 8080; List<CommandImpl> commands = Collections.singletonList( new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap())); OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build(); Mockito.when(mockProject.services()).thenReturn(mockServices); Service service = new Service(); ServiceSpec spec = new ServiceSpec(); spec.setPorts( Collections.singletonList(new ServicePort("a", null, port, "TCP", new IntOrString(port)))); service.setSpec(spec); Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service)); Mockito.when(mockProject.routes()).thenReturn(mockRoutes); Mockito.when(mockRoutes.get()).thenReturn(Collections.emptyList()); previewUrlCommandProvisioner.provision(env, mockProject); assertTrue(commands.containsAll(env.getCommands())); assertTrue(env.getCommands().containsAll(commands)); assertEquals( env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL); }
Example #9
Source File: TemplateTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
protected static void assertListIsServiceWithPort8080(List<HasMetadata> items) { assertNotNull(items); assertEquals(1, items.size()); HasMetadata item = items.get(0); assertTrue(item instanceof Service); Service service = (Service) item; ServiceSpec serviceSpec = service.getSpec(); assertNotNull(serviceSpec); List<ServicePort> ports = serviceSpec.getPorts(); assertEquals(1, ports.size()); ServicePort port = ports.get(0); assertEquals(new Integer(8080), port.getPort()); }
Example #10
Source File: OpenShiftPreviewUrlCommandProvisionerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException { int port = 8080; List<CommandImpl> commands = Collections.singletonList( new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap())); OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build(); Mockito.when(mockProject.services()).thenReturn(mockServices); Service service = new Service(); ObjectMeta metadata = new ObjectMeta(); metadata.setName("servicename"); service.setMetadata(metadata); ServiceSpec spec = new ServiceSpec(); spec.setPorts( Collections.singletonList( new ServicePort("8080", null, port, "TCP", new IntOrString(port)))); service.setSpec(spec); Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service)); Route route = new Route(); RouteSpec routeSpec = new RouteSpec(); routeSpec.setPort(new RoutePort(new IntOrString("8080"))); routeSpec.setTo(new RouteTargetReference("a", "servicename", 1)); routeSpec.setHost("testhost"); route.setSpec(routeSpec); Mockito.when(mockProject.routes()).thenReturn(mockRoutes); Mockito.when(mockRoutes.get()).thenReturn(Collections.singletonList(route)); previewUrlCommandProvisioner.provision(env, mockProject); assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl")); assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost"); assertTrue(env.getWarnings().isEmpty()); }
Example #11
Source File: OpenShiftInternalRuntimeTest.java From che with Eclipse Public License 2.0 | 5 votes |
private static Service mockService() { final Service service = mock(Service.class); final ServiceSpec spec = mock(ServiceSpec.class); mockName(SERVICE_NAME, service); when(service.getSpec()).thenReturn(spec); when(spec.getSelector()).thenReturn(ImmutableMap.of(POD_SELECTOR, POD_NAME)); final ServicePort sp1 = new ServicePortBuilder().withTargetPort(intOrString(EXPOSED_PORT_1)).build(); final ServicePort sp2 = new ServicePortBuilder().withTargetPort(intOrString(EXPOSED_PORT_2)).build(); when(spec.getPorts()).thenReturn(ImmutableList.of(sp1, sp2)); return service; }
Example #12
Source File: OpenShiftPreviewUrlExposerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldNotProvisionWhenServiceAndRouteFound() throws InternalInfrastructureException { final int PORT = 8080; final String SERVER_PORT_NAME = "server-" + PORT; CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()); Service service = new Service(); ObjectMeta serviceMeta = new ObjectMeta(); serviceMeta.setName("servicename"); service.setMetadata(serviceMeta); ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts( singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT)))); service.setSpec(serviceSpec); Route route = new Route(); RouteSpec routeSpec = new RouteSpec(); routeSpec.setPort(new RoutePort(new IntOrString(SERVER_PORT_NAME))); routeSpec.setTo(new RouteTargetReference("routekind", "servicename", 1)); route.setSpec(routeSpec); Map<String, Service> services = new HashMap<>(); services.put("servicename", service); Map<String, Route> routes = new HashMap<>(); routes.put("routename", route); OpenShiftEnvironment env = OpenShiftEnvironment.builder() .setCommands(singletonList(new CommandImpl(command))) .setServices(services) .setRoutes(routes) .build(); assertEquals(env.getRoutes().size(), 1); previewUrlEndpointsProvisioner.expose(env); assertEquals(env.getRoutes().size(), 1); }
Example #13
Source File: OpenShiftPreviewUrlExposerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldProvisionRouteWhenNotFound() throws InternalInfrastructureException { 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(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT)))); service.setSpec(serviceSpec); Map<String, Service> services = new HashMap<>(); services.put(SERVICE_NAME, service); OpenShiftEnvironment env = OpenShiftEnvironment.builder() .setCommands(singletonList(new CommandImpl(command))) .setServices(services) .setRoutes(new HashMap<>()) .build(); previewUrlEndpointsProvisioner.expose(env); assertEquals(env.getRoutes().size(), 1); Route provisionedRoute = env.getRoutes().values().iterator().next(); assertEquals(provisionedRoute.getSpec().getTo().getName(), SERVICE_NAME); assertEquals( provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME); }
Example #14
Source File: RoutesTest.java From che with Eclipse Public License 2.0 | 5 votes |
private Service createService(String portString, int portInt) { Service service = new Service(); ObjectMeta metadata = new ObjectMeta(); metadata.setName("servicename"); service.setMetadata(metadata); ServiceSpec spec = new ServiceSpec(); spec.setPorts( Collections.singletonList(new ServicePort(portString, null, portInt, "TCP", null))); service.setSpec(spec); return service; }
Example #15
Source File: KubernetesObjectUtil.java From che with Eclipse Public License 2.0 | 5 votes |
/** Adds selector into target Kubernetes service. */ public static void putSelector(Service target, String key, String value) { ServiceSpec spec = target.getSpec(); if (spec == null) { target.setSpec(spec = new ServiceSpec()); } Map<String, String> selector = spec.getSelector(); if (selector == null) { spec.setSelector(selector = new HashMap<>()); } selector.put(key, value); }
Example #16
Source File: KubernetesPreviewUrlCommandProvisionerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldDoNothingWhenCantFindIngressForPreviewUrl() throws InfrastructureException { int port = 8080; List<CommandImpl> commands = Collections.singletonList( new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap())); KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build(); Mockito.when(mockNamespace.services()).thenReturn(mockServices); Service service = new Service(); ServiceSpec spec = new ServiceSpec(); spec.setPorts( Collections.singletonList(new ServicePort("a", null, port, "TCP", new IntOrString(port)))); service.setSpec(spec); Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service)); Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses); Mockito.when(mockIngresses.get()).thenReturn(Collections.emptyList()); previewUrlCommandProvisioner.provision(env, mockNamespace); assertTrue(commands.containsAll(env.getCommands())); assertTrue(env.getCommands().containsAll(commands)); assertEquals( env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL); }
Example #17
Source File: KubernetesInternalRuntimeTest.java From che with Eclipse Public License 2.0 | 5 votes |
private static Service mockService() { final Service service = mock(Service.class); final ServiceSpec spec = mock(ServiceSpec.class); mockName(SERVICE_NAME, service); when(service.getSpec()).thenReturn(spec); when(spec.getSelector()).thenReturn(ImmutableMap.of(POD_SELECTOR, WORKSPACE_POD_NAME)); final ServicePort sp1 = new ServicePortBuilder().withTargetPort(intOrString(EXPOSED_PORT_1)).build(); final ServicePort sp2 = new ServicePortBuilder().withTargetPort(intOrString(EXPOSED_PORT_2)).build(); when(spec.getPorts()).thenReturn(ImmutableList.of(sp1, sp2)); return service; }
Example #18
Source File: PreviewUrlExposerTest.java From che with Eclipse Public License 2.0 | 5 votes |
@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(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.getServicePort().getStrVal(), SERVER_PORT_NAME); assertEquals(provisionedIngressBackend.getServiceName(), SERVICE_NAME); }
Example #19
Source File: IngressesTest.java From che with Eclipse Public License 2.0 | 5 votes |
private Service createService(String serverPortName, int port) { Service service = new Service(); ObjectMeta serviceMeta = new ObjectMeta(); serviceMeta.setName("servicename"); service.setMetadata(serviceMeta); ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts( singletonList(new ServicePort(serverPortName, null, port, "TCP", new IntOrString(port)))); service.setSpec(serviceSpec); return service; }
Example #20
Source File: ServicesTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void testFindPortWhenExists() { final int PORT = 1234; Service service = new Service(); ServiceSpec spec = new ServiceSpec(); ServicePort port = new ServicePort(); port.setPort(PORT); spec.setPorts(Arrays.asList(port, new ServicePort())); service.setSpec(spec); assertEquals(Services.findPort(service, PORT).get(), port); }
Example #21
Source File: ServicesTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void testFindServiceWhenExists() { final int PORT = 1234; Service service = new Service(); ServiceSpec spec = new ServiceSpec(); ServicePort port = new ServicePort(); port.setPort(PORT); spec.setPorts(Collections.singletonList(port)); service.setSpec(spec); assertEquals( Services.findServiceWithPort(Arrays.asList(service, new Service()), PORT).get(), service); }
Example #22
Source File: ExposeEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private boolean hasWebPort(Service service) { ServiceSpec spec = service.getSpec(); if (spec != null) { List<ServicePort> ports = spec.getPorts(); if (ports != null) { for (ServicePort port : ports) { Integer portNumber = port.getPort(); if (portNumber != null && webPorts.contains(portNumber)) { return true; } } } } return false; }
Example #23
Source File: RouteEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private Set<Integer> getPorts(ServiceBuilder service) { Set<Integer> answer = new HashSet<>(); if (service != null) { ServiceSpec spec = getOrCreateSpec(service); for (ServicePort port : spec.getPorts()) { answer.add(port.getPort()); } } return answer; }
Example #24
Source File: DefaultServiceEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void addDefaultService(KubernetesListBuilder builder, Service defaultService) { if (defaultService == null) { return; } ServiceSpec spec = defaultService.getSpec(); List<ServicePort> ports = spec.getPorts(); if (!ports.isEmpty()) { log.info("Adding a default service '%s' with ports [%s]", defaultService.getMetadata().getName(), formatPortsAsList(ports)); } else { log.info("Adding headless default service '%s'", defaultService.getMetadata().getName()); } builder.addToServiceItems(defaultService); }
Example #25
Source File: ThorntailOnKubernetesTest.java From dekorate with Apache License 2.0 | 5 votes |
@Test void shouldContainDeployment() { KubernetesList list = Serialization.unmarshalAsList(ThorntailOnKubernetesTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml")); assertNotNull(list); Optional<Deployment> deployment = findFirst(list, Deployment.class); assertTrue(deployment.isPresent()); Deployment d = deployment.get(); List<Container> containers = d.getSpec().getTemplate().getSpec().getContainers(); assertEquals(1, containers.size()); Container container = containers.get(0); assertEquals(1, container.getPorts().size()); assertEquals("http", container.getPorts().get(0).getName()); assertEquals(9090, container.getPorts().get(0).getContainerPort()); HTTPGetAction livenessProbe = container.getLivenessProbe().getHttpGet(); assertNotNull(livenessProbe); assertEquals("/health", livenessProbe.getPath()); assertEquals(9090, livenessProbe.getPort().getIntVal()); assertEquals(180, container.getLivenessProbe().getInitialDelaySeconds()); HTTPGetAction readinessProbe = container.getReadinessProbe().getHttpGet(); assertNotNull(readinessProbe); assertEquals("/health", readinessProbe.getPath()); assertEquals(9090, readinessProbe.getPort().getIntVal()); assertEquals(20, container.getReadinessProbe().getInitialDelaySeconds()); Optional<Service> service = findFirst(list, Service.class); assertTrue(service.isPresent()); ServiceSpec s = service.get().getSpec(); assertEquals(1, s.getPorts().size()); assertEquals("http", s.getPorts().get(0).getName()); assertEquals(9090, s.getPorts().get(0).getPort()); assertEquals(9090, s.getPorts().get(0).getTargetPort().getIntVal()); }
Example #26
Source File: TillerInstaller.java From microbean-helm with Apache License 2.0 | 5 votes |
protected ServiceSpec createServiceSpec(final Map<String, String> labels) { final ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setType("ClusterIP"); final ServicePort servicePort = new ServicePort(); servicePort.setName(DEFAULT_NAME); servicePort.setPort(Integer.valueOf(44134)); servicePort.setTargetPort(new IntOrString(DEFAULT_NAME)); serviceSpec.setPorts(Arrays.asList(servicePort)); serviceSpec.setSelector(normalizeLabels(labels)); return serviceSpec; }
Example #27
Source File: ResolveServicesByNameTest.java From vxms with Apache License 2.0 | 5 votes |
public void initService() { final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("test", "test").withName("myTestService").build(); final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build(); final ServiceSpec specmyTestService = new ServiceSpecBuilder() .addNewPort() .and() .withClusterIP("192.168.1.1") .withPorts(portmyTestService) .build(); final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("test", "test2").withName("myTestService2").build(); final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build(); final ServiceSpec specmyTestService2 = new ServiceSpecBuilder() .addNewPort() .and() .withClusterIP("192.168.1.2") .withPorts(portmyTestService2) .build(); final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build(); final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build(); server .expect() .withPath("/api/v1/namespaces/default/services") .andReturn( 200, new ServiceListBuilder() .addToItems(servicemyTestService, servicemyTestService2) .build()) .times(2); }
Example #28
Source File: ResolveServicesByLabelsConfigAndPortOKOfflineTest.java From vxms with Apache License 2.0 | 4 votes |
public void initService() { final ObjectMeta buildmyTestService = new ObjectMetaBuilder() .addToLabels("name", "myTestService") .addToLabels("version", "v1") .withName("myTestService") .build(); final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build(); final ServiceSpec specmyTestService = new ServiceSpecBuilder() .addNewPort() .and() .withClusterIP("192.168.1.1") .withPorts(portmyTestService) .build(); final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder() .addToLabels("name", "myTestService") .addToLabels("version", "v2") .withName("myTestService2") .build(); final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build(); final ServiceSpec specmyTestService2 = new ServiceSpecBuilder() .addNewPort() .and() .withClusterIP("192.168.1.2") .withPorts(portmyTestService2) .build(); final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build(); final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build(); server .expect() .withPath( "/api/v1/namespaces/default/services?labelSelector=name%3DmyTestService,version%3Dv1") .andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService).build()) .times(1); server .expect() .withPath( "/api/v1/namespaces/default/services?labelSelector=name%3DmyTestService,version%3Dv2") .andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService2).build()) .times(1); }
Example #29
Source File: ThorntailOnOpenshiftTest.java From dekorate with Apache License 2.0 | 4 votes |
@Test void shouldContainDeployment() { KubernetesList list = Serialization.unmarshalAsList(ThorntailOnOpenshiftTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/openshift.yml")); assertNotNull(list); Optional<DeploymentConfig> deploymentConfig = findFirst(list, DeploymentConfig.class); assertTrue(deploymentConfig.isPresent()); DeploymentConfig d = deploymentConfig.get(); List<Container> containers = d.getSpec().getTemplate().getSpec().getContainers(); assertEquals(1, containers.size()); Container container = containers.get(0); assertEquals(1, container.getPorts().size()); assertEquals("http", container.getPorts().get(0).getName()); assertEquals(8080, container.getPorts().get(0).getContainerPort()); HTTPGetAction livenessProbe = container.getLivenessProbe().getHttpGet(); assertNotNull(livenessProbe); assertEquals("/health", livenessProbe.getPath()); assertEquals(8080, livenessProbe.getPort().getIntVal()); assertEquals(180, container.getLivenessProbe().getInitialDelaySeconds()); HTTPGetAction readinessProbe = container.getReadinessProbe().getHttpGet(); assertNotNull(readinessProbe); assertEquals("/health", readinessProbe.getPath()); assertEquals(8080, readinessProbe.getPort().getIntVal()); assertEquals(20, container.getReadinessProbe().getInitialDelaySeconds()); Optional<Service> service = findFirst(list, Service.class); assertTrue(service.isPresent()); ServiceSpec s = service.get().getSpec(); assertEquals(1, s.getPorts().size()); assertEquals("http", s.getPorts().get(0).getName()); assertEquals(8080, s.getPorts().get(0).getPort()); assertEquals(8080, s.getPorts().get(0).getTargetPort().getIntVal()); Optional<Route> route = findFirst(list, Route.class); assertTrue(route.isPresent()); RouteSpec r = route.get().getSpec(); assertEquals(8080, r.getPort().getTargetPort().getIntVal()); assertEquals("/", r.getPath()); }
Example #30
Source File: PreviewUrlExposerTest.java From che with Eclipse Public License 2.0 | 4 votes |
@Test public void shouldNotProvisionWhenServiceAndIngressFound() throws InternalInfrastructureException { final int PORT = 8080; final String SERVER_PORT_NAME = "server-" + PORT; CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()); Service service = new Service(); ObjectMeta serviceMeta = new ObjectMeta(); serviceMeta.setName("servicename"); service.setMetadata(serviceMeta); ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts( singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT)))); service.setSpec(serviceSpec); Ingress ingress = new Ingress(); ObjectMeta ingressMeta = new ObjectMeta(); ingressMeta.setName("ingressname"); ingress.setMetadata(ingressMeta); IngressSpec ingressSpec = new IngressSpec(); IngressRule ingressRule = new IngressRule(); ingressRule.setHost("ingresshost"); IngressBackend ingressBackend = new IngressBackend("servicename", new IntOrString(SERVER_PORT_NAME)); ingressRule.setHttp( new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null)))); ingressSpec.setRules(singletonList(ingressRule)); ingress.setSpec(ingressSpec); Map<String, Service> services = new HashMap<>(); services.put("servicename", service); Map<String, Ingress> ingresses = new HashMap<>(); ingresses.put("ingressname", ingress); KubernetesEnvironment env = KubernetesEnvironment.builder() .setCommands(singletonList(new CommandImpl(command))) .setServices(services) .setIngresses(ingresses) .build(); assertEquals(env.getIngresses().size(), 1); previewUrlExposer.expose(env); assertEquals(env.getIngresses().size(), 1); }