use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder 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.IngressBackendBuilder in project che-server by eclipse-che.
the class ExternalServerIngressBuilder method build.
public Ingress build() {
ServiceBackendPortBuilder serviceBackendPortBuilder = new ServiceBackendPortBuilder();
// cannot set both port and name
if (!isNullOrEmpty(servicePortName)) {
serviceBackendPortBuilder.withName(servicePortName);
} else if (servicePort != null) {
serviceBackendPortBuilder.withNumber(servicePort);
}
IngressServiceBackend ingressServiceBackend = new IngressServiceBackendBuilder().withPort(serviceBackendPortBuilder.build()).withName(serviceName).build();
IngressBackend ingressBackend = new IngressBackendBuilder().withService(ingressServiceBackend).build();
HTTPIngressPathBuilder httpIngressPathBuilder = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPathType(INGRESS_PATH_TYPE);
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 IngressBuilder().withSpec(ingressSpec).withMetadata(new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).withLabels(labels).build()).build();
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project devspaces-images by redhat-developer.
the class ExternalServerIngressBuilder method build.
public Ingress build() {
ServiceBackendPortBuilder serviceBackendPortBuilder = new ServiceBackendPortBuilder();
// cannot set both port and name
if (!isNullOrEmpty(servicePortName)) {
serviceBackendPortBuilder.withName(servicePortName);
} else if (servicePort != null) {
serviceBackendPortBuilder.withNumber(servicePort);
}
IngressServiceBackend ingressServiceBackend = new IngressServiceBackendBuilder().withPort(serviceBackendPortBuilder.build()).withName(serviceName).build();
IngressBackend ingressBackend = new IngressBackendBuilder().withService(ingressServiceBackend).build();
HTTPIngressPathBuilder httpIngressPathBuilder = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPathType(INGRESS_PATH_TYPE);
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 IngressBuilder().withSpec(ingressSpec).withMetadata(new ObjectMetaBuilder().withName(name).withAnnotations(ingressAnnotations).withLabels(labels).build()).build();
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project ingress-access-operator by neo9.
the class ServiceExposerReconciler method reconcile.
public void reconcile(Service service) {
String serviceNamespaceAndName = getResourceNamespaceAndName(service);
log.trace("start working with service {}", serviceNamespaceAndName);
Ingress oldIngress = ingressRepository.get(service.getMetadata().getNamespace(), service.getMetadata().getName());
if (nonNull(oldIngress) && !isManagedByOperator(oldIngress)) {
throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldIngress));
}
String hostname = generateHostname(service);
log.debug("generating ingress for hostname : {}", hostname);
Map<String, String> ingressAnnotations = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_ANNOTATIONS, service, ""));
Map<String, String> ingressLabels = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_LABELS, service, ""));
SpecNested<IngressBuilder> ingressBuilderSpecNested = new IngressBuilder().withNewMetadata().withNamespace(service.getMetadata().getNamespace()).withName(service.getMetadata().getName()).addToAnnotations(ingressAnnotations).addToLabels(ingressLabels).addToLabels(MANAGED_BY_OPERATOR_KEY, MANAGED_BY_OPERATOR_VALUE).endMetadata().withNewSpec().withRules(new IngressRuleBuilder().withHost(hostname).withHttp(new HTTPIngressRuleValueBuilder().withPaths(new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withBackend(new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build()).build()).build()).build());
if (shouldEnableTls(ingressAnnotations)) {
ingressBuilderSpecNested = ingressBuilderSpecNested.withTls(new IngressTLSBuilder().addToHosts(hostname).withSecretName(String.format("%s-tls", service.getMetadata().getName())).build());
}
Ingress ingress = ingressBuilderSpecNested.endSpec().build();
ingressRepository.createOrReplace(ingress);
log.trace("end of working with service {}", serviceNamespaceAndName);
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class KubernetesNetworkingService method buildIngress.
private Ingress buildIngress(BridgeIngress bridgeIngress, Service service) {
Ingress ingress = templateProvider.loadBridgeIngressKubernetesIngressTemplate(bridgeIngress);
IngressBackend ingressBackend = new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build();
HTTPIngressPath httpIngressPath = new HTTPIngressPathBuilder().withBackend(ingressBackend).withPath("/" + service.getMetadata().getName() + PATH_REGEX).withPathType("Prefix").build();
IngressRule ingressRule = new IngressRuleBuilder().withHttp(new HTTPIngressRuleValueBuilder().withPaths(httpIngressPath).build()).build();
IngressSpec ingressSpec = new IngressSpecBuilder().withRules(ingressRule).build();
ingress.setSpec(ingressSpec);
return ingress;
}
Aggregations