io.fabric8.kubernetes.api.model.extensions.IngressTLS Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.extensions.IngressTLS.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IngressTlsProvisioner.java From che with Eclipse Public License 2.0 | 6 votes |
private void enableTLS(Ingress ingress, String wsTlsSecretName) { String host = ingress.getSpec().getRules().get(0).getHost(); IngressTLSBuilder ingressTLSBuilder = new IngressTLSBuilder().withHosts(host); // according to ingress tls spec, secret name is optional // when working in single-host mode, nginx controller wil reuse the che-master secret // https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/api/extensions/v1beta1/types.go if (!isNullOrEmpty(wsTlsSecretName)) { ingressTLSBuilder.withSecretName(wsTlsSecretName); } IngressTLS ingressTLS = ingressTLSBuilder.build(); List<IngressTLS> ingressTLSList = new ArrayList<>(Collections.singletonList(ingressTLS)); ingress.getSpec().setTls(ingressTLSList); }
Example #2
Source File: IngressHandler.java From module-ballerina-kubernetes with Apache License 2.0 | 4 votes |
/** * Generate kubernetes ingress definition from annotation. * * @param ingressModel IngressModel object * @throws KubernetesPluginException If an error occurs while generating artifact. */ private void generate(IngressModel ingressModel) throws KubernetesPluginException { //generate ingress backend IngressBackend ingressBackend = new IngressBackendBuilder() .withServiceName(ingressModel.getServiceName()) .withNewServicePort(ingressModel.getServicePort()) .build(); //generate ingress path HTTPIngressPath ingressPath = new HTTPIngressPathBuilder() .withBackend(ingressBackend) .withPath(ingressModel .getPath()).build(); //generate TLS List<IngressTLS> ingressTLS = new ArrayList<>(); if (ingressModel.isEnableTLS()) { ingressTLS.add(new IngressTLSBuilder() .withHosts(ingressModel.getHostname()) .build()); } //generate annotationMap Map<String, String> annotationMap = new HashMap<>(); annotationMap.put("kubernetes.io/ingress.class", ingressModel.getIngressClass()); if (NGINX.equals(ingressModel.getIngressClass())) { annotationMap.put("nginx.ingress.kubernetes.io/ssl-passthrough", String.valueOf(ingressModel.isEnableTLS ())); if (ingressModel.getTargetPath() != null) { annotationMap.put("nginx.ingress.kubernetes.io/rewrite-target", ingressModel.getTargetPath()); } } //Add user defined ingress annotations to yaml. Map<String, String> userDefinedAnnotationMap = ingressModel.getAnnotations(); if (userDefinedAnnotationMap != null) { userDefinedAnnotationMap.forEach(annotationMap::putIfAbsent); } //generate ingress Ingress ingress = new IngressBuilder() .withNewMetadata() .withName(ingressModel.getName()) .withNamespace(dataHolder.getNamespace()) .addToLabels(ingressModel.getLabels()) .addToAnnotations(annotationMap) .endMetadata() .withNewSpec() .withTls(ingressTLS) .addNewRule() .withHost(ingressModel.getHostname()) .withNewHttp() .withPaths(ingressPath) .endHttp() .endRule() .endSpec() .build(); String ingressYAML; try { ingressYAML = SerializationUtils.dumpWithoutRuntimeStateAsYaml(ingress); KubernetesUtils.writeToFile(ingressYAML, INGRESS_FILE_POSTFIX + YAML); } catch (IOException e) { String errorMessage = "error while generating yaml file for ingress: " + ingressModel.getName(); throw new KubernetesPluginException(errorMessage, e); } }
Example #3
Source File: KafkaCluster.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * 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 #4
Source File: KafkaCluster.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * 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; }