use of io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createIngressForService.
private Ingress createIngressForService(String routeDomainPostfix, String namespace, Service service) {
Ingress ingress = null;
String serviceName = KubernetesHelper.getName(service);
ServiceSpec serviceSpec = service.getSpec();
if (serviceSpec != null && Strings.isNotBlank(serviceName) && shouldCreateExternalURLForService(service, serviceName)) {
String ingressId = serviceName;
String host = "";
if (Strings.isNotBlank(routeDomainPostfix)) {
host = serviceName + "." + namespace + "." + Strings.stripPrefix(routeDomainPostfix, ".");
}
List<HTTPIngressPath> paths = new ArrayList<>();
List<ServicePort> ports = serviceSpec.getPorts();
if (ports != null) {
for (ServicePort port : ports) {
Integer portNumber = port.getPort();
if (portNumber != null) {
HTTPIngressPath path = new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(createIntOrString(portNumber.intValue())).endBackend().build();
paths.add(path);
}
}
}
if (paths.isEmpty()) {
return ingress;
}
ingress = new IngressBuilder().withNewMetadata().withName(ingressId).withNamespace(namespace).endMetadata().withNewSpec().addNewRule().withHost(host).withNewHttp().withPaths(paths).endHttp().endRule().endSpec().build();
String json;
try {
json = KubernetesHelper.toJson(ingress);
} catch (JsonProcessingException e) {
json = e.getMessage() + ". object: " + ingress;
}
log.debug("Created ingress: " + json);
}
return ingress;
}
use of io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder in project fabric8-maven-plugin by fabric8io.
the class IngressEnricher method addIngress.
private void addIngress(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder) {
ObjectMeta serviceMetadata = serviceBuilder.getMetadata();
if (serviceMetadata != null && isExposedService(serviceMetadata) && shouldCreateExternalURLForService(serviceBuilder)) {
String serviceName = serviceMetadata.getName();
if (!hasIngress(listBuilder, serviceName)) {
Integer servicePort = getServicePort(serviceBuilder);
if (servicePort != null) {
IngressBuilder ingressBuilder = new IngressBuilder().withMetadata(serviceMetadata).withNewSpec().endSpec();
// removing `expose : true` label from metadata.
ingressBuilder.withNewMetadataLike(removeExposeLabel(ingressBuilder.getMetadata()));
if (StringUtils.isNotBlank(routeDomainPostfix)) {
routeDomainPostfix = serviceName + "." + FileUtil.stripPrefix(routeDomainPostfix, ".");
ingressBuilder = ingressBuilder.withSpec(new IngressSpecBuilder().addNewRule().withHost(routeDomainPostfix).withNewHttp().withPaths(new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(KubernetesHelper.createIntOrString(getServicePort(serviceBuilder))).endBackend().build()).endHttp().endRule().build());
} else {
ingressBuilder.withSpec(new IngressSpecBuilder().withBackend(new IngressBackendBuilder().withNewServiceName(serviceName).withNewServicePort(getServicePort(serviceBuilder)).build()).build());
}
listBuilder.addToItems(ingressBuilder.build());
}
}
}
}
use of io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder in project strimzi by strimzi.
the class KafkaCluster method generateExternalBootstrapIngressesV1Beta1.
/**
* Generates a list of bootstrap ingress which can be used to bootstrap clients outside of Kubernetes.
*
* @return The list of generated Ingresses
*/
public List<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> generateExternalBootstrapIngressesV1Beta1() {
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
List<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> ingresses = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String ingressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(cluster, listener);
String serviceName = ListenersUtils.backwardsCompatibleBootstrapServiceName(cluster, listener);
String host = ListenersUtils.bootstrapHost(listener);
String ingressClass = ListenersUtils.ingressClass(listener);
io.fabric8.kubernetes.api.model.networking.v1beta1.HTTPIngressPath path = new io.fabric8.kubernetes.api.model.networking.v1beta1.HTTPIngressPathBuilder().withPath("/").withNewBackend().withNewServicePort(listener.getPort()).withServiceName(serviceName).endBackend().build();
io.fabric8.kubernetes.api.model.networking.v1beta1.IngressRule rule = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressRuleBuilder().withHost(host).withNewHttp().withPaths(path).endHttp().build();
io.fabric8.kubernetes.api.model.networking.v1beta1.IngressTLS tls = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressTLSBuilder().withHosts(host).build();
io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingress = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder().withNewMetadata().withName(ingressName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templateExternalBootstrapIngressLabels, ListenersUtils.bootstrapLabels(listener))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templateExternalBootstrapIngressAnnotations, ListenersUtils.bootstrapAnnotations(listener))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withIngressClassName(ingressClass).withRules(rule).withTls(tls).endSpec().build();
ingresses.add(ingress);
}
return ingresses;
}
use of io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder in project strimzi by strimzi.
the class KafkaCluster method generateExternalBootstrapIngresses.
/**
* Generates a list of bootstrap ingress which can be used to bootstrap clients outside of Kubernetes.
*
* @return The list of generated Ingresses
*/
public List<Ingress> generateExternalBootstrapIngresses() {
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
List<Ingress> ingresses = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String ingressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(cluster, listener);
String serviceName = ListenersUtils.backwardsCompatibleBootstrapServiceName(cluster, listener);
String host = ListenersUtils.bootstrapHost(listener);
String ingressClass = ListenersUtils.ingressClass(listener);
HTTPIngressPath path = new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withNewBackend().withNewService().withName(serviceName).withNewPort().withNumber(listener.getPort()).endPort().endService().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(ingressName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templateExternalBootstrapIngressLabels, ListenersUtils.bootstrapLabels(listener))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templateExternalBootstrapIngressAnnotations, ListenersUtils.bootstrapAnnotations(listener))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withIngressClassName(ingressClass).withRules(rule).withTls(tls).endSpec().build();
ingresses.add(ingress);
}
return ingresses;
}
use of io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaCluster method generateExternalIngresses.
/**
* Generates list of 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 list of generated Ingresses
*/
public List<Ingress> generateExternalIngresses(int pod) {
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
List<Ingress> ingresses = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String ingressName = ListenersUtils.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
String host = ListenersUtils.brokerHost(listener, pod);
String ingressClass = ListenersUtils.ingressClass(listener);
HTTPIngressPath path = new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withNewBackend().withNewService().withName(ingressName).withNewPort().withNumber(listener.getPort()).endPort().endService().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(ingressName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templatePerPodIngressLabels, ListenersUtils.brokerLabels(listener, pod))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templatePerPodIngressAnnotations, ListenersUtils.brokerAnnotations(listener, pod))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withIngressClassName(ingressClass).withRules(rule).withTls(tls).endSpec().build();
ingresses.add(ingress);
}
return ingresses;
}
Aggregations