use of com.bakdata.quick.manager.k8s.ImageConfig in project quick by bakdata.
the class GatewayResourceLoader method forCreation.
/**
* Creates resources that can be deployed.
*
* <p>
* This function creates all the Kubernetes resources that a gateway needs for its deployment. Deployment, Service,
* Ingress, Middleware, and ConfigMap templates are filled with the data passed through the {@link
* GatewayCreationData}.
*/
@Override
public GatewayResources forCreation(final GatewayCreationData gatewayCreationData, final ResourcePrefix resourcePrefix) {
final String imageTag = Objects.requireNonNullElse(gatewayCreationData.getTag(), this.deploymentConfig.getDefaultImageTag());
final int imageReplicas = Objects.requireNonNullElse(gatewayCreationData.getReplicas(), this.deploymentConfig.getDefaultReplicas());
final String dockerRegistry = this.deploymentConfig.getDockerRegistry();
final ImageConfig imageConfig = ImageConfig.of(dockerRegistry, GATEWAY_IMAGE, imageReplicas, imageTag);
final String gatewayName = gatewayCreationData.getName();
final String resourceName = getResourceName(gatewayName);
final boolean hasFixedTag = gatewayCreationData.getTag() != null;
final GatewayDeployment deployment = new GatewayDeployment(this.createGatewayDeployment(resourceName, imageConfig, this.resourceConfig, hasFixedTag));
final GatewayService service = new GatewayService(this.createGatewayService(resourceName));
final GatewayIngress ingress = new GatewayIngress(this.createGatewayIngress(resourceName, gatewayCreationData.getName(), this.namespace, this.deploymentConfig.getIngressHost(), this.deploymentConfig.isIngressSsl(), this.deploymentConfig.getIngressEntrypoint()));
final GatewayMiddleware middleware = new GatewayMiddleware(this.createGatewayMiddleware(resourceName, gatewayCreationData.getName()));
final GatewayConfigMap configMap = new GatewayConfigMap(this.createGatewayConfigMap(resourceName, gatewayCreationData.getSchema()));
return new GatewayResources(gatewayName, deployment, service, ingress, middleware, configMap);
}
use of com.bakdata.quick.manager.k8s.ImageConfig in project quick by bakdata.
the class ApplicationResourceLoader method forCreation.
/**
* Creates resources that can be deployed.
*
* <p>
* This function creates all the Kubernetes resources that an application needs for its deployment. Deployment and
* Service templates are filled with the data passed.
*/
@Override
public ApplicationResources forCreation(final ApplicationCreationData appCreationData, final ResourcePrefix resourcePrefix) {
final int replicas = Objects.requireNonNullElse(appCreationData.getReplicas(), this.deploymentConfig.getDefaultReplicas());
final ImageConfig config = ImageConfig.of(appCreationData.getRegistry(), appCreationData.getImageName(), replicas, appCreationData.getTag());
final String applicationName = appCreationData.getName();
final String deploymentName = getDeploymentName(applicationName);
final Map<String, String> arguments = Objects.requireNonNullElse(appCreationData.getArguments(), Map.of());
final List<String> listArgs = CliArgHandler.convertArgs(arguments, this.kafkaConfig);
final ApplicationDeployment deployment = new ApplicationDeployment(this.createAppDeployment(deploymentName, listArgs, config, this.resourceConfig, appCreationData.getPort(), appCreationData.getImagePullSecret()));
if (appCreationData.getPort() != null) {
final ApplicationService service = new ApplicationService(this.createApplicationService(deploymentName, appCreationData.getPort()));
return new ApplicationResources(applicationName, deployment, Optional.of(service));
}
return new ApplicationResources(applicationName, deployment, Optional.empty());
}
use of com.bakdata.quick.manager.k8s.ImageConfig 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.manager.k8s.ImageConfig in project quick by bakdata.
the class KubernetesApplicationServiceTest method shouldCreateDeletionJob.
@Test
void shouldCreateDeletionJob() {
final ImageConfig imageConfig = ImageConfig.of(DOCKER_REGISTRY, IMAGE_NAME, 1, DEFAULT_IMAGE_TAG);
this.deployApplication(DEFAULT_PORT, Map.of("--input-topics", "test"));
assertThat(this.getDeployments()).isNotNull().hasSize(1);
final Completable deleteRequest = this.service.deleteApplication(APP_NAME);
Optional.ofNullable(deleteRequest.blockingGet()).ifPresent(Assertions::fail);
assertThat(this.client.batch().v1().jobs().list().getItems()).isNotNull().hasSize(1).first().satisfies(job -> assertThat(job.getMetadata().getName()).isEqualTo(DEPLOYMENT_NAME + "-deletion")).extracting(job -> job.getSpec().getTemplate().getSpec().getContainers(), InstanceOfAssertFactories.list(Container.class)).hasSize(1).first().satisfies(container -> {
assertThat(container.getImage()).isEqualTo(imageConfig.asImageString());
assertThat(container.getArgs()).contains("--input-topics=test");
});
}
use of com.bakdata.quick.manager.k8s.ImageConfig in project quick by bakdata.
the class ApplicationResourceLoaderTest method shouldCreateDeploymentForAppDefaults.
@Test
void shouldCreateDeploymentForAppDefaults() {
final ImageConfig imageConfig = ImageConfig.of(DOCKER_REGISTRY, "test", 3, "snapshot");
final ApplicationResources applicationResources = this.createApplicationResource(null, null, null, Map.of());
final Optional<HasMetadata> hasMetadata = findResource(applicationResources, ResourceKind.DEPLOYMENT);
final Map<String, String> labels = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/component", "streamsApp");
assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Deployment.class)).satisfies(deployment -> {
assertThat(deployment.getMetadata()).hasFieldOrPropertyWithValue("name", DEFAULT_DEPLOYMENT_NAME);
final DeploymentSpec deploymentSpec = deployment.getSpec();
assertThat(deploymentSpec).hasFieldOrPropertyWithValue("replicas", 1).extracting(spec -> spec.getTemplate().getMetadata().getLabels(), MAP).contains(Map.entry("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME));
assertThat(deployment.getMetadata()).satisfies(metadata -> {
assertThat(metadata.getName()).isEqualTo(DEFAULT_DEPLOYMENT_NAME);
assertThat(metadata.getLabels()).containsExactlyInAnyOrderEntriesOf(labels);
});
final PodSpec podSpec = deploymentSpec.getTemplate().getSpec();
assertThat(podSpec.getImagePullSecrets()).isNullOrEmpty();
assertThat(podSpec.getContainers()).isNotNull().hasSize(1).first().hasFieldOrPropertyWithValue("image", imageConfig.asImageString()).hasFieldOrPropertyWithValue("imagePullPolicy", "Always").hasFieldOrPropertyWithValue("name", DEFAULT_DEPLOYMENT_NAME).satisfies(container -> {
assertThat(container.getPorts()).isNullOrEmpty();
assertThat(container.getEnv()).hasSize(1).first().extracting(EnvVar::getName).isEqualTo("JAVA_TOOL_OPTIONS");
assertThat(container.getEnvFrom()).isNotNull().hasSize(1).first().extracting(EnvFromSource::getConfigMapRef).isNotNull().hasFieldOrPropertyWithValue("name", KubernetesResources.QUICK_CONFIG_NAME);
assertThat(container.getArgs()).hasSize(2).contains("--brokers=bootstrap").contains("--schema-registry-url=http://dummy:123");
});
});
}
Aggregations