Search in sources :

Example 6 with MirrorCreationData

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

the class KubernetesMirrorServiceTest method shouldCreateMirrorResources.

@Test
void shouldCreateMirrorResources() {
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(TOPIC_NAME, TOPIC_NAME, 1, null, null);
    this.createMirror(mirrorCreationData);
    final List<Deployment> deployments = this.getDeployments();
    final List<Service> services = this.getServices();
    assertThat(deployments).isNotNull().hasSize(1);
    assertThat(services).isNotNull().hasSize(1);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Service(io.fabric8.kubernetes.api.model.Service) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 7 with MirrorCreationData

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

the class KubernetesMirrorServiceTest method shouldCreateServiceWithDefaults.

@Test
void shouldCreateServiceWithDefaults() {
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(TOPIC_NAME, TOPIC_NAME, 1, null, null);
    this.createMirror(mirrorCreationData);
    final List<Service> services = this.getServices();
    assertThat(services).isNotNull().hasSize(1).first().extracting(Service::getMetadata).hasFieldOrPropertyWithValue("name", DEPLOYMENT_NAME);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 8 with MirrorCreationData

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

the class MirrorResourceLoaderTest method shouldCreateMirrorDeployment.

@Test
void shouldCreateMirrorDeployment() {
    final ImageConfig imageConfig = ImageConfig.of(DOCKER_REGISTRY, EXPECTED_MIRROR_IMAGE, 3, DEFAULT_IMAGE_TAG);
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(DEFAULT_NAME, DEFAULT_TOPIC_NAME, 3, null, Duration.of(1, ChronoUnit.MINUTES));
    final MirrorResources mirrorResources = this.loader.forCreation(mirrorCreationData, ResourcePrefix.MIRROR);
    final Optional<HasMetadata> hasMetadata = findResource(mirrorResources, ResourceKind.DEPLOYMENT);
    final Map<String, String> labels = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/managed-by", "quick", "app.kubernetes.io/component", "mirror");
    final Map<String, String> selectors = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/component", "mirror");
    final Map<String, String> annotations = Map.of("d9p.io/fixed-tag", "false");
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Deployment.class)).satisfies(deployment -> {
        assertThat(deployment.getMetadata()).satisfies(metadata -> {
            assertThat(metadata.getName()).isEqualTo(DEFAULT_DEPLOYMENT_NAME);
            assertThat(metadata.getLabels()).containsExactlyInAnyOrderEntriesOf(labels);
            assertThat(metadata.getAnnotations()).containsExactlyInAnyOrderEntriesOf(annotations);
        });
        assertThat(deployment.getSpec()).satisfies(spec -> {
            assertThat(spec.getReplicas()).isEqualTo(3);
            assertThat(spec.getSelector().getMatchLabels()).containsExactlyInAnyOrderEntriesOf(selectors);
            assertThat(spec.getTemplate().getMetadata().getLabels()).containsExactlyInAnyOrderEntriesOf(labels);
        });
        final DeploymentSpec deploymentSpec = deployment.getSpec();
        assertThat(deploymentSpec).hasFieldOrPropertyWithValue("replicas", 3).extracting(spec -> spec.getTemplate().getMetadata().getLabels(), MAP).containsExactlyInAnyOrderEntriesOf(labels);
        final PodSpec podSpec = deploymentSpec.getTemplate().getSpec();
        assertThat(podSpec.getContainers()).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("image", imageConfig.asImageString()).hasFieldOrPropertyWithValue("imagePullPolicy", "Always").hasFieldOrPropertyWithValue("name", DEFAULT_DEPLOYMENT_NAME).satisfies(container -> {
            assertThat(container.getPorts()).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("containerPort", KubernetesResources.CONTAINER_PORT);
            assertThat(container.getArgs()).contains(String.format("--input-topics=%s", DEFAULT_TOPIC_NAME), "--retention-time=PT1M");
            assertThat(container.getEnv()).isNotNull().hasSize(2).first().hasFieldOrPropertyWithValue("name", "POD_IP").extracting(EnvVar::getValueFrom).isNotNull().extracting(EnvVarSource::getFieldRef).hasFieldOrPropertyWithValue("fieldPath", "status.podIP");
            assertThat(container.getEnvFrom()).isNotNull().hasSize(1).first().extracting(EnvFromSource::getConfigMapRef).isNotNull().hasFieldOrPropertyWithValue("name", KubernetesResources.QUICK_CONFIG_NAME);
        });
    });
}
Also used : ImageConfig(com.bakdata.quick.manager.k8s.ImageConfig) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) BeforeEach(org.junit.jupiter.api.BeforeEach) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) MAP(org.assertj.core.api.InstanceOfAssertFactories.MAP) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnvFromSource(io.fabric8.kubernetes.api.model.EnvFromSource) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Duration(java.time.Duration) Map(java.util.Map) Service(io.fabric8.kubernetes.api.model.Service) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) 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) Test(org.junit.jupiter.api.Test) ChronoUnit(java.time.temporal.ChronoUnit) TestUtil(com.bakdata.quick.manager.TestUtil) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) LIST(org.assertj.core.api.InstanceOfAssertFactories.LIST) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Optional(java.util.Optional) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ImageConfig(com.bakdata.quick.manager.k8s.ImageConfig) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) EnvFromSource(io.fabric8.kubernetes.api.model.EnvFromSource) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 9 with MirrorCreationData

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

