Search in sources :

Example 6 with PluginBuilder

use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.

the class KafkaConnectBuildTest method testDeployment.

@ParallelTest
public void testDeployment() {
    Map<String, Quantity> limit = new HashMap<>();
    limit.put("cpu", new Quantity("500m"));
    limit.put("memory", new Quantity("512Mi"));
    Map<String, Quantity> request = new HashMap<>();
    request.put("cpu", new Quantity("1000m"));
    request.put("memory", new Quantity("1Gi"));
    KafkaConnect kc = new KafkaConnectBuilder().withNewMetadata().withName(cluster).withNamespace(namespace).endMetadata().withNewSpec().withImage("my-source-image:latest").withBootstrapServers("my-kafka:9092").withNewBuild().withNewDockerOutput().withImage("my-image:latest").withPushSecret("my-docker-credentials").endDockerOutput().withPlugins(new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactWithChecksum).build(), new PluginBuilder().withName("my-connector2").withArtifacts(jarArtifactNoChecksum).build()).withResources(new ResourceRequirementsBuilder().withLimits(limit).withRequests(request).build()).endBuild().endSpec().build();
    KafkaConnectBuild build = KafkaConnectBuild.fromCrd(new Reconciliation("test", kc.getKind(), kc.getMetadata().getNamespace(), kc.getMetadata().getName()), kc, VERSIONS);
    assertThat(build.baseImage, is("my-source-image:latest"));
    Pod pod = build.generateBuilderPod(true, ImagePullPolicy.IFNOTPRESENT, null, null);
    assertThat(pod.getMetadata().getName(), is(KafkaConnectResources.buildPodName(cluster)));
    assertThat(pod.getMetadata().getNamespace(), is(namespace));
    Map<String, String> expectedDeploymentLabels = TestUtils.map(Labels.STRIMZI_CLUSTER_LABEL, this.cluster, Labels.STRIMZI_NAME_LABEL, KafkaConnectResources.buildPodName(cluster), Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND, Labels.KUBERNETES_NAME_LABEL, KafkaConnectBuild.APPLICATION_NAME, Labels.KUBERNETES_INSTANCE_LABEL, this.cluster, Labels.KUBERNETES_PART_OF_LABEL, Labels.APPLICATION_NAME + "-" + this.cluster, Labels.KUBERNETES_MANAGED_BY_LABEL, AbstractModel.STRIMZI_CLUSTER_OPERATOR_NAME);
    assertThat(pod.getMetadata().getLabels(), is(expectedDeploymentLabels));
    assertThat(pod.getSpec().getServiceAccountName(), is(KafkaConnectResources.buildServiceAccountName(cluster)));
    assertThat(pod.getSpec().getContainers().size(), is(1));
    assertThat(pod.getSpec().getContainers().get(0).getArgs(), is(defaultArgs));
    assertThat(pod.getSpec().getContainers().get(0).getName(), is(KafkaConnectResources.buildPodName(this.cluster)));
    assertThat(pod.getSpec().getContainers().get(0).getImage(), is(build.image));
    assertThat(pod.getSpec().getContainers().get(0).getPorts().size(), is(0));
    assertThat(pod.getSpec().getContainers().get(0).getResources().getLimits(), is(limit));
    assertThat(pod.getSpec().getContainers().get(0).getResources().getRequests(), is(request));
    assertThat(pod.getSpec().getVolumes().size(), is(2));
    assertThat(pod.getSpec().getVolumes().get(0).getName(), is("dockerfile"));
    assertThat(pod.getSpec().getVolumes().get(0).getConfigMap().getName(), is(KafkaConnectResources.dockerFileConfigMapName(cluster)));
    assertThat(pod.getSpec().getVolumes().get(1).getName(), is("docker-credentials"));
    assertThat(pod.getSpec().getVolumes().get(1).getSecret().getSecretName(), is("my-docker-credentials"));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().size(), is(2));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is("dockerfile"));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is("/dockerfile"));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is("docker-credentials"));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/kaniko/.docker"));
    assertThat(pod.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(pod.getMetadata().getOwnerReferences().get(0), is(build.createOwnerReference()));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 7 with PluginBuilder

use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.

the class KafkaConnectBuildTest method testValidationUniqueNames.

@ParallelTest
public void testValidationUniqueNames() {
    KafkaConnect kc = new KafkaConnectBuilder().withNewMetadata().withName(cluster).withNamespace(namespace).endMetadata().withNewSpec().withBootstrapServers("my-kafka:9092").withNewBuild().withNewDockerOutput().withImage("my-image:latest").withPushSecret("my-docker-credentials").endDockerOutput().withPlugins(new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactWithChecksum).build(), new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactNoChecksum).build()).endBuild().endSpec().build();
    assertThrows(InvalidResourceException.class, () -> {
        KafkaConnectBuild.fromCrd(new Reconciliation("test", kc.getKind(), kc.getMetadata().getNamespace(), kc.getMetadata().getName()), kc, VERSIONS);
    });
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 8 with PluginBuilder

