use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi 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()));
}
use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi 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()));
}
use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi 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));
}
use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.
the class KafkaConnectDockerfileTest method testMavenDockerfile.
@ParallelTest
public void testMavenDockerfile() {
JarArtifact jar = new JarArtifactBuilder().withUrl("http://url.com/ar.jar").build();
MavenArtifact mvn1 = new MavenArtifactBuilder().withGroup("g1").withArtifact("a1").withVersion("v1").build();
MavenArtifact mvn2 = new MavenArtifactBuilder().withGroup("g2").withArtifact("a2").withVersion("v2").build();
Build connectBuild = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(jar, mvn1, mvn2).build(), new PluginBuilder().withName("other-connector-plugin").withArtifacts(jar).build()).build();
KafkaConnectDockerfile df = new KafkaConnectDockerfile("myImage:latest", connectBuild);
assertThat(df.getDockerfile(), is("##############################\n" + "##############################\n" + "# This file is automatically generated by the Strimzi Cluster Operator\n" + "# Any changes to this file will be ignored and overwritten!\n" + "##############################\n" + "##############################\n" + "\n" + "FROM quay.io/strimzi/maven-builder:latest AS downloadArtifacts\n" + "RUN 'curl' '-L' '--create-dirs' '--output' '/tmp/my-connector-plugin/64cebd9c/pom.xml' 'https://repo1.maven.org/maven2/g1/a1/v1/a1-v1.pom' \\\n" + " && 'mvn' 'dependency:copy-dependencies' '-DoutputDirectory=/tmp/artifacts/my-connector-plugin/64cebd9c' '-f' '/tmp/my-connector-plugin/64cebd9c/pom.xml' \\\n" + " && 'curl' '-L' '--create-dirs' '--output' '/tmp/artifacts/my-connector-plugin/64cebd9c/a1-v1.jar' 'https://repo1.maven.org/maven2/g1/a1/v1/a1-v1.jar'\n" + "\n" + "RUN 'curl' '-L' '--create-dirs' '--output' '/tmp/my-connector-plugin/9983060e/pom.xml' 'https://repo1.maven.org/maven2/g2/a2/v2/a2-v2.pom' \\\n" + " && 'mvn' 'dependency:copy-dependencies' '-DoutputDirectory=/tmp/artifacts/my-connector-plugin/9983060e' '-f' '/tmp/my-connector-plugin/9983060e/pom.xml' \\\n" + " && 'curl' '-L' '--create-dirs' '--output' '/tmp/artifacts/my-connector-plugin/9983060e/a2-v2.jar' 'https://repo1.maven.org/maven2/g2/a2/v2/a2-v2.jar'\n" + "\n" + "FROM myImage:latest\n" + "\n" + "USER root:root\n" + "\n" + "##########\n" + "# Connector plugin my-connector-plugin\n" + "##########\n" + "RUN 'mkdir' '-p' '/opt/kafka/plugins/my-connector-plugin/9bb2fd11' \\\n" + " && 'curl' '-L' '--output' '/opt/kafka/plugins/my-connector-plugin/9bb2fd11/9bb2fd11.jar' 'http://url.com/ar.jar'\n" + "\n" + "COPY --from=downloadArtifacts '/tmp/artifacts/my-connector-plugin/64cebd9c' '/opt/kafka/plugins/my-connector-plugin/64cebd9c'\n" + "\n" + "COPY --from=downloadArtifacts '/tmp/artifacts/my-connector-plugin/9983060e' '/opt/kafka/plugins/my-connector-plugin/9983060e'\n" + "\n" + "##########\n" + "# Connector plugin other-connector-plugin\n" + "##########\n" + "RUN 'mkdir' '-p' '/opt/kafka/plugins/other-connector-plugin/9bb2fd11' \\\n" + " && 'curl' '-L' '--output' '/opt/kafka/plugins/other-connector-plugin/9bb2fd11/9bb2fd11.jar' 'http://url.com/ar.jar'\n" + "\n" + "USER 1001\n" + "\n"));
}
use of io.strimzi.api.kafka.model.connect.build.PluginBuilder in project strimzi by strimzi.
the class KafkaConnectDockerfileTest method testNoArtifacts.
@ParallelTest
public void testNoArtifacts() {
Build connectBuild = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(emptyList()).build()).build();
KafkaConnectDockerfile df = new KafkaConnectDockerfile("myImage:latest", connectBuild);
assertThat(df.getDockerfile(), isEquivalent("FROM myImage:latest", "USER root:root", "USER 1001"));
}
Aggregations