Search in sources :

Example 11 with KubernetesResources

use of com.bakdata.quick.manager.k8s.KubernetesResources in project quick by bakdata.

the class ImageUpdaterTest method shouldUpdateMirror.

@Test
void shouldUpdateMirror() {
    final MirrorResourceLoader loader = new MirrorResourceLoader(new KubernetesResources(), this.getDeploymentConfig(), this.getResourceConfig());
    final MirrorService mirrorService = new KubernetesMirrorService(new KubernetesResources(), this.getManagerClient(), this.getDeploymentConfig(), loader);
    final MirrorCreationData mirrorCreationData = new MirrorCreationData("topic", "service", 1, // use default tag
    null, null);
    mirrorService.createMirror(mirrorCreationData).blockingAwait();
    assertThat(this.getDeployments()).hasSize(1).first().extracting(ImageUpdaterTest::getContainerImage).isEqualTo(String.format("%s/%s:%s", DOCKER_REGISTRY, MIRROR_IMAGE, DEFAULT_IMAGE_TAG));
    final DeploymentConfig newDeploymentConfig = this.createNewDeploymentConfig();
    final ImageUpdater imageUpdater = new ImageUpdater(this.client, newDeploymentConfig);
    imageUpdater.updateManagedDeployments();
    assertThat(this.getDeployments()).hasSize(1).first().extracting(ImageUpdaterTest::getContainerImage).isEqualTo(String.format("%s/%s:%s", DOCKER_REGISTRY, MIRROR_IMAGE, NEW_TAG));
}
Also used : MirrorResourceLoader(com.bakdata.quick.manager.mirror.resources.MirrorResourceLoader) KubernetesMirrorService(com.bakdata.quick.manager.mirror.KubernetesMirrorService) MirrorService(com.bakdata.quick.manager.mirror.MirrorService) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) KubernetesMirrorService(com.bakdata.quick.manager.mirror.KubernetesMirrorService) DeploymentConfig(com.bakdata.quick.manager.config.DeploymentConfig) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 12 with KubernetesResources

use of com.bakdata.quick.manager.k8s.KubernetesResources 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 13 with KubernetesResources

use of com.bakdata.quick.manager.k8s.KubernetesResources in project quick by bakdata.

the class JobCleanerTest method shouldRunWithoutErrorForWithoutSucceeded.

@Test
void shouldRunWithoutErrorForWithoutSucceeded() {
    final JobCleaner jobCleaner = new JobCleaner(this.client);
    final KubernetesResources resources = new KubernetesResources();
    final Job deletionJob = resources.createDeletionJob("test", "image", List.of("--key", "value"));
    final Job runningJob = new JobBuilder(deletionJob).withNewStatus().withActive(0).withSucceeded(null).endStatus().build();
    this.kubernetesServer.getClient().batch().v1().jobs().create(runningJob);
    assertThatNoException().isThrownBy(jobCleaner::deleteJobs);
}
Also used : JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) Test(org.junit.jupiter.api.Test) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest)

Aggregations

KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)13 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)10 Test (org.junit.jupiter.api.Test)10 DeploymentConfig (com.bakdata.quick.manager.config.DeploymentConfig)7 GatewayCreationData (com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData)4 GatewayResourceLoader (com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader)4 MirrorResourceLoader (com.bakdata.quick.manager.mirror.resources.MirrorResourceLoader)4 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)3 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)3 GatewayService (com.bakdata.quick.manager.gateway.GatewayService)3 KubernetesGatewayService (com.bakdata.quick.manager.gateway.KubernetesGatewayService)3 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)3 KubernetesMirrorService (com.bakdata.quick.manager.mirror.KubernetesMirrorService)3 MirrorService (com.bakdata.quick.manager.mirror.MirrorService)3 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)2 ApplicationResourceLoader (com.bakdata.quick.manager.application.resources.ApplicationResourceLoader)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1