Search in sources :

Example 11 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData 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 12 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData 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 13 with GatewayCreationData

use of com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData in project quick by bakdata.

the class GatewayResourceLoaderTest method shouldCreateGatewayService.

@Test
void shouldCreateGatewayService() {
    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.SERVICE);
    final String deploymentName = ResourcePrefix.GATEWAY.getPrefix() + GATEWAY_NAME;
    final Map<String, String> labels = Map.of("app.kubernetes.io/name", deploymentName, "app.kubernetes.io/managed-by", "quick", "app.kubernetes.io/component", "gateway");
    final Map<String, String> selectors = Map.of("app.kubernetes.io/name", deploymentName, "app.kubernetes.io/component", "gateway");
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Service.class)).satisfies(service -> {
        assertThat(service.getMetadata()).hasFieldOrPropertyWithValue("name", deploymentName).extracting(ObjectMeta::getLabels, MAP).isNotNull().containsExactlyInAnyOrderEntriesOf(labels);
        final ServiceSpec serviceSpec = service.getSpec();
        assertThat(serviceSpec.getSelector()).containsExactlyInAnyOrderEntriesOf(selectors);
        assertThat(serviceSpec.getPorts()).hasSize(1).first().hasFieldOrPropertyWithValue("protocol", "TCP").hasFieldOrPropertyWithValue("port", KubernetesResources.SERVICE_PORT).hasFieldOrPropertyWithValue("targetPort", new IntOrString(KubernetesResources.CONTAINER_PORT));
    });
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) GatewayCreationData(com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Aggregations

GatewayCreationData (com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData)13 Test (org.junit.jupiter.api.Test)12 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)11 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)7 DeploymentConfig (com.bakdata.quick.manager.config.DeploymentConfig)5 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)5 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)3 GatewayService (com.bakdata.quick.manager.gateway.GatewayService)3 KubernetesGatewayService (com.bakdata.quick.manager.gateway.KubernetesGatewayService)3 GatewayResourceLoader (com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader)3 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)2 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)2 IngressSpec (io.fabric8.kubernetes.api.model.networking.v1.IngressSpec)2 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)1 TestUtil (com.bakdata.quick.manager.TestUtil)1 Middleware (com.bakdata.quick.manager.k8s.middleware.Middleware)1