Search in sources :

Example 46 with IngressRule

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"));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Expectations(mockit.Expectations) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRulePathConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathConfig) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IngressRuleConfig(org.eclipse.jkube.kit.config.resource.IngressRuleConfig) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) Service(io.fabric8.kubernetes.api.model.Service) IngressRulePathResourceConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) IngressTlsConfig(org.eclipse.jkube.kit.config.resource.IngressTlsConfig) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Before(org.junit.Before) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JKubeEnricherContext(org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext) Test(org.junit.Test) CREATE_EXTERNAL_URLS(org.eclipse.jkube.kit.enricher.api.BaseEnricher.CREATE_EXTERNAL_URLS) KitLogger(org.eclipse.jkube.kit.common.KitLogger) List(java.util.List) TreeMap(java.util.TreeMap) IngressConfig(org.eclipse.jkube.kit.config.resource.IngressConfig) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Collections(java.util.Collections) Mocked(mockit.Mocked) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IngressRulePathResourceConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig) Test(org.junit.Test)

Example 47 with IngressRule

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();
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressRulePathConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathConfig)

Example 48 with IngressRule

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);
    });
}
Also used : ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) BeforeEach(org.junit.jupiter.api.BeforeEach) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) MAP(org.assertj.core.api.InstanceOfAssertFactories.MAP) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Middleware(com.bakdata.quick.manager.k8s.middleware.Middleware) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) Map(java.util.Map) GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) Service(io.fabric8.kubernetes.api.model.Service) Volume(io.fabric8.kubernetes.api.model.Volume) ResourcePrefix(com.bakdata.quick.manager.k8s.resource.QuickResources.ResourcePrefix) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.jupiter.api.Test) TestUtil(com.bakdata.quick.manager.TestUtil) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) DeploymentConfig(com.bakdata.quick.manager.config.DeploymentConfig) Optional(java.util.Optional) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressRuleValue(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 49 with IngressRule

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;
}
Also used : IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Example 50 with IngressRule

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;
}
Also used : IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) IngressBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBackendBuilder) HTTPIngressRuleValueBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder) IngressSpecBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder) IngressServiceBackendBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackendBuilder) ServiceBackendPortBuilder(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPortBuilder) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Aggregations

IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)39 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)37 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)19 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)19 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)19 Service (io.fabric8.kubernetes.api.model.Service)17 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)16 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)14 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)12 Test (org.testng.annotations.Test)12 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)11 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)10 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)10 ArrayList (java.util.ArrayList)10 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)9 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)8 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)8 HTTPIngressRuleValueBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValueBuilder)7 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)6