io.fabric8.openshift.api.model.Route Java Examples
The following examples show how to use
io.fabric8.openshift.api.model.Route.
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: OpenShiftExternalServerExposer.java From che with Eclipse Public License 2.0 | 6 votes |
@Override public void expose( OpenShiftEnvironment env, String machineName, String serviceName, String serverId, ServicePort servicePort, Map<String, ServerConfig> externalServers) { Route commonRoute = new RouteBuilder() .withName(Names.generateName("route")) .withMachineName(machineName) .withTargetPort(servicePort.getName()) .withServers(externalServers) .withTo(serviceName) .build(); env.getRoutes().put(commonRoute.getMetadata().getName(), commonRoute); }
Example #2
Source File: OpenShiftServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingServersWhenThereIsNoTheCorrespondingServiceAndRouteForTheSpecifiedMachine() { // given Service nonMatchedByPodService = createService("nonMatched", "foreignMachine", CONTAINER_PORT, null); Route route = createRoute( "nonMatched", "foreignMachine", ImmutableMap.of( "http-server", new ServerConfigImpl("3054", "http", "/api", ATTRIBUTES_MAP))); OpenShiftServerResolver serverResolver = new OpenShiftServerResolver(singletonList(nonMatchedByPodService), singletonList(route)); // when Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); // then assertTrue(resolved.isEmpty()); }
Example #3
Source File: OpenShiftServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingServersWhenThereIsMatchedRouteForMachineAndServerPathIsNull() { Route route = createRoute( "matched", "machine", singletonMap( "http-server", new ServerConfigImpl("3054", "http", null, ATTRIBUTES_MAP))); OpenShiftServerResolver serverResolver = new OpenShiftServerResolver(emptyList(), singletonList(route)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("http://localhost") .withStatus(UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #4
Source File: OpenShiftServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingServersWhenThereIsMatchedRouteForMachineAndServerPathIsEmpty() { Route route = createRoute( "matched", "machine", singletonMap("http-server", new ServerConfigImpl("3054", "http", "", ATTRIBUTES_MAP))); OpenShiftServerResolver serverResolver = new OpenShiftServerResolver(emptyList(), singletonList(route)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("http://localhost") .withStatus(UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #5
Source File: HandlersTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test void checkHandlers() { checkHandler(new BuildConfig(), new BuildConfigHandler()); checkHandler(new Build(), new BuildHandler()); checkHandler(new DeploymentConfig(), new DeploymentConfigHandler()); checkHandler(new Group(), new GroupHandler()); checkHandler(new Identity(), new IdentityHandler()); checkHandler(new Image(), new ImageHandler()); checkHandler(new ImageStream(), new ImageStreamHandler()); checkHandler(new ImageStreamTag(), new ImageStreamTagHandler()); checkHandler(new NetNamespace(), new NetNamespaceHandler()); checkHandler(new OAuthAccessToken(), new OAuthAccessTokenHandler()); checkHandler(new OAuthAuthorizeToken(), new OAuthAuthorizeTokenHandler()); checkHandler(new OAuthClient(), new OAuthClientHandler()); checkHandler(new Project(), new ProjectHandler()); checkHandler(new Route(), new RouteHandler()); checkHandler(new SecurityContextConstraints(), new SecurityContextConstraintsHandler()); checkHandler(new User(), new UserHandler()); }
Example #6
Source File: OpenShiftServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingInternalServers() { Service service = createService( "service11", "machine", CONTAINER_PORT, singletonMap( "http-server", new ServerConfigImpl("3054", "http", "api", ATTRIBUTES_MAP))); Route route = createRoute("matched", "machine", null); OpenShiftServerResolver serverResolver = new OpenShiftServerResolver(singletonList(service), singletonList(route)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("http://service11:3054/api") .withStatus(UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #7
Source File: OpenShiftServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolvingInternalServersWithPortWithTransportProtocol() { Service service = createService( "service11", "machine", CONTAINER_PORT, singletonMap( "http-server", new ServerConfigImpl("3054/udp", "xxx", "api", ATTRIBUTES_MAP))); Route route = createRoute("matched", "machine", null); OpenShiftServerResolver serverResolver = new OpenShiftServerResolver(singletonList(service), singletonList(route)); Map<String, ServerImpl> resolved = serverResolver.resolve("machine"); assertEquals(resolved.size(), 1); assertEquals( resolved.get("http-server"), new ServerImpl() .withUrl("xxx://service11:3054/api") .withStatus(UNKNOWN) .withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054"))); }
Example #8
Source File: ApplyService.java From jkube with Eclipse Public License 2.0 | 6 votes |
public void applyRoute(Route entity, String sourceName) { OpenShiftClient openShiftClient = getOpenShiftClient(); if (openShiftClient != null) { String id = getName(entity); Objects.requireNonNull(id, "No name for " + entity + " " + sourceName); String namespace = KubernetesHelper.getNamespace(entity); if (StringUtils.isBlank(namespace)) { namespace = getNamespace(); } Route route = openShiftClient.routes().inNamespace(namespace).withName(id).get(); if (route == null) { try { log.info("Creating Route " + namespace + ":" + id + " " + (entity.getSpec() != null ? "host: " + entity.getSpec().getHost() : "No Spec !")); openShiftClient.routes().inNamespace(namespace).create(entity); } catch (Exception e) { onApplyError("Failed to create Route from " + sourceName + ". " + e + ". " + entity, e); } } } }
Example #9
Source File: OpenShiftServerResolverTest.java From che with Eclipse Public License 2.0 | 6 votes |
private Route createRoute( String name, String machineName, Map<String, ServerConfigImpl> servers) { Serializer serializer = Annotations.newSerializer(); serializer.machineName(machineName); if (servers != null) { serializer.servers(servers); } return new RouteBuilder() .withNewMetadata() .withName(name) .withAnnotations(serializer.annotations()) .endMetadata() .withNewSpec() .withHost(ROUTE_HOST) .withNewTo() .withName(name) .endTo() .endSpec() .build(); }
Example #10
Source File: RouteEnricherTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void testCreate() { // Given Service providedService = getTestService().build(); KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService); RouteEnricher routeEnricher = new RouteEnricher(context); // When routeEnricher.create(PlatformMode.openshift, kubernetesListBuilder); // Then Route route = (Route) kubernetesListBuilder.buildLastItem(); assertEquals(2, kubernetesListBuilder.buildItems().size()); assertNotNull(route); assertEquals(providedService.getMetadata().getName(), route.getMetadata().getName()); assertNotNull(route.getSpec()); assertEquals("Service", route.getSpec().getTo().getKind()); assertEquals("test-svc", route.getSpec().getTo().getName()); assertEquals(8080, route.getSpec().getPort().getTargetPort().getIntVal().intValue()); }
Example #11
Source File: OpenShift.java From enmasse with Apache License 2.0 | 6 votes |
@Override public void createExternalEndpoint(String name, String namespace, Service service, ServicePort targetPort) { Route route = new RouteBuilder() .editOrNewMetadata() .withName(name) .withNamespace(namespace) .endMetadata() .editOrNewSpec() .editOrNewPort() .withNewTargetPort(targetPort.getPort()) .endPort() .withNewTls() .withTermination("passthrough") .endTls() .withNewTo() .withName(service.getMetadata().getName()) .withKind("Service") .endTo() .endSpec() .build(); OpenShiftClient openShift = client.adapt(OpenShiftClient.class); openShift.routes().inNamespace(namespace).withName(name).createOrReplace(route); }
Example #12
Source File: RouteEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, final KubernetesListBuilder listBuilder) { ResourceConfig resourceConfig = getConfiguration().getResource(); if (resourceConfig != null && resourceConfig.getRouteDomain() != null) { routeDomainPostfix = resourceConfig.getRouteDomain(); } if(platformMode == PlatformMode.openshift && generateRoute.equals(Boolean.TRUE)) { final List<Route> routes = new ArrayList<>(); listBuilder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { addRoute(listBuilder, serviceBuilder, routes); } }); if (!routes.isEmpty()) { Route[] routeArray = new Route[routes.size()]; routes.toArray(routeArray); listBuilder.addToItems(routeArray); } } }
Example #13
Source File: RouteTlsProvisioner.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Traced public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity) throws InfrastructureException { TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId); if (!isTlsEnabled) { return; } final Set<Route> routes = new HashSet<>(osEnv.getRoutes().values()); for (Route route : routes) { useSecureProtocolForServers(route); enableTls(route); } }
Example #14
Source File: Routes.java From che with Eclipse Public License 2.0 | 6 votes |
/** * In given {@code routes} finds route that for given {@code service} and {@code port} * * @return found {@link Route} or {@link Optional#empty()} */ public static Optional<Route> findRouteForServicePort( Collection<Route> routes, Service service, int port) { Optional<ServicePort> foundPort = Services.findPort(service, port); if (!foundPort.isPresent()) { return Optional.empty(); } for (Route route : routes) { RouteSpec spec = route.getSpec(); if (spec.getTo().getName().equals(service.getMetadata().getName()) && matchesPort(foundPort.get(), spec.getPort().getTargetPort())) { return Optional.of(route); } } return Optional.empty(); }
Example #15
Source File: OpenShiftEnvironment.java From che with Eclipse Public License 2.0 | 6 votes |
public OpenShiftEnvironment( InternalRecipe internalRecipe, Map<String, InternalMachineConfig> machines, List<Warning> warnings, Map<String, Pod> pods, Map<String, Deployment> deployments, Map<String, Service> services, Map<String, Ingress> ingresses, Map<String, PersistentVolumeClaim> pvcs, Map<String, Secret> secrets, Map<String, ConfigMap> configMaps, Map<String, Route> routes) { super( internalRecipe, machines, warnings, pods, deployments, services, ingresses, pvcs, secrets, configMaps); setType(TYPE); this.routes = routes; }
Example #16
Source File: ServiceResourceUtilTest.java From kubernetes-pipeline-plugin with Apache License 2.0 | 6 votes |
@Test public void patchServiceNameAndRoute() throws Exception { // GIVEN envVars.set(ServiceResourceUtil.K8S_PIPELINE_SERVICE_PATCH, "enabled"); Set<HasMetadata> entities = getEntitiesFromResource("/services/invalidservice1.yaml"); ServiceResourceUtil util = new ServiceResourceUtil(); // WHEN util.patchServiceName(entities); // THEN HasMetadata service = getKind(entities, "Service"); Route route = (Route) getKind(entities, "Route"); assertEquals(2, entities.size()); assertFalse(util.hasInvalidDNS((Service) service)); assertEquals(service.getMetadata().getName(), route.getSpec().getTo().getName()); }
Example #17
Source File: ServiceResourceUtilTest.java From kubernetes-pipeline-plugin with Apache License 2.0 | 6 votes |
@Test public void patchServiceNameOnlyIfNoRouteToService() throws Exception { // GIVEN envVars.set(ServiceResourceUtil.K8S_PIPELINE_SERVICE_PATCH, "enabled"); Set<HasMetadata> entities = getEntitiesFromResource("/services/invalidservice3.yaml"); ServiceResourceUtil util = new ServiceResourceUtil(); // WHEN util.patchServiceName(entities); // THEN HasMetadata service = getKind(entities, "Service"); Route route = (Route) getKind(entities, "Route"); assertEquals(2, entities.size()); assertFalse(util.hasInvalidDNS((Service) service)); assertEquals("somelb", route.getSpec().getTo().getName()); }
Example #18
Source File: ServiceResourceUtilTest.java From kubernetes-pipeline-plugin with Apache License 2.0 | 6 votes |
@Test public void dontPatchValidServiceAndRoute() throws Exception { // GIVEN envVars.set(ServiceResourceUtil.K8S_PIPELINE_SERVICE_PATCH, "enabled"); Set<HasMetadata> entities = getEntitiesFromResource("/services/validservice3.yaml"); ServiceResourceUtil util = new ServiceResourceUtil(); // WHEN util.patchServiceName(entities); // THEN HasMetadata service = getKind(entities, "Service"); Route route = (Route) getKind(entities, "Route"); assertEquals(4, entities.size()); assertFalse(util.hasInvalidDNS((Service) service)); assertEquals("nodejs-rest-http", service.getMetadata().getName()); assertEquals("nodejs-rest-http", route.getSpec().getTo().getName()); }
Example #19
Source File: URLFromOpenshiftRouteImpl.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(Locale.ROOT); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }
Example #20
Source File: OpenShiftEnvironmentValidator.java From che with Eclipse Public License 2.0 | 6 votes |
private void validateRoutesMatchServices(OpenShiftEnvironment env) throws ValidationException { Set<String> recipeServices = env.getServices() .values() .stream() .map(s -> s.getMetadata().getName()) .collect(Collectors.toSet()); for (Route route : env.getRoutes().values()) { if (route.getSpec() == null || route.getSpec().getTo() == null || !route.getSpec().getTo().getKind().equals(SERVICE_KIND)) { continue; } String serviceName = route.getSpec().getTo().getName(); if (!recipeServices.contains(serviceName)) { throw new ValidationException( String.format( "Route '%s' refers to Service '%s'. Routes must refer to Services included in recipe", route.getMetadata().getName(), serviceName)); } } }
Example #21
Source File: TeiidOpenShiftClient.java From syndesis with Apache License 2.0 | 6 votes |
private RouteStatus getRoute(String openShiftName, ProtocolType protocolType) { String namespace = ApplicationProperties.getNamespace(); OpenShiftClient client = openshiftClient(); RouteStatus theRoute = null; debug(openShiftName, "Getting route of type " + protocolType.id() + " for Service"); Route route = client.routes().inNamespace(namespace).withName(openShiftName + StringConstants.HYPHEN + protocolType.id()).get(); if (route != null) { ObjectMeta metadata = route.getMetadata(); String name = metadata.getName(); RouteSpec spec = route.getSpec(); String target = spec.getTo().getName(); theRoute = new RouteStatus(name, protocolType); theRoute.setHost(spec.getHost()); theRoute.setPath(spec.getPath()); theRoute.setPort(spec.getPort().getTargetPort().getStrVal()); theRoute.setTarget(target); theRoute.setSecure(spec.getTls() != null); } return theRoute; }
Example #22
Source File: KafkaAssemblyOperator.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
Future<ReconciliationState> kafkaReplicaRoutes() { int replicas = kafkaCluster.getReplicas(); List<Future> routeFutures = new ArrayList<>(replicas); for (int i = 0; i < replicas; i++) { Route route = kafkaCluster.generateExternalRoute(i); if (pfa.hasRoutes()) { routeFutures.add(routeOperations.reconcile(namespace, KafkaCluster.externalServiceName(name, i), route)); } else if (route != null) { log.warn("{}: The OpenShift route API is not available in this Kubernetes cluster. Exposing Kafka cluster {} using routes is not possible.", reconciliation, name); return withVoid(Future.failedFuture("The OpenShift route API is not available in this Kubernetes cluster. Exposing Kafka cluster " + name + " using routes is not possible.")); } } return withVoid(CompositeFuture.join(routeFutures)); }
Example #23
Source File: OpenShiftExternalServerExposer.java From che with Eclipse Public License 2.0 | 6 votes |
private Route build() { io.fabric8.openshift.api.model.RouteBuilder builder = new io.fabric8.openshift.api.model.RouteBuilder(); return builder .withNewMetadata() .withName(name.replace("/", "-")) .withAnnotations( Annotations.newSerializer().servers(servers).machineName(machineName).annotations()) .endMetadata() .withNewSpec() .withNewTo() .withName(serviceName) .endTo() .withNewPort() .withTargetPort(targetPort) .endPort() .endSpec() .build(); }
Example #24
Source File: RouteTlsProvisionerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void provisionTlsForRoutes() throws Exception { // given RouteTlsProvisioner tlsProvisioner = new RouteTlsProvisioner(true); ServerConfigImpl httpServer = new ServerConfigImpl("8080/tpc", "http", "/api", emptyMap()); ServerConfigImpl wsServer = new ServerConfigImpl("8080/tpc", "ws", "/ws", emptyMap()); final Map<String, Route> routes = new HashMap<>(); Route route = createRoute("route", ImmutableMap.of("http-server", httpServer, "ws-server", wsServer)); routes.put("route", route); when(osEnv.getRoutes()).thenReturn(routes); // when tlsProvisioner.provision(osEnv, runtimeIdentity); // then assertEquals(route.getSpec().getTls().getTermination(), TERMINATION_EDGE); assertEquals( route.getSpec().getTls().getInsecureEdgeTerminationPolicy(), TERMINATION_POLICY_REDIRECT); Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(route.getMetadata().getAnnotations()).servers(); assertEquals(servers.get("http-server").getProtocol(), "https"); assertEquals(servers.get("ws-server").getProtocol(), "wss"); }
Example #25
Source File: RouteIT.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void delete() { ReadyEntity<Route> route1Ready = new ReadyEntity<>(Route.class, client, "route1", this.currentNamespace); await().atMost(30, TimeUnit.SECONDS).until(route1Ready); boolean bDeleted = client.routes().inNamespace(currentNamespace).withName("route1").delete(); assertTrue(bDeleted); }
Example #26
Source File: OpenShiftRoutes.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Returns all existing routes. * * @throws InfrastructureException when any exception occurs */ public List<Route> get() throws InfrastructureException { try { return clientFactory .createOC(workspaceId) .routes() .inNamespace(namespace) .withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId) .list() .getItems(); } catch (KubernetesClientException e) { throw new KubernetesInfrastructureException(e); } }
Example #27
Source File: OpenShiftEnvironment.java From che with Eclipse Public License 2.0 | 5 votes |
public OpenShiftEnvironment( InternalEnvironment internalEnvironment, Map<String, Pod> pods, Map<String, Deployment> deployments, Map<String, Service> services, Map<String, Ingress> ingresses, Map<String, PersistentVolumeClaim> pvcs, Map<String, Secret> secrets, Map<String, ConfigMap> configMaps, Map<String, Route> routes) { super(internalEnvironment, pods, deployments, services, ingresses, pvcs, secrets, configMaps); setType(TYPE); this.routes = routes; }
Example #28
Source File: OpenShiftPreviewUrlCommandProvisioner.java From che with Eclipse Public License 2.0 | 5 votes |
@Override protected List<Route> loadExposureObjects(KubernetesNamespace namespace) throws InfrastructureException { if (!(namespace instanceof OpenShiftProject)) { throw new InternalInfrastructureException( String.format( "OpenShiftProject instance expected, but got '%s'. Please report a bug!", namespace.getClass().getCanonicalName())); } OpenShiftProject project = (OpenShiftProject) namespace; return project.routes().get(); }
Example #29
Source File: OpenShiftInternalRuntime.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Traced protected void startMachines() throws InfrastructureException { OpenShiftEnvironment osEnv = getContext().getEnvironment(); String workspaceId = getContext().getIdentity().getWorkspaceId(); createSecrets(osEnv, workspaceId); createConfigMaps(osEnv, workspaceId); List<Service> createdServices = createServices(osEnv, workspaceId); List<Route> createdRoutes = createRoutes(osEnv, workspaceId); listenEvents(); doStartMachine(new OpenShiftServerResolver(createdServices, createdRoutes)); }
Example #30
Source File: OpenShiftRoutes.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Creates specified route. * * @param route route to create * @return created route * @throws InfrastructureException when any exception occurs */ public Route create(Route route) throws InfrastructureException { putLabel(route, CHE_WORKSPACE_ID_LABEL, workspaceId); try { return clientFactory.createOC(workspaceId).routes().inNamespace(namespace).create(route); } catch (KubernetesClientException e) { throw new KubernetesInfrastructureException(e); } }