Search in sources :

Example 6 with ImageConfig

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

the class KubernetesMirrorService method deleteMirror.

@Override
public Completable deleteMirror(final String name) {
    final String deploymentName = MirrorResourceLoader.getDeploymentName(name);
    final ImageConfig imageConfig = ImageConfig.of(this.deploymentConfig.getDockerRegistry(), MIRROR_IMAGE, 1, this.deploymentConfig.getDefaultImageTag());
    // first extract info about mirror deployment
    // we need this to properly delete all kafka related resources like the internal state store topic
    final Single<Deployment> deployment = this.kubeClient.readDeployment(deploymentName);
    // as well as all kafka related resources
    final Completable kafkaCleanUp = deployment.map(d -> d.getSpec().getTemplate().getSpec().getContainers().get(0).getArgs()).map(list -> this.resources.createDeletionJob(deploymentName, imageConfig.asImageString(), list)).flatMapCompletable(this.kubeClient::deploy);
    final Completable resourceDeletion = Single.fromCallable(() -> this.loader.forDeletion(deploymentName)).flatMapCompletable(this.kubeClient::delete);
    return kafkaCleanUp.andThen(resourceDeletion);
}
Also used : ImageConfig(com.bakdata.quick.manager.k8s.ImageConfig) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) Environment(io.micronaut.context.env.Environment) ResourcePrefix(com.bakdata.quick.manager.k8s.resource.QuickResources.ResourcePrefix) KubernetesManagerClient(com.bakdata.quick.manager.k8s.KubernetesManagerClient) Completable(io.reactivex.Completable) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) Singleton(javax.inject.Singleton) Single(io.reactivex.Single) MIRROR_IMAGE(com.bakdata.quick.manager.mirror.resources.MirrorResources.MIRROR_IMAGE) DeploymentConfig(com.bakdata.quick.manager.config.DeploymentConfig) Requires(io.micronaut.context.annotation.Requires) MirrorResourceLoader(com.bakdata.quick.manager.mirror.resources.MirrorResourceLoader) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ImageConfig(com.bakdata.quick.manager.k8s.ImageConfig) Completable(io.reactivex.Completable) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Example 7 with ImageConfig

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

the class MirrorResourceLoader method forCreation.

/**
 * Creates resources that can be deployed.
 *
 * <p>
 * This function creates all the Kubernetes resources that a mirror needs for its deployment. Deployment and Service
 * templates are filled with the data passed.
 */
@Override
public MirrorResources forCreation(final MirrorCreationData mirrorCreationData, final ResourcePrefix prefix) {
    final String mirrorName = mirrorCreationData.getName();
    final String deploymentName = prefix.getPrefix() + mirrorName;
    final String imageTag = Objects.requireNonNullElse(mirrorCreationData.getTag(), this.deploymentConfig.getDefaultImageTag());
    final int imageReplicas = Objects.requireNonNullElse(mirrorCreationData.getReplicas(), this.deploymentConfig.getDefaultReplicas());
    final ImageConfig config = ImageConfig.of(this.deploymentConfig.getDockerRegistry(), MIRROR_IMAGE, imageReplicas, imageTag);
    final boolean hasFixedTag = mirrorCreationData.getTag() != null;
    final List<String> arguments = CliArgHandler.convertArgs(createArgs(mirrorCreationData.getTopicName(), mirrorCreationData.getRetentionTime()));
    final MirrorDeployment deployment = new MirrorDeployment(this.createMirrorDeployment(deploymentName, arguments, config, this.resourceConfig, hasFixedTag));
    final MirrorService service = new MirrorService(this.createMirrorService(deploymentName));
    return new MirrorResources(mirrorName, deployment, service);
}
Also used : ImageConfig(com.bakdata.quick.manager.k8s.ImageConfig)

Aggregations

ImageConfig (com.bakdata.quick.manager.k8s.ImageConfig)7 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)4 ResourcePrefix (com.bakdata.quick.manager.k8s.resource.QuickResources.ResourcePrefix)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)3 Container (io.fabric8.kubernetes.api.model.Container)3 Service (io.fabric8.kubernetes.api.model.Service)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)3 ApplicationCreationData (com.bakdata.quick.common.api.model.manager.creation.ApplicationCreationData)2 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)2 KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)2 TestUtil (com.bakdata.quick.manager.TestUtil)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)2 EnvFromSource (io.fabric8.kubernetes.api.model.EnvFromSource)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2