use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder 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.v1beta1.IngressBuilder 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.v1beta1.IngressBuilder in project che-server by eclipse-che.
the class KubernetesEnvironmentFactoryTest method ignoreIgressesWhenRecipeContainsThem.
@Test
public void ignoreIgressesWhenRecipeContainsThem() throws Exception {
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(new IngressBuilder().withNewMetadata().withName("ingress1").endMetadata().build(), new IngressBuilder().withNewMetadata().withName("ingress2").endMetadata().build()));
final KubernetesEnvironment parsed = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
assertTrue(parsed.getIngresses().isEmpty());
assertEquals(parsed.getWarnings().size(), 1);
assertEquals(parsed.getWarnings().get(0), new WarningImpl(INGRESSES_IGNORED_WARNING_CODE, INGRESSES_IGNORED_WARNING_MESSAGE));
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder 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.IngressBuilder in project kubernetes-client by fabric8io.
the class KubernetesAttributesExtractorTest method shouldHandleIngress.
@Test
void shouldHandleIngress() {
KubernetesAttributesExtractor extractor = new KubernetesAttributesExtractor();
extractor.extract(new IngressBuilder().withNewMetadata().endMetadata().build());
AttributeSet attributes = extractor.fromPath("/apis/extensions/v1beta1/namespaces/myns/ingresses/myingress");
AttributeSet expected = new AttributeSet();
expected = expected.add(new Attribute("plural", "ingresses"));
expected = expected.add(new Attribute("namespace", "myns"));
expected = expected.add(new Attribute("name", "myingress"));
assertTrue(attributes.matches(expected));
}
Aggregations