use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project jkube by eclipse.
the class IngressEnricherTest method testCreateIngressFromXMLConfigWithConfiguredServiceName.
@Test
public void testCreateIngressFromXMLConfigWithConfiguredServiceName() {
// Given
ResourceConfig resourceConfig = ResourceConfig.builder().ingress(IngressConfig.builder().ingressRule(IngressRuleConfig.builder().host("foo.bar.com").path(IngressRulePathConfig.builder().pathType("ImplementationSpecific").path("/icons").serviceName("hello-k8s").servicePort(80).build()).build()).ingressRule(IngressRuleConfig.builder().host("*.foo.com").path(IngressRulePathConfig.builder().path("/icons-storage").pathType("Exact").resource(IngressRulePathResourceConfig.builder().apiGroup("k8s.example.com").kind("StorageBucket").name("icon-assets").build()).build()).build()).ingressTlsConfig(IngressTlsConfig.builder().host("https-example.foo.com").secretName("testsecret-tls").build()).build()).build();
// @formatter:off
new Expectations() {
{
// Enable creation of Ingress for Service of type LoadBalancer
context.getProperty(CREATE_EXTERNAL_URLS);
result = "true";
context.getConfiguration().getResource();
result = resourceConfig;
}
};
// @formatter:on
Service providedService = initTestService().build();
KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService);
// When
ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder);
// Then
assertThat(kubernetesListBuilder).extracting(KubernetesListBuilder::buildItems).asList().hasSize(2).element(1).asInstanceOf(InstanceOfAssertFactories.type(Ingress.class)).hasFieldOrPropertyWithValue("apiVersion", "networking.k8s.io/v1").hasFieldOrPropertyWithValue("metadata.name", providedService.getMetadata().getName()).extracting(Ingress::getSpec).satisfies(is -> assertThat(is).extracting("tls").asList().element(0).hasFieldOrPropertyWithValue("secretName", "testsecret-tls").extracting("hosts").asList().containsExactly("https-example.foo.com")).extracting(IngressSpec::getRules).satisfies(r -> assertThat(r).asList().element(0).hasFieldOrPropertyWithValue("host", "foo.bar.com").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/icons").hasFieldOrPropertyWithValue("pathType", "ImplementationSpecific").hasFieldOrPropertyWithValue("backend.service.name", "hello-k8s").hasFieldOrPropertyWithValue("backend.service.port.number", 80)).satisfies(r -> assertThat(r).asList().element(1).hasFieldOrPropertyWithValue("host", "*.foo.com").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/icons-storage").hasFieldOrPropertyWithValue("pathType", "Exact").hasFieldOrPropertyWithValue("backend.resource.apiGroup", "k8s.example.com").hasFieldOrPropertyWithValue("backend.resource.kind", "StorageBucket").hasFieldOrPropertyWithValue("backend.resource.name", "icon-assets"));
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project jkube by eclipse.
the class NetworkingV1IngressGenerator method getIngressRuleFromXmlConfig.
private static IngressRule getIngressRuleFromXmlConfig(IngressRuleConfig ingressRuleConfig) {
IngressRuleBuilder ingressRuleBuilder = new IngressRuleBuilder();
if (ingressRuleConfig.getHost() != null) {
ingressRuleBuilder.withHost(ingressRuleConfig.getHost());
}
if (ingressRuleConfig.getPaths() != null && !ingressRuleConfig.getPaths().isEmpty()) {
HTTPIngressRuleValueBuilder httpIngressPathBuilder = new HTTPIngressRuleValueBuilder();
for (IngressRulePathConfig ingressRulePathConfig : ingressRuleConfig.getPaths()) {
httpIngressPathBuilder.addToPaths(getHTTPIngressPath(ingressRulePathConfig));
}
ingressRuleBuilder.withHttp(httpIngressPathBuilder.build());
}
return ingressRuleBuilder.build();
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project quick by bakdata.
the class GatewayResourceLoaderTest method shouldCreateGatewayIngress.
@Test
void shouldCreateGatewayIngress() {
final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
final GatewayResources gatewayResources = this.loader.forCreation(gatewayCreationData, ResourcePrefix.GATEWAY);
final Optional<HasMetadata> hasMetadata = findResource(gatewayResources, ResourceKind.INGRESS);
final String expected = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Ingress.class)).satisfies(gatewayIngress -> {
assertThat(gatewayIngress.getMetadata()).hasFieldOrPropertyWithValue("name", expected).extracting(ObjectMeta::getAnnotations, MAP).containsExactlyInAnyOrderEntriesOf(Map.of("kubernetes.io/ingress.class", "traefik", "traefik.ingress.kubernetes.io/router.middlewares", String.format("%s-%s@kubernetescrd", "test", expected), "traefik.ingress.kubernetes.io/router.entrypoints", "websecure", "traefik.ingress.kubernetes.io/router.tls", "true"));
final IngressSpec ingressSpec = gatewayIngress.getSpec();
assertThat(ingressSpec).isNotNull();
assertThat(ingressSpec.getRules()).isNotNull().hasSize(1).first().satisfies(rule -> assertThat(rule.getHost()).isEqualTo("quick.host.io")).extracting(IngressRule::getHttp).isNotNull().extracting(HTTPIngressRuleValue::getPaths, InstanceOfAssertFactories.list(HTTPIngressPath.class)).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("path", "/gateway/" + GATEWAY_NAME).hasFieldOrPropertyWithValue("pathType", "Prefix").extracting(path -> path.getBackend().getService()).isNotNull().hasFieldOrPropertyWithValue("name", expected).extracting(IngressServiceBackend::getPort).hasFieldOrPropertyWithValue("number", KubernetesResources.SERVICE_PORT);
});
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule in project xp-operator by enonic.
the class OperatorXp7ConfigSync method hasMappingsWithNodeGroups.
private boolean hasMappingsWithNodeGroups(final Ingress ingress, final List<String> nodeGroups) {
Set<Mapping> targetMappings = getAnnotationMappings(ingress);
// No mappings
if (targetMappings.size() == 0) {
return false;
}
// No rules
if (ingress.getSpec().getRules() == null) {
return false;
}
for (IngressRule rule : ingress.getSpec().getRules()) {
// No paths
if (rule.getHttp() == null || rule.getHttp().getPaths() == null) {
return false;
}
for (HTTPIngressPath path : rule.getHttp().getPaths()) {
// No backend
if (path.getBackend() == null || path.getBackend().getService().getName() == null || path.getBackend().getService().getPort() == null) {
return false;
}
// Get service and port
String service = path.getBackend().getService().getName();
Integer port = path.getBackend().getService().getPort().getNumber();
// Only if service is the same as a nodegroup and port is 8080
if (nodeGroups.contains(service) && port == 8080) {
return true;
}
}
}
// Return false by default
return false;
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressRule 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