Search in sources :

Example 26 with PluginBuilder

use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi-kafka-operator 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 27 with PluginBuilder

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

the class KafkaConnectBuildTest method testInvalidKanikoOptions.

@ParallelTest
public void testInvalidKanikoOptions() {
    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").withAdditionalKanikoOptions("--reproducible", "--reproducible-something", "--build-arg", "--single-snapshot", "--digest-file=/dev/null", "--log-format=json").endDockerOutput().withPlugins(new PluginBuilder().withName("my-connector").withArtifacts(jarArtifactWithChecksum).build(), new PluginBuilder().withName("my-connector2").withArtifacts(jarArtifactNoChecksum).build()).endBuild().endSpec().build();
    InvalidResourceException e = assertThrows(InvalidResourceException.class, () -> KafkaConnectBuild.fromCrd(new Reconciliation("test", kc.getKind(), kc.getMetadata().getNamespace(), kc.getMetadata().getName()), kc, VERSIONS));
    assertThat(e.getMessage(), containsString(".spec.build.additionalKanikoOptions contains forbidden options: [--reproducible-something, --build-arg, --digest-file]"));
}
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 28 with PluginBuilder

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

the class KafkaConnectBuildTest method testConfigMap.

@ParallelTest
public void testConfigMap() {
    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 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());
    ConfigMap cm = build.generateDockerfileConfigMap(dockerfile);
    assertThat(cm.getMetadata().getName(), is(KafkaConnectResources.dockerFileConfigMapName(cluster)));
    assertThat(cm.getMetadata().getNamespace(), is(namespace));
    assertThat(cm.getData().get("Dockerfile"), is(dockerfile.getDockerfile()));
    assertThat(cm.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(cm.getMetadata().getOwnerReferences().get(0), is(build.createOwnerReference()));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) 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 29 with PluginBuilder

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

the class KafkaConnectBuildTest method testBuildconfigWithImageStreamOutput.

@ParallelTest
public void testBuildconfigWithImageStreamOutput() {
    KafkaConnect kc = new KafkaConnectBuilder().withNewMetadata().withName(cluster).withNamespace(namespace).endMetadata().withNewSpec().withBootstrapServers("my-kafka:9092").withNewBuild().withNewImageStreamOutput().withImage("my-image:latest").endImageStreamOutput().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);
    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("ImageStreamTag"));
    assertThat(bc.getSpec().getOutput().getTo().getName(), is("my-image:latest"));
    assertThat(bc.getSpec().getStrategy().getDockerStrategy(), is(notNullValue()));
    assertThat(bc.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(bc.getMetadata().getOwnerReferences().get(0), is(build.createOwnerReference()));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 30 with PluginBuilder

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

the class KafkaConnectBuildTest method testTemplate.

@ParallelTest
public void testTemplate() {
    Map<String, String> buildPodLabels = TestUtils.map("l1", "v1", "l2", "v2");
    Map<String, String> buildPodAnnos = TestUtils.map("a1", "v1", "a2", "v2");
    Map<String, String> buildConfigLabels = TestUtils.map("l3", "v3", "l4", "v4");
    Map<String, String> buildConfigAnnos = TestUtils.map("a3", "v3", "a4", "v4");
    Map<String, String> saLabels = TestUtils.map("l5", "v5", "l6", "v6");
    Map<String, String> saAnots = TestUtils.map("a5", "v5", "a6", "v6");
    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().withNewTemplate().withNewBuildPod().withNewMetadata().withLabels(buildPodLabels).withAnnotations(buildPodAnnos).endMetadata().withPriorityClassName("top-priority").withSchedulerName("my-scheduler").withEnableServiceLinks(false).endBuildPod().withNewBuildContainer().withEnv(new ContainerEnvVarBuilder().withName("TEST_ENV_VAR").withValue("testValue").build()).endBuildContainer().withNewBuildConfig().withNewMetadata().withLabels(buildConfigLabels).withAnnotations(buildConfigAnnos).endMetadata().withPullSecret("my-pull-secret").endBuildConfig().withNewBuildServiceAccount().withNewMetadata().withLabels(saLabels).withAnnotations(saAnots).endMetadata().endBuildServiceAccount().endTemplate().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.getMetadata().getLabels().entrySet().containsAll(buildPodLabels.entrySet()), is(true));
    assertThat(pod.getMetadata().getAnnotations().entrySet().containsAll(buildPodAnnos.entrySet()), is(true));
    assertThat(pod.getSpec().getPriorityClassName(), is("top-priority"));
    assertThat(pod.getSpec().getSchedulerName(), is("my-scheduler"));
    assertThat(pod.getSpec().getEnableServiceLinks(), is(false));
    assertThat(pod.getSpec().getContainers().get(0).getEnv().stream().filter(env -> "TEST_ENV_VAR".equals(env.getName())).findFirst().orElseThrow().getValue(), is("testValue"));
    KafkaConnectDockerfile dockerfile = new KafkaConnectDockerfile("my-image:latest", kc.getSpec().getBuild());
    BuildConfig bc = build.generateBuildConfig(dockerfile);
    assertThat(bc.getMetadata().getLabels().entrySet().containsAll(buildConfigLabels.entrySet()), is(true));
    assertThat(bc.getMetadata().getAnnotations().entrySet().containsAll(buildConfigAnnos.entrySet()), is(true));
    assertThat(bc.getSpec().getStrategy().getDockerStrategy().getPullSecret().getName(), is("my-pull-secret"));
    // Check Service Account
    ServiceAccount sa = build.generateServiceAccount();
    assertThat(sa.getMetadata().getLabels().entrySet().containsAll(saLabels.entrySet()), is(true));
    assertThat(sa.getMetadata().getAnnotations().entrySet().containsAll(saAnots.entrySet()), is(true));
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) Reconciliation(io.strimzi.operator.common.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) 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)

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