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());
});
}
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);
});
}
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));
});
}
Aggregations