Search in sources :

Example 16 with IngressSpec

use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project devspaces-images by redhat-developer.

the class IngressesTest method createIngress.

private Ingress createIngress(IngressBackend backend) {
    Ingress ingress = new Ingress();
    ObjectMeta ingressMeta = new ObjectMeta();
    ingressMeta.setName("ingressname");
    ingress.setMetadata(ingressMeta);
    IngressSpec ingressSpec = new IngressSpec();
    IngressRule ingressRule = new IngressRule();
    ingressRule.setHost("ingresshost");
    ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(backend, null, null))));
    ingressSpec.setRules(singletonList(ingressRule));
    ingress.setSpec(ingressSpec);
    return ingress;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) 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) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Example 17 with IngressSpec

use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec 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 18 with IngressSpec

use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec in project quick by bakdata.

the class GatewayResourceLoaderTest method shouldCreateGatewayIngressWithHttpIngress.

@Test
void shouldCreateGatewayIngressWithHttpIngress() {
    // given null host and ingress point
    final Optional<String> host = Optional.empty();
    final String ingressEntrypoint = "web";
    final boolean useSsl = false;
    final GatewayCreationData gatewayCreationData = new GatewayCreationData(GATEWAY_NAME, REPLICAS, TAG, null);
    final DeploymentConfig customConfig = new DeploymentConfig(this.getDeploymentConfig().getDockerRegistry(), this.getDeploymentConfig().getDefaultImageTag(), this.getDeploymentConfig().getDefaultReplicas(), host, useSsl, ingressEntrypoint);
    final GatewayResourceLoader customLoader = new GatewayResourceLoader(new KubernetesResources(), customConfig, TestUtil.newResourceConfig(), NAMESPACE);
    final GatewayResources gatewayResources = customLoader.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", "web", "traefik.ingress.kubernetes.io/router.tls", "false"));
        final IngressSpec ingressSpec = gatewayIngress.getSpec();
        assertThat(ingressSpec).isNotNull();
        assertThat(ingressSpec.getRules()).isNotNull().hasSize(1).first().satisfies(rule -> assertThat(rule.getHost()).isNull());
    });
}
Also used : 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) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) DeploymentConfig(com.bakdata.quick.manager.config.DeploymentConfig) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 19 with IngressSpec

use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec 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 20 with IngressSpec

use of io.fabric8.kubernetes.api.model.networking.v1.IngressSpec 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

IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)15 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)14 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)12 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)11 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)10 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)9 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)9 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)8 Service (io.fabric8.kubernetes.api.model.Service)7 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)6 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)5 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)5 IngressSpecBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressSpecBuilder)5 HTTPIngressPath (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPath)4 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.extensions.HTTPIngressRuleValue)4 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)4 IngressBackend (io.fabric8.kubernetes.api.model.extensions.IngressBackend)4 IngressRule (io.fabric8.kubernetes.api.model.extensions.IngressRule)4 IngressSpec (io.fabric8.kubernetes.api.model.extensions.IngressSpec)4