io.fabric8.openshift.api.model.RouteBuilder Java Examples

The following examples show how to use io.fabric8.openshift.api.model.RouteBuilder. 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: OpenShiftEnvironmentValidatorTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Make route for use in tests. If serviceName is null, return a route that does not refer to a
 * service.
 */
private Route makeRoute(String routeName, String serviceName) {
  RouteBuilder routeBuilder =
      new RouteBuilder().withNewMetadata().withName(routeName).endMetadata();
  if (serviceName != null) {
    routeBuilder
        .withNewSpec()
        .withNewTo()
        .withKind("Service")
        .withName(serviceName)
        .endTo()
        .endSpec();
  } else {
    routeBuilder.withNewSpec().endSpec();
  }
  return routeBuilder.build();
}
 
Example #2
Source File: OpenShiftServerResolverTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
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 #3
Source File: OpenShift.java    From enmasse with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: ServiceIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void getURL() {
  // Testing NodePort Impl
  String url = client.services().inNamespace(currentNamespace).withName("svc1").getURL("http");
  assertNotNull(url);

  // Testing Ingress Impl
  Ingress ingress = client.extensions().ingresses().load(getClass().getResourceAsStream("/test-ingress.yml")).get();
  client.extensions().ingresses().inNamespace(currentNamespace).create(ingress);

  url = client.services().inNamespace(currentNamespace).withName("svc2").getURL("80");
  assertNotNull(url);

  // Testing OpenShift Route Impl
  Service svc3 = client.services().inNamespace(currentNamespace).create(new ServiceBuilder()
      .withNewMetadata().withName("svc3").endMetadata()
      .withNewSpec()
      .addNewPort().withName("80").withProtocol("TCP").withPort(80).endPort()
      .endSpec()
      .build());

  OpenShiftClient openshiftClient = client.adapt(OpenShiftClient.class);
  openshiftClient.routes().inNamespace(currentNamespace).create(new RouteBuilder()
    .withNewMetadata().withName(svc3.getMetadata().getName()).endMetadata()
    .withNewSpec()
    .withHost("www.example.com")
    .withNewTo().withName(svc3.getMetadata().getName()).withKind("Service").endTo()
    .endSpec()
    .build());

  url = client.services().inNamespace(currentNamespace).withName("svc3").getURL("80");
  assertNotNull(url);
}
 
Example #5
Source File: RouteEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void addRoute(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder, List<Route> routes) {
    ObjectMeta serviceMetadata = serviceBuilder.buildMetadata();

    if (serviceMetadata != null && StringUtils.isNotBlank(serviceMetadata.getName())
            && hasExactlyOneServicePort(serviceBuilder, serviceMetadata.getName()) && isExposedService(serviceMetadata)) {
        String name = serviceMetadata.getName();
        if (!hasRoute(listBuilder, name)) {
            if (StringUtils.isNotBlank(routeDomainPostfix)) {
                routeDomainPostfix = prepareHostForRoute(routeDomainPostfix, name);
            } else {
                routeDomainPostfix = "";
            }

            RoutePort routePort = createRoutePort(serviceBuilder);
            if (routePort != null) {
                RouteBuilder routeBuilder = new RouteBuilder().
                        withMetadata(serviceMetadata).
                        withNewSpec().
                        withPort(routePort).
                        withNewTo().withKind("Service").withName(name).endTo().
                        withHost(routeDomainPostfix.isEmpty() ? null : routeDomainPostfix).
                        endSpec();

                // removing `expose : true` label from metadata.
                removeLabel(routeBuilder.buildMetadata(), EXPOSE_LABEL, "true");
                removeLabel(routeBuilder.buildMetadata(), JKubeAnnotations.SERVICE_EXPOSE_URL.value(), "true");
                routeBuilder.withNewMetadataLike(routeBuilder.buildMetadata());
                routes.add(routeBuilder.build());
            }
        }
    }
}
 
Example #6
Source File: RouteIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
  currentNamespace = session.getNamespace();
  route1 = new RouteBuilder()
    .withNewMetadata().withName("route1").endMetadata()
    .withNewSpec().withHost("www.example.com").withNewTo().withKind("Service").withName("service-name1").endTo().endSpec()
    .build();
  route2 = new RouteBuilder()
    .withNewMetadata().withName("route2").endMetadata()
    .withNewSpec().withNewTo().withKind("Service").withName("service-name2").endTo().endSpec()
    .build();

  client.routes().inNamespace(currentNamespace).create(route1);
  client.routes().inNamespace(currentNamespace).create(route2);
}
 
