use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend 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;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend 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.IngressBackend 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.IngressBackend in project che-server by eclipse-che.
the class MultiHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, String portProtocol, Integer port, ServicePort servicePort, ServerConfigImpl expected) {
// ensure that required ingress is created
String ingressName = serviceName + "-" + (expected.isUnique() ? serverNameRegex : servicePort.getName());
Ingress ingress = kubernetesEnvironment.getIngresses().get(ingressName);
IngressRule ingressRule = ingress.getSpec().getRules().get(0);
assertEquals(ingressRule.getHost(), ingressName + "." + DOMAIN);
assertEquals(ingressRule.getHttp().getPaths().get(0).getPath(), "/");
IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
assertEquals(backend.getService().getName(), serviceName);
assertEquals(backend.getService().getPort().getName(), servicePort.getName());
Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
ServerConfig serverConfig = servers.get(serverNameRegex);
assertEquals(serverConfig, expected);
assertEquals(ingressAnnotations.machineName(), machineName);
assertEquals(ingress.getMetadata().getLabels().get("foo"), "bar");
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBackend in project che-server by eclipse-che.
the class IngressServerResolverTest method createIngress.
private Ingress createIngress(String name, String machineName, Pair<String, ServerConfig> server) {
Serializer serializer = Annotations.newSerializer();
serializer.machineName(machineName);
serializer.server(server.first, server.second);
return new IngressBuilder().withNewMetadata().withName(name).withAnnotations(serializer.annotations()).endMetadata().withNewSpec().withRules(new IngressRule(null, new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend(name, new ServiceBackendPort("8080", 8080))), INGRESS_PATH_PREFIX, null))))).endSpec().withNewStatus().withLoadBalancer(new LoadBalancerStatusBuilder().addNewIngress().withIp("127.0.0.1").endIngress().build()).endStatus().build();
}
Aggregations