io.fabric8.kubernetes.api.model.extensions.IngressRuleBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.extensions.IngressRuleBuilder. 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: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 6 votes vote down vote up
private static Ingress getSystemtestsIngressResource(String appName, int port) throws Exception {
    IngressBackend backend = new IngressBackend();
    backend.setServiceName(appName);
    backend.setServicePort(new IntOrString(port));
    HTTPIngressPath path = new HTTPIngressPath();
    path.setPath("/");
    path.setBackend(backend);

    return new IngressBuilder()
            .withNewMetadata()
            .withName(appName)
            .addToLabels("route", appName)
            .endMetadata()
            .withNewSpec()
            .withRules(new IngressRuleBuilder()
                    .withHost(appName + "."
                            + (env.kubernetesDomain().equals("nip.io") ? new URL(env.getApiUrl()).getHost() + ".nip.io" : env.kubernetesDomain()))
                    .withNewHttp()
                    .withPaths(path)
                    .endHttp()
                    .build())
            .endSpec()
            .build();
}
 
Example #2
Source File: SparkOperatorEntrypoint.java    From spark-operator with Apache License 2.0 5 votes vote down vote up
private Ingress createIngressForMetrics() {
        Ingress ingress = new IngressBuilder().withNewMetadata().withName("spark-operator-metrics")
                .withLabels(Collections.singletonMap("type", "operator-metrics")).endMetadata()
                .withNewSpec().withRules(new IngressRuleBuilder().withNewHttp()
                        .withPaths(new HTTPIngressPathBuilder().withNewBackend().withServiceName("spark-operator-metrics")
                                .withNewServicePort(entrypoint.getConfig().getMetricsPort()).endBackend().build()).endHttp().build())
                .endSpec().build();
        return ingress;
}
 
Example #3
Source File: ExternalServerIngressBuilder.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
public Ingress build() {

    IngressBackend ingressBackend =
        new IngressBackendBuilder()
            .withServiceName(serviceName)
            .withNewServicePort(servicePort.getStrVal())
            .build();

    HTTPIngressPathBuilder httpIngressPathBuilder =
        new HTTPIngressPathBuilder().withBackend(ingressBackend);

    if (!isNullOrEmpty(path)) {
      httpIngressPathBuilder.withPath(path);
    }

    HTTPIngressPath httpIngressPath = httpIngressPathBuilder.build();

    HTTPIngressRuleValue httpIngressRuleValue =
        new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build();
    IngressRuleBuilder ingressRuleBuilder = new IngressRuleBuilder().withHttp(httpIngressRuleValue);

    if (!isNullOrEmpty(host)) {
      ingressRuleBuilder.withHost(host);
    }

    IngressRule ingressRule = ingressRuleBuilder.build();

    IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();

    Map<String, String> ingressAnnotations = new HashMap<>(annotations);
    ingressAnnotations.putAll(
        Annotations.newSerializer().servers(serversConfigs).machineName(machineName).annotations());

    return new io.fabric8.kubernetes.api.model.extensions.IngressBuilder()
        .withSpec(ingressSpec)
        .withMetadata(
            new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).build())
        .build();
  }
 
Example #4
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;
}
 
Example #5
Source File: KafkaCluster.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Generates ingress for pod. This ingress is used for exposing it externally using Nginx Ingress.
 *
 * @param pod Number of the pod for which this ingress should be generated
 * @return The generated Ingress
 */