Example #7
Source File: RouteCrudTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCrud() {
  OpenShiftClient client = server.getOpenshiftClient();

  Route route1 = new RouteBuilder().withNewMetadata().withName("route1")
    .addToLabels("foo", "bar")
    .and().build();
  Route route2 = new RouteBuilder().withNewMetadata().withName("route2")
    .addToLabels("foo", "bar")
    .and().build();
  Route route3 = new RouteBuilder().withNewMetadata().withName("route3")
    .addToLabels("foo", "bar")
    .and().build();

  client.routes().inNamespace("ns1").create(route1);
  client.routes().inNamespace("ns1").create(route2);
  client.routes().inNamespace("ns2").create(route3);

  RouteList aRouteList = client.routes().list();
  assertNotNull(aRouteList);
  assertEquals(0, aRouteList.getItems().size());

  aRouteList = client.routes().inAnyNamespace().list();
  assertNotNull(aRouteList);
  assertEquals(3, aRouteList.getItems().size());

  aRouteList = client.routes().inNamespace("ns1").list();
  assertNotNull(aRouteList);
  assertEquals(2, aRouteList.getItems().size());

  aRouteList = client.routes().inAnyNamespace().withLabels(Collections.singletonMap("foo", "bar")).list();
  assertNotNull(aRouteList);
  assertEquals(3, aRouteList.getItems().size());

  boolean bDeleted = client.routes().inNamespace("ns1").delete();
  aRouteList = client.routes().inNamespace("ns1").list();
  assertTrue(bDeleted);
  assertEquals(0, aRouteList.getItems().size());
}
 
Example #8
Source File: OpenShiftEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void addRoutesWhenRecipeContainsThem() throws Exception {
  Route route = new RouteBuilder().withNewMetadata().withName("test-route").endMetadata().build();
  when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(route));

  final OpenShiftEnvironment parsed =
      osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());

  assertEquals(parsed.getRoutes().size(), 1);
  assertEquals(
      parsed.getRoutes().get("test-route").getMetadata().getName(),
      route.getMetadata().getName());
}
 
Example #9
Source File: RouteTlsProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Route createRoute(String name, Map<String, ServerConfigImpl> servers) {
  return new RouteBuilder()
      .withNewMetadata()
      .withName(name)
      .withAnnotations(Annotations.newSerializer().servers(servers).annotations())
      .endMetadata()
      .withNewSpec()
      .endSpec()
      .build();
}
 
Example #10
Source File: KafkaCluster.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a bootstrap route which can be used to bootstrap clients outside of OpenShift.
 *
 * @return The generated Routes
 */
public Route generateExternalBootstrapRoute() {
    if (isExposedWithRoute()) {
        Route route = new RouteBuilder()
                .withNewMetadata()
                    .withName(serviceName)
                    .withLabels(getLabelsWithStrimziName(serviceName, templateExternalBootstrapRouteLabels).toMap())
                    .withAnnotations(mergeLabelsOrAnnotations(null, templateExternalBootstrapRouteAnnotations))
                    .withNamespace(namespace)
                    .withOwnerReferences(createOwnerReference())
                .endMetadata()
                .withNewSpec()
                    .withNewTo()
                        .withKind("Service")
                        .withName(externalBootstrapServiceName(cluster))
                    .endTo()
                    .withNewPort()
                        .withNewTargetPort(EXTERNAL_PORT)
                    .endPort()
                    .withNewTls()
                        .withTermination("passthrough")
                    .endTls()
                .endSpec()
                .build();

        KafkaListenerExternalRoute listener = (KafkaListenerExternalRoute) listeners.getExternal();
        if (listener.getOverrides() != null && listener.getOverrides().getBootstrap() != null && listener.getOverrides().getBootstrap().getHost() != null && !listener.getOverrides().getBootstrap().getHost().isEmpty()) {
            route.getSpec().setHost(listener.getOverrides().getBootstrap().getHost());
        }

        return route;
    }

    return null;
}
 