the class MirrorResourceLoaderTest method shouldCreateDeploymentWithCustomTopicName.

@Test
void shouldCreateDeploymentWithCustomTopicName() {
    final String topicName = "__internal-test-topic";
    final String name = "test-topic";
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(name, topicName, 1, null, null);
    final MirrorResources mirrorResources = this.loader.forCreation(mirrorCreationData, ResourcePrefix.MIRROR);
    final Optional<HasMetadata> hasMetadata = findResource(mirrorResources, ResourceKind.DEPLOYMENT);
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Deployment.class)).satisfies(deployment -> {
        final String deploymentName = ResourcePrefix.MIRROR.getPrefix() + name;
        assertThat(deployment.getMetadata()).hasFieldOrPropertyWithValue("name", deploymentName);
        final DeploymentSpec deploymentSpec = deployment.getSpec();
        assertThat(deploymentSpec.getTemplate().getMetadata().getLabels()).contains(Map.entry("app.kubernetes.io/name", deploymentName));
        final PodSpec podSpec = deploymentSpec.getTemplate().getSpec();
        assertThat(podSpec.getContainers()).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("name", deploymentName).extracting(Container::getArgs, LIST).contains("--input-topics=" + topicName);
    });
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 10 with MirrorCreationData

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

the class MirrorResourceLoaderTest method shouldSetReplicasForDeployment.

@Test
void shouldSetReplicasForDeployment() {
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(DEFAULT_NAME, DEFAULT_TOPIC_NAME, 5, null, null);
    final MirrorResources mirrorResources = this.loader.forCreation(mirrorCreationData, ResourcePrefix.MIRROR);
    final Optional<HasMetadata> hasMetadata = findResource(mirrorResources, ResourceKind.DEPLOYMENT);
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Deployment.class)).satisfies(deployment -> {
        final DeploymentSpec deploymentSpec = deployment.getSpec();
        assertThat(deploymentSpec).hasFieldOrPropertyWithValue("replicas", 5);
    });
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Aggregations

MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)23 Test (org.junit.jupiter.api.Test)21 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)17 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)5 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)5 MirrorService (com.bakdata.quick.manager.mirror.MirrorService)4 MirrorResourceLoader (com.bakdata.quick.manager.mirror.resources.MirrorResourceLoader)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 Service (io.fabric8.kubernetes.api.model.Service)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 Completable (io.reactivex.Completable)4 DeploymentConfig (com.bakdata.quick.manager.config.DeploymentConfig)3 KubernetesMirrorService (com.bakdata.quick.manager.mirror.KubernetesMirrorService)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)3 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)3 Duration (java.time.Duration)3 Assertions (org.junit.jupiter.api.Assertions)3 KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)2