Search in sources :

Example 26 with KafkaConnect

use of io.strimzi.api.kafka.model.KafkaConnect in project strimzi by strimzi.

the class KafkaConnectClusterTest method testKafkaConnectInitContainerSectionIsConfigurable.

@ParallelTest
public void testKafkaConnectInitContainerSectionIsConfigurable() {
    Map<String, Quantity> limits = new HashMap<>();
    limits.put("cpu", Quantity.parse("1"));
    limits.put("memory", Quantity.parse("256Mi"));
    Map<String, Quantity> requirements = new HashMap<>();
    requirements.put("cpu", Quantity.parse("100m"));
    requirements.put("memory", Quantity.parse("128Mi"));
    ResourceRequirements resourceReq = new ResourceRequirementsBuilder().withLimits(limits).withRequests(requirements).build();
    KafkaConnect kafkaConnect = new KafkaConnectBuilder(this.resource).editSpec().withResources(resourceReq).withNewRack().withTopologyKey("rack-key").endRack().endSpec().build();
    KafkaConnectCluster kcc = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaConnect, VERSIONS);
    ResourceRequirements initContainersResources = kcc.getInitContainers(ImagePullPolicy.IFNOTPRESENT).get(0).getResources();
    assertThat(initContainersResources.getRequests(), is(requirements));
    assertThat(initContainersResources.getLimits(), is(limits));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) HashMap(java.util.HashMap) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 27 with KafkaConnect

use of io.strimzi.api.kafka.model.KafkaConnect in project strimzi by strimzi.

the class KafkaConnectClusterTest method testNullClusterRoleBinding.

@ParallelTest
public void testNullClusterRoleBinding() {
    String testNamespace = "other-namespace";
    KafkaConnect kafkaConnect = new KafkaConnectBuilder(this.resource).editOrNewMetadata().withNamespace(testNamespace).endMetadata().build();
    KafkaConnectCluster kafkaConnectCluster = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaConnect, VERSIONS);
    ClusterRoleBinding crb = kafkaConnectCluster.generateClusterRoleBinding();
    assertThat(crb, is(nullValue()));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 28 with KafkaConnect

use of io.strimzi.api.kafka.model.KafkaConnect in project strimzi by strimzi.

the class KafkaConnectClusterTest method testGenerateDeploymentWithPlainAuthAndTLSSameSecret.

/**
 * This test uses the same secret to hold the certs for TLS and the credentials for plain client authentication. It checks that
 * the volumes and volume mounts that reference the secret are correctly created and that each volume name is only created once - volumes
 * with duplicate names will cause Kubernetes to reject the deployment.
 */
@ParallelTest
public void testGenerateDeploymentWithPlainAuthAndTLSSameSecret() {
    KafkaConnect resource = new KafkaConnectBuilder(this.resource).editSpec().editOrNewTls().addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("cert.crt").build()).endTls().withNewKafkaClientAuthenticationPlain().withUsername("user1").withNewPasswordSecret().withSecretName("my-secret").withPassword("user1.password").endPasswordSecret().endKafkaClientAuthenticationPlain().endSpec().build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kc.generateDeployment(emptyMap(), true, null, null);
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().size(), is(3));
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(0).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(1).getName(), is("kafka-metrics-and-logging"));
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(2).getName(), is("my-secret"));
    List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers();
    assertThat(containers.get(0).getVolumeMounts().size(), is(4));
    assertThat(containers.get(0).getVolumeMounts().get(0).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
    assertThat(containers.get(0).getVolumeMounts().get(0).getMountPath(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
    assertThat(containers.get(0).getVolumeMounts().get(1).getName(), is("kafka-metrics-and-logging"));
    assertThat(containers.get(0).getVolumeMounts().get(1).getMountPath(), is("/opt/kafka/custom-config/"));
    assertThat(containers.get(0).getVolumeMounts().get(2).getName(), is("my-secret"));
    assertThat(containers.get(0).getVolumeMounts().get(2).getMountPath(), is(KafkaConnectCluster.TLS_CERTS_BASE_VOLUME_MOUNT + "my-secret"));
    assertThat(containers.get(0).getVolumeMounts().get(3).getName(), is("my-secret"));
    assertThat(containers.get(0).getVolumeMounts().get(3).getMountPath(), is(KafkaConnectCluster.PASSWORD_VOLUME_MOUNT + "my-secret"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)), hasEntry(KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_SASL_PASSWORD_FILE, "my-secret/user1.password"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)), hasEntry(KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_SASL_USERNAME, "user1"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)), hasEntry(KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_SASL_MECHANISM, "plain"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)), hasEntry(KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_TLS, "true"));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Container(io.fabric8.kubernetes.api.model.Container) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 29 with KafkaConnect

use of io.strimzi.api.kafka.model.KafkaConnect in project strimzi by strimzi.

the class KafkaConnectClusterTest method testGracePeriod.

@ParallelTest
public void testGracePeriod() {
    KafkaConnect resource = new KafkaConnectBuilder(this.resource).editSpec().withNewTemplate().withNewPod().withTerminationGracePeriodSeconds(123).endPod().endTemplate().endSpec().build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kc.generateDeployment(emptyMap(), true, null, null);
    assertThat(dep.getSpec().getTemplate().getSpec().getTerminationGracePeriodSeconds(), is(Long.valueOf(123)));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 30 with KafkaConnect

use of io.strimzi.api.kafka.model.KafkaConnect in project strimzi by strimzi.

the class KafkaConnectBuildTest method testValidationPluginsExist.

@ParallelTest
public void testValidationPluginsExist() {
    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().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) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)266 KafkaConnectBuilder (io.strimzi.api.kafka.model.KafkaConnectBuilder)200 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)134 ParallelTest (io.strimzi.test.annotations.ParallelTest)132 Reconciliation (io.strimzi.operator.common.Reconciliation)128 List (java.util.List)113 KafkaConnectResources (io.strimzi.api.kafka.model.KafkaConnectResources)112 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)112 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)110 Service (io.fabric8.kubernetes.api.model.Service)103 NetworkPolicy (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy)103 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)103 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)98 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)98 CoreMatchers.is (org.hamcrest.CoreMatchers.is)98 Collections.emptyList (java.util.Collections.emptyList)94 Test (org.junit.jupiter.api.Test)94 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)90 HashMap (java.util.HashMap)83 Map (java.util.Map)83