Example #11
Source File: SparkOperatorEntrypoint.java    From spark-operator with Apache License 2.0 5 votes vote down vote up
private Route createRouteForMetrics() {
        Route route = new RouteBuilder().withNewMetadata().withName("spark-operator-metrics")
                .withLabels(Collections.singletonMap("type", "operator-metrics")).endMetadata()
                .withNewSpec()
                .withNewTo("Service", "spark-operator-metrics", 100)
                .endSpec().build();
        return route;
}
 
Example #12
Source File: RouteEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns true if we already have a route created for the given name
 */
private boolean hasRoute(final KubernetesListBuilder listBuilder, final String name) {
    final AtomicBoolean answer = new AtomicBoolean(false);
    listBuilder.accept(new TypedVisitor<RouteBuilder>() {

        @Override
        public void visit(RouteBuilder builder) {
            ObjectMeta metadata = builder.buildMetadata();
            if (metadata != null && name.equals(metadata.getName())) {
                answer.set(true);
            }
        }
    });
    return answer.get();
}
 
Example #13
Source File: RouteOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected Route resource() {
    return new RouteBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(RESOURCE_NAME).endMetadata().build();
}
 
Example #14
Source File: ResourceUtils.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static ResourceOperatorSupplier supplierWithMocks(boolean openShift) {
    RouteOperator routeOps = openShift ? mock(RouteOperator.class) : null;

    ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(
            mock(ServiceOperator.class), routeOps, mock(ZookeeperSetOperator.class),
            mock(KafkaSetOperator.class), mock(ConfigMapOperator.class), mock(SecretOperator.class),
            mock(PvcOperator.class), mock(DeploymentOperator.class),
            mock(ServiceAccountOperator.class), mock(RoleBindingOperator.class), mock(ClusterRoleBindingOperator.class),
            mock(NetworkPolicyOperator.class), mock(PodDisruptionBudgetOperator.class), mock(PodOperator.class),
            mock(IngressOperator.class), mock(ImageStreamOperator.class), mock(BuildConfigOperator.class),
            mock(DeploymentConfigOperator.class), mock(CrdOperator.class), mock(CrdOperator.class), mock(CrdOperator.class),
            mock(CrdOperator.class), mock(CrdOperator.class), mock(CrdOperator.class), mock(CrdOperator.class), mock(CrdOperator.class),
            mock(StorageClassOperator.class), mock(NodeOperator.class), zookeeperScalerProvider(), metricsProvider());
    when(supplier.serviceAccountOperations.reconcile(anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
    when(supplier.roleBindingOperations.reconcile(anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
    when(supplier.clusterRoleBindingOperator.reconcile(anyString(), any())).thenReturn(Future.succeededFuture());

    if (openShift) {
        when(supplier.routeOperations.reconcile(anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
        when(supplier.routeOperations.hasAddress(anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
        when(supplier.routeOperations.get(anyString(), anyString())).thenAnswer(i -> {
            return new RouteBuilder()
                    .withNewStatus()
                    .addNewIngress()
                    .withHost(i.getArgument(0) + "." + i.getArgument(1) + ".mydomain.com")
                    .endIngress()
                    .endStatus()
                    .build();
        });
    }

    when(supplier.serviceOperations.hasIngressAddress(anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(supplier.serviceOperations.hasNodePort(anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(supplier.serviceOperations.get(anyString(), anyString())).thenAnswer(i -> {
        return new ServiceBuilder()
                .withNewStatus()
                .withNewLoadBalancer()
                .withIngress(new LoadBalancerIngressBuilder().withHostname(i.getArgument(0) + "." + i.getArgument(1) + ".mydomain.com").build())
                .endLoadBalancer()
                .endStatus()
                .withNewSpec()
                .withPorts(new ServicePortBuilder().withNodePort(31245).build())
                .endSpec()
                .build();
    });

    return supplier;
}
 
Example #15
Source File: OpenShiftUniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private static Route newRoute() {
  return new RouteBuilder()
      .withMetadata(new ObjectMetaBuilder().withName(ROUTE_NAME).build())
      .build();
}
 
Example #16
Source File: KafkaCluster.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Generates route for pod. This route is used for exposing it externally using OpenShift Routes.
 *
 * @param pod Number of the pod for which this route should be generated
 * @return The generated Route
 */
public Route generateExternalRoute(int pod) {
    if (isExposedWithRoute()) {
        String perPodServiceName = externalServiceName(cluster, pod);

        Route route = new RouteBuilder()
                .withNewMetadata()
                    .withName(perPodServiceName)
                    .withLabels(getLabelsWithStrimziName(perPodServiceName, templatePerPodRouteLabels).toMap())
                    .withAnnotations(templatePerPodRouteAnnotations)
                    .withNamespace(namespace)
                    .withOwnerReferences(createOwnerReference())
                .endMetadata()
                .withNewSpec()
                    .withNewTo()
                        .withKind("Service")
                        .withName(perPodServiceName)
                    .endTo()
                    .withNewPort()
                        .withNewTargetPort(EXTERNAL_PORT)
                    .endPort()
                    .withNewTls()
                        .withTermination("passthrough")
                    .endTls()
                .endSpec()
                .build();

        KafkaListenerExternalRoute listener = (KafkaListenerExternalRoute) listeners.getExternal();
        if (listener.getOverrides() != null && listener.getOverrides().getBrokers() != null) {
            String specHost = listener.getOverrides().getBrokers().stream()
                    .filter(broker -> broker != null && broker.getBroker() == pod
                            && broker.getHost() != null)
                    .map(RouteListenerBrokerOverride::getHost)
                    .findAny()
                    .orElse(null);

            if (specHost != null && !specHost.isEmpty()) {
                route.getSpec().setHost(specHost);
            }
        }

        return route;
    }

    return null;
}
 
Example #17
Source File: OpenShiftServiceImplTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldExposeDeploymentsViaServicesAndRoutes() {
    final DeploymentData deploymentData = new DeploymentData.Builder()
        .withExposure(EnumSet.of(Exposure.SERVICE, Exposure.ROUTE))
        .build();

    final String name = "via-service-and-route";

    final DeploymentConfig expectedDeploymentConfig = baseDeploymentFor(name, deploymentData)
        .build();

    expectDeploymentOf(name, expectedDeploymentConfig);

    final Service expectedService = new ServiceBuilder()
        .withNewMetadata()
            .withName(openshiftName(name))
            .withAnnotations(new HashMap<String, String>())
            .withLabels(new HashMap<String, String>())
        .endMetadata()
        .withNewSpec()
            .addNewPort()
                .withName("http")
                .withPort(8080)
                .withProtocol("TCP")
                .withTargetPort(new IntOrString(8080))
            .endPort()
            .addToSelector("syndesis.io/integration", openshiftName(name))
        .endSpec()
        .build();

    server.expect()
        .post()
        .withPath("/api/v1/namespaces/test/services")
        .andReturn(200, expectedService)
        .always();

    final Route expectedRoute = new RouteBuilder()
        .withApiVersion("route.openshift.io/v1")
        .withKind("Route")
        .withNewMetadata()
            .withName(openshiftName(name))
        .endMetadata()
        .withNewSpec()
            .withNewTls()
                .withTermination("edge")
            .endTls()
            .withNewTo()
                .withKind("Service")
                .withName(openshiftName(name))
            .endTo()
        .endSpec()
        .build();

    server.expect()
        .post()
        .withPath("/apis/route.openshift.io/v1/namespaces/test/routes")
        .andReturn(200, expectedRoute)
        .always();

    service.deploy(name, deploymentData);
    final List<Request> issuedRequests = gatherRequests();
    assertThat(issuedRequests).contains(Request.with("POST", "/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs", expectedDeploymentConfig));
    assertThat(issuedRequests).contains(Request.with("POST", "/api/v1/namespaces/test/services", expectedService));
    assertThat(issuedRequests).contains(Request.with("POST", "/apis/route.openshift.io/v1/namespaces/test/routes"));
}
 
Example #18
Source File: OpenShiftRouteHandler.java    From module-ballerina-kubernetes with Apache License 2.0 4 votes vote down vote up
/**
 * Generate the yaml file for a route model.
 *
 * @param routeModel The model.
 * @param serviceModel Matching service model.
 * @throws KubernetesPluginException When an error occurs while writing yaml files.
 */
private void generate(OpenShiftRouteModel routeModel, ServiceModel serviceModel) throws KubernetesPluginException {
    try {
        String routeHost = routeModel.getHost();
        // If domain is used for setting the host, then update the host as <service_name>-<namespace>.<domain>
        if (routeModel.getDomain() != null) {
            // Setting the host using domain name required namespace.
            if (null == dataHolder.getNamespace() || "".equals(dataHolder.getNamespace().trim())) {
                throw new KubernetesPluginException("'namespace' field in @kubernetes:Deployment{} is required " +
                                                    "when using 'domain' field for setting the host of the " +
                                                    "@openshift:Route{} annotation. use the OpenShift " +
                                                    "project name as the value for 'namespace' field.");
            }
            routeHost = routeModel.getName() + "-" + dataHolder.getNamespace() + "." + routeModel.getDomain();
        }

        Route route = new RouteBuilder()
                .withNewMetadata()
                .withName(routeModel.getName())
                .withLabels(routeModel.getLabels())
                .withAnnotations(routeModel.getAnnotations())
                .withNamespace(dataHolder.getNamespace())
                .endMetadata()
                .withNewSpec()
                .withHost(routeHost)
                .withNewPort()
                .withNewTargetPort(serviceModel.getTargetPort())
                .endPort()
                .withNewTo()
                .withKind("Service")
                .withName(serviceModel.getName())
                .withWeight(100)
                .endTo()
                .endSpec()
                .build();
        
        String resourceQuotaContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(route);
        KubernetesUtils.writeToFile(dataHolder.getK8sArtifactOutputPath().resolve(OPENSHIFT), resourceQuotaContent,
                OPENSHIFT_ROUTE_FILE_POSTFIX + YAML);
    } catch (IOException e) {
        String errorMessage = "error while generating OpenShift Route yaml file: " +
                              routeModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
 
Example #19
Source File: RouteTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void routeBuilderTest(){

    Route route = new RouteBuilder()
            .withNewMetadata()
                .withName("fabric8-maven-sample-zero-config")
                .addToLabels("expose", "true")
                .addToLabels("app", "fabric8-maven-sample-zero-config")
                .addToLabels("provider", "fabric8")
                .addToLabels("version", "3.5-SNAPSHOT")
                .addToLabels("group", "io.fabric8")
            .endMetadata()
            .withNewSpec()
            .withHost("www.example.com")
            .withPath("/test")
            .withNewPort().withNewTargetPort().withIntVal(8080).endTargetPort().endPort()
            .withNewTo().withKind("Service")
                        .withName("fabric8-maven-sample-zero-config")
                        .withWeight(5)
            .endTo()
            .addToAlternateBackends(
                    new RouteTargetReferenceBuilder().withName("test1").withKind("Service").withWeight(0).build()
            )
            .addToAlternateBackends(
                    new RouteTargetReferenceBuilder().withName("test2").withKind("Service").withWeight(0).build()
            )
            .addToAlternateBackends(
                    new RouteTargetReferenceBuilder().withName("test3").withKind("Service").withWeight(0).build()
            )
            .withNewTls()
                .withTermination("edge")
                .withKey("$(perl -pe 's/\n/\\n/' example-test.key)")
                .withCertificate("$(perl -pe 's/\n/\\n/' example-test.cert)")
                .withCaCertificate("$(perl -pe 's/\n/\\n/' example-test.cert)")
                .withDestinationCACertificate("$(perl -pe 's/\n/\\n/' example-test.cert)")
                .withInsecureEdgeTerminationPolicy("Allow")
            .endTls()
            .withWildcardPolicy("Subdomain")
            .endSpec()
            .build();

    assertNotNull(route);
    assertEquals("fabric8-maven-sample-zero-config",route.getMetadata().getName());
    assertTrue(route.getMetadata().getLabels().get("expose").equals("true"));
    assertTrue(route.getMetadata().getLabels().get("app").equals("fabric8-maven-sample-zero-config"));
    assertTrue(route.getMetadata().getLabels().get("provider").equals("fabric8"));
    assertTrue(route.getMetadata().getLabels().get("version").equals("3.5-SNAPSHOT"));
    assertTrue(route.getMetadata().getLabels().get("group").equals("io.fabric8"));
    assertEquals("www.example.com", route.getSpec().getHost());
    assertEquals("/test", route.getSpec().getPath());
    assertNotNull(route.getSpec().getPort());
    assertEquals(8080, route.getSpec().getPort().getTargetPort().getIntVal().intValue());
    assertNotNull(route.getSpec().getTo());
    assertEquals("Service", route.getSpec().getTo().getKind());
    assertEquals("fabric8-maven-sample-zero-config", route.getSpec().getTo().getName());
    assertEquals("5", route.getSpec().getTo().getWeight().toString());
    assertNotNull(route.getSpec().getAlternateBackends());
    assertEquals(3, route.getSpec().getAlternateBackends().size());
    assertEquals(0, route.getSpec().getAlternateBackends().get(0).getWeight().intValue());
    assertEquals("Service", route.getSpec().getAlternateBackends().get(0).getKind());
    assertEquals(0, route.getSpec().getAlternateBackends().get(1).getWeight().intValue());
    assertEquals("Service", route.getSpec().getAlternateBackends().get(1).getKind());
    assertEquals(0, route.getSpec().getAlternateBackends().get(2).getWeight().intValue());
    assertEquals("Service", route.getSpec().getAlternateBackends().get(2).getKind());
    assertTrue(route.getSpec().getAlternateBackends().get(0).getName().startsWith("test"));
    assertTrue(route.getSpec().getAlternateBackends().get(1).getName().startsWith("test"));
    assertTrue(route.getSpec().getAlternateBackends().get(2).getName().startsWith("test"));
    assertNotNull(route.getSpec().getTls());
    assertEquals("edge", route.getSpec().getTls().getTermination());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.key)", route.getSpec().getTls().getKey());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.cert)", route.getSpec().getTls().getCertificate());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.cert)", route.getSpec().getTls().getCaCertificate());
    assertEquals("$(perl -pe 's/\n/\\n/' example-test.cert)", route.getSpec().getTls().getDestinationCACertificate());
    assertEquals("Allow", route.getSpec().getTls().getInsecureEdgeTerminationPolicy());
    assertEquals("Subdomain", route.getSpec().getWildcardPolicy());
}
 
Example #20
Source File: KubernetesHistoryServerDeployer.java    From spark-operator with Apache License 2.0 4 votes vote down vote up
public KubernetesResourceList getResourceList(SparkHistoryServer hs, String namespace, boolean isOpenshift) {
    checkForInjectionVulnerabilities(hs, namespace);
    List<HasMetadata> resources = new ArrayList<>();

    Map<String, String> defaultLabels = getDefaultLabels(hs.getName());
    int uiPort = hs.getInternalPort();

    Deployment deployment = getDeployment(hs, defaultLabels);
    resources.add(deployment);

    if (HistoryServerHelper.needsVolume(hs) && null != hs.getSharedVolume()) {
        PersistentVolumeClaim pvc = getPersistentVolumeClaim(hs, defaultLabels);
        resources.add(pvc);
    }

    // expose the service using Ingress or Route
    if (hs.getExpose()) {
        Service service = new ServiceBuilder().withNewMetadata().withLabels(defaultLabels).withName(hs.getName())
                .endMetadata().withNewSpec().withSelector(defaultLabels)
                .withPorts(new ServicePortBuilder().withName("web-ui").withPort(uiPort).build()).endSpec().build();
        resources.add(service);
        if (isOpenshift) {
            Route route = new RouteBuilder().withNewMetadata().withName(hs.getName())
                    .withLabels(defaultLabels).endMetadata()
                    .withNewSpec().withHost(hs.getHost())
                    .withNewTo("Service", hs.getName(), 100)
                    .endSpec().build();
            resources.add(route);
        } else {
            Ingress ingress = new IngressBuilder().withNewMetadata().withName(hs.getName())
                    .withLabels(defaultLabels).endMetadata()
                    .withNewSpec().withRules(new IngressRuleBuilder().withHost(hs.getHost()).withNewHttp()
                            .withPaths(new HTTPIngressPathBuilder().withNewBackend().withServiceName(hs.getName()).withNewServicePort(uiPort).endBackend().build()).endHttp().build())
                    .endSpec().build();
            resources.add(ingress);
        }
    }

    KubernetesList k8sResources = new KubernetesListBuilder().withItems(resources).build();
    return k8sResources;
}