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