use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project kubernetes by ballerinax.
the class IngressHandler method generate.
/**
* Generate kubernetes ingress definition from annotation.
*
* @return Generated kubernetes {@link Ingress} definition
* @throws KubernetesPluginException If an error occurs while generating artifact.
*/
public String generate() 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
IngressTLS ingressTLS;
if (ingressModel.isEnableTLS()) {
ingressTLS = new IngressTLSBuilder().withHosts(ingressModel.getHostname()).build();
} else {
ingressTLS = new IngressTLSBuilder().build();
}
// generate annotationMap
Map<String, String> annotationMap = new HashMap<>();
annotationMap.put("kubernetes.io/ingress.class", 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());
}
// generate ingress
Ingress ingress = new IngressBuilder().withNewMetadata().withName(ingressModel.getName()).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);
} catch (JsonProcessingException e) {
String errorMessage = "Error while generating yaml file for ingress: " + ingressModel.getName();
throw new KubernetesPluginException(errorMessage, e);
}
return ingressYAML;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project kubernetes by ballerinax.
the class IngressHandler method generate.
/**
* 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);
}
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project jkube by eclipse.
the class NetworkingV1IngressGenerator method getIngressBackend.
private static IngressBackend getIngressBackend(IngressRulePathConfig ingressRulePathConfig) {
IngressBackendBuilder ingressBackendBuilder = new IngressBackendBuilder();
if (ingressRulePathConfig.getResource() != null) {
IngressRulePathResourceConfig resource = ingressRulePathConfig.getResource();
ingressBackendBuilder.withNewResource(resource.getApiGroup(), resource.getKind(), resource.getName());
}
ingressBackendBuilder.withService(getIngressServiceBackend(ingressRulePathConfig.getServiceName(), ingressRulePathConfig.getServicePort()));
return ingressBackendBuilder.build();
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder in project cmcc-operator by T-Systems-MMS.
the class NginxIngressBuilder method build.
@Override
public Collection<? extends HasMetadata> build() {
ObjectMeta metadata = targetState.getResourceMetadataFor(name);
metadata.getAnnotations().putAll(annotations);
List<HTTPIngressPath> httpPaths = paths.stream().map(path -> withPath(new HTTPIngressPathBuilder(), path).withBackend(new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(path.getService()).withPort(new ServiceBackendPort("http", null)).build()).build()).build()).collect(Collectors.toList());
return Collections.singletonList(new io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder().withMetadata(metadata).withSpec(new IngressSpecBuilder().withIngressClassName("nginx").withTls(new IngressTLSBuilder().withHosts(hostname).build()).withRules(new IngressRuleBuilder().withHost(hostname).withHttp(new HTTPIngressRuleValueBuilder().withPaths(httpPaths).build()).build()).build()).build());
}
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