use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.

the class KafkaConnectBuildTest method testBuildconfigWithDockerOutput.

@ParallelTest
public void testBuildconfigWithDockerOutput() {
    Map<String, Quantity> limit = new HashMap<>();
    limit.put("cpu", new Quantity("500m"));
    limit.put("memory", new Quantity("512Mi"));
    Map<String, Quantity> request = new HashMap<>();
    request.put("cpu", new Quantity("1000m"));
    request.put("memory", new Quantity("1Gi"));
    KafkaConnect kc = new KafkaConnectBuilder().withNewMetadata().withName(cluster).withNamespace(namespace).endMetadata().withNewSpec().withBootstrapServers("my-kafka:9092").withNewBuild().withNewDockerOutput().withImage("my-image:latest").withPushSecret("my-docker-credentials").endDockerOutput().withPlugins(new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactWithChecksum).build(), new PluginBuilder().withName("my-connector2").withArtifacts(jarArtifactNoChecksum).build()).withResources(new ResourceRequirementsBuilder().withLimits(limit).withRequests(request).build()).endBuild().endSpec().build();
    KafkaConnectBuild build = KafkaConnectBuild.fromCrd(new Reconciliation("test", kc.getKind(), kc.getMetadata().getNamespace(), kc.getMetadata().getName()), kc, VERSIONS);
    KafkaConnectDockerfile dockerfile = new KafkaConnectDockerfile("my-image:latest", kc.getSpec().getBuild());
    BuildConfig bc = build.generateBuildConfig(dockerfile);
    assertThat(bc.getMetadata().getName(), is(KafkaConnectResources.buildConfigName(cluster)));
    assertThat(bc.getMetadata().getNamespace(), is(namespace));
    Map<String, String> expectedDeploymentLabels = TestUtils.map(Labels.STRIMZI_CLUSTER_LABEL, this.cluster, Labels.STRIMZI_NAME_LABEL, KafkaConnectResources.buildPodName(cluster), Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND, Labels.KUBERNETES_NAME_LABEL, KafkaConnectBuild.APPLICATION_NAME, Labels.KUBERNETES_INSTANCE_LABEL, this.cluster, Labels.KUBERNETES_PART_OF_LABEL, Labels.APPLICATION_NAME + "-" + this.cluster, Labels.KUBERNETES_MANAGED_BY_LABEL, AbstractModel.STRIMZI_CLUSTER_OPERATOR_NAME);
    assertThat(bc.getMetadata().getLabels(), is(expectedDeploymentLabels));
    assertThat(bc.getSpec().getSource().getDockerfile(), is(dockerfile.getDockerfile()));
    assertThat(bc.getSpec().getOutput().getTo().getKind(), is("DockerImage"));
    assertThat(bc.getSpec().getOutput().getTo().getName(), is("my-image:latest"));
    assertThat(bc.getSpec().getOutput().getPushSecret().getName(), is("my-docker-credentials"));
    assertThat(bc.getSpec().getStrategy().getDockerStrategy(), is(notNullValue()));
    assertThat(bc.getSpec().getResources().getLimits(), is(limit));
    assertThat(bc.getSpec().getResources().getRequests(), is(request));
    assertThat(bc.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(bc.getMetadata().getOwnerReferences().get(0), is(build.createOwnerReference()));
}
Also used : HashMap(java.util.HashMap) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 9 with PluginBuilder