public Ingress generateExternalIngress(int pod) {
    if (isExposedWithIngress()) {
        KafkaListenerExternalIngress listener = (KafkaListenerExternalIngress) listeners.getExternal();
        Map<String, String> dnsAnnotations = null;
        String host = null;

        if (listener.getConfiguration() != null && listener.getConfiguration().getBrokers() != null) {
            host = listener.getConfiguration().getBrokers().stream()
                    .filter(broker -> broker != null && broker.getBroker() == pod
                            && broker.getHost() != null)
                    .map(IngressListenerBrokerConfiguration::getHost)
                    .findAny()
                    .orElseThrow(() -> new InvalidResourceException("Hostname for broker with id " + pod + " is required for exposing Kafka cluster using Ingress"));

            dnsAnnotations = listener.getConfiguration().getBrokers().stream()
                    .filter(broker -> broker != null && broker.getBroker() == pod)
                    .map(IngressListenerBrokerConfiguration::getDnsAnnotations)
                    .findAny()
                    .orElse(null);
        }

        String perPodServiceName = externalServiceName(cluster, pod);

        HTTPIngressPath path = new HTTPIngressPathBuilder()
                .withPath("/")
                .withNewBackend()
                    .withNewServicePort(EXTERNAL_PORT)
                    .withServiceName(perPodServiceName)
                .endBackend()
                .build();

        IngressRule rule = new IngressRuleBuilder()
                .withHost(host)
                .withNewHttp()
                    .withPaths(path)
                .endHttp()
                .build();

        IngressTLS tls = new IngressTLSBuilder()
                .withHosts(host)
                .build();

        Ingress ingress = new IngressBuilder()
                .withNewMetadata()
                    .withName(perPodServiceName)
                    .withLabels(getLabelsWithStrimziName(perPodServiceName, templatePerPodIngressLabels).toMap())
                    .withAnnotations(mergeLabelsOrAnnotations(generateInternalIngressAnnotations(listener), templatePerPodIngressAnnotations, dnsAnnotations))
                    .withNamespace(namespace)
                    .withOwnerReferences(createOwnerReference())
                .endMetadata()
                .withNewSpec()
                    .withRules(rule)
                    .withTls(tls)
                .endSpec()
                .build();

        return ingress;
    }

    return null;
}
 
Example #6
Source File: KafkaCluster.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a bootstrap ingress which can be used to bootstrap clients outside of Kubernetes.
 *
 * @return The generated Ingress
 */
public Ingress generateExternalBootstrapIngress() {
    if (isExposedWithIngress()) {
        KafkaListenerExternalIngress listener = (KafkaListenerExternalIngress) listeners.getExternal();
        Map<String, String> dnsAnnotations;
        String host;

        if (listener.getConfiguration() != null && listener.getConfiguration().getBootstrap() != null && listener.getConfiguration().getBootstrap().getHost() != null) {
            host = listener.getConfiguration().getBootstrap().getHost();
            dnsAnnotations = listener.getConfiguration().getBootstrap().getDnsAnnotations();
        } else {
            throw new InvalidResourceException("Bootstrap hostname is required for exposing Kafka cluster using Ingress");
        }

        HTTPIngressPath path = new HTTPIngressPathBuilder()
                .withPath("/")
                .withNewBackend()
                    .withNewServicePort(EXTERNAL_PORT)
                    .withServiceName(externalBootstrapServiceName(cluster))
                .endBackend()
                .build();

        IngressRule rule = new IngressRuleBuilder()
                .withHost(host)
                .withNewHttp()
                    .withPaths(path)
                .endHttp()
                .build();

        IngressTLS tls = new IngressTLSBuilder()
                .withHosts(host)
                .build();

        Ingress ingress = new IngressBuilder()
                .withNewMetadata()
                    .withName(serviceName)
                    .withLabels(getLabelsWithStrimziName(serviceName, templateExternalBootstrapIngressLabels).toMap())
                    .withAnnotations(mergeLabelsOrAnnotations(generateInternalIngressAnnotations(listener), templateExternalBootstrapIngressAnnotations, dnsAnnotations))
                    .withNamespace(namespace)
                    .withOwnerReferences(createOwnerReference())
                .endMetadata()
                .withNewSpec()
                    .withRules(rule)
                    .withTls(tls)
                .endSpec()
                .build();

        return ingress;
    }

    return null;
}