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()));
}
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]"));
}
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()));
}
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()));
}
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));
}
Aggregations