use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.

the class KafkaConnectBuildTest method testFromCrd.

@ParallelTest
public void testFromCrd() {
    KafkaConnect kc = new KafkaConnectBuilder().withNewMetadata().withName(cluster).withNamespace(namespace).endMetadata().withNewSpec().withBootstrapServers("my-kafka:9092").withNewBuild().withNewDockerOutput().withImage("my-image:latest").withPushSecret("my-docker-credentials").endDockerOutput().withPlugins(new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactWithChecksum).build(), new PluginBuilder().withName("my-connector2").withArtifacts(jarArtifactNoChecksum).build()).endBuild().endSpec().build();
    KafkaConnectBuild.fromCrd(new Reconciliation("test", kc.getKind(), kc.getMetadata().getNamespace(), kc.getMetadata().getName()), kc, VERSIONS);
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 10 with PluginBuilder

use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.

the class KafkaConnectBuildTest method testDeploymentWithoutPushSecret.

@ParallelTest
public void testDeploymentWithoutPushSecret() {
    KafkaConnect kc = new KafkaConnectBuilder().withNewMetadata().withName(cluster).withNamespace(namespace).endMetadata().withNewSpec().withBootstrapServers("my-kafka:9092").withNewBuild().withNewDockerOutput().withImage("my-image:latest").endDockerOutput().withPlugins(new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactWithChecksum).build(), new PluginBuilder().withName("my-connector2").withArtifacts(jarArtifactNoChecksum).build()).endBuild().endSpec().build();
    KafkaConnectBuild build = KafkaConnectBuild.fromCrd(new Reconciliation("test", kc.getKind(), kc.getMetadata().getNamespace(), kc.getMetadata().getName()), kc, VERSIONS);
    Pod pod = build.generateBuilderPod(true, ImagePullPolicy.IFNOTPRESENT, null, null);
    assertThat(pod.getSpec().getVolumes().size(), is(1));
    assertThat(pod.getSpec().getContainers().get(0).getArgs(), is(defaultArgs));
    assertThat(pod.getSpec().getVolumes().get(0).getName(), is("dockerfile"));
    assertThat(pod.getSpec().getVolumes().get(0).getConfigMap().getName(), is(KafkaConnectResources.dockerFileConfigMapName(cluster)));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().size(), is(1));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is("dockerfile"));
    assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is("/dockerfile"));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

PluginBuilder (io.strimzi.api.kafka.model.connect.build.PluginBuilder)98 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)62 KafkaConnectBuilder (io.strimzi.api.kafka.model.KafkaConnectBuilder)58 Reconciliation (io.strimzi.operator.common.Reconciliation)58 ParallelTest (io.strimzi.test.annotations.ParallelTest)56 JarArtifactBuilder (io.strimzi.api.kafka.model.connect.build.JarArtifactBuilder)44 Plugin (io.strimzi.api.kafka.model.connect.build.Plugin)42 Service (io.fabric8.kubernetes.api.model.Service)40 KafkaConnectResources (io.strimzi.api.kafka.model.KafkaConnectResources)40 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)40 Annotations (io.strimzi.operator.common.Annotations)40 Util (io.strimzi.operator.common.Util)40 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)40 BeforeAll (org.junit.jupiter.api.BeforeAll)40 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)38 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)36 NetworkPolicy (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy)36 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)36 KafkaConnectorList (io.strimzi.api.kafka.KafkaConnectorList)36 KafkaConnectStatus (io.strimzi.api.kafka.model.status.KafkaConnectStatus)36