use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project devspaces-images by redhat-developer.
the class IngressTlsProvisioner method enableTLS.
private void enableTLS(Ingress ingress, String wsTlsSecretName) {
String host = ingress.getSpec().getRules().get(0).getHost();
IngressTLSBuilder ingressTLSBuilder = new IngressTLSBuilder().withHosts(host);
// 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);
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project devspaces-images by redhat-developer.
the class IngressTlsProvisioner method provision.
@Override
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws KubernetesInfrastructureException {
if (!isTlsEnabled) {
return;
}
String wsTlsSecretName = tlsSecretName;
if (!isNullOrEmpty(tlsCert) && !isNullOrEmpty(tlsKey)) {
wsTlsSecretName = identity.getWorkspaceId() + '-' + tlsSecretName;
provisionTlsSecret(k8sEnv, wsTlsSecretName);
}
for (Ingress ingress : k8sEnv.getIngresses().values()) {
useSecureProtocolForIngressServers(ingress);
enableTLS(ingress, wsTlsSecretName);
}
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress 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.v1beta1.Ingress in project devspaces-images by redhat-developer.
the class IngressServerResolver method fillIngressServers.
private Map<String, ServerImpl> fillIngressServers(Ingress ingress) {
IngressRule ingressRule = ingress.getSpec().getRules().get(0);
// host either set by rule, or determined by LB ip
final String host = ingressRule.getHost() != null ? ingressRule.getHost() : ingress.getStatus().getLoadBalancer().getIngress().get(0).getIp();
return Annotations.newDeserializer(ingress.getMetadata().getAnnotations()).servers().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> {
String root = pathTransformInverter.undoPathTransformation(ingressRule.getHttp().getPaths().get(0).getPath());
String path = buildPath(root, e.getValue().getPath());
// the /jwt/auth needs to be based on the webroot of the server, not the path of
// the endpoint.
String endpointOrigin = buildPath(root, "/");
return new RuntimeServerBuilder().protocol(e.getValue().getProtocol()).host(host).path(path).endpointOrigin(endpointOrigin).attributes(e.getValue().getAttributes()).targetPort(e.getValue().getPort()).build();
}));
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project devspaces-images by redhat-developer.
the class IngressServerResolverTest method testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsEmpty.
@Test
public void testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsEmpty() {
Ingress ingress = createIngress("matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "", ATTRIBUTES_MAP)));
ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), emptyList(), singletonList(ingress));
Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
assertEquals(resolved.size(), 1);
assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, INGRESS_PATH_PREFIX + "/")));
}
Aggregations