use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2ClusterTest method testGenerateDeploymentWithScramSha512AuthAndTLSSameSecret.
/**
* This test uses the same secret to hold the certs for TLS and the credentials for SCRAM SHA 512 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 testGenerateDeploymentWithScramSha512AuthAndTLSSameSecret() {
KafkaMirrorMaker2ClusterSpec targetClusterWithScramSha512Auth = new KafkaMirrorMaker2ClusterSpecBuilder(this.targetCluster).editOrNewTls().addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("cert.crt").build()).endTls().withNewKafkaClientAuthenticationScramSha512().withUsername("user1").withNewPasswordSecret().withSecretName("my-secret").withPassword("user1.password").endPasswordSecret().endKafkaClientAuthenticationScramSha512().build();
KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withClusters(targetClusterWithScramSha512Auth).endSpec().build();
KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().size(), is(4));
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"));
assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(3).getName(), is("target-my-secret"));
Container cont = getContainer(dep);
assertThat(cont.getVolumeMounts().size(), is(6));
assertThat(cont.getVolumeMounts().get(0).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
assertThat(cont.getVolumeMounts().get(0).getMountPath(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
assertThat(cont.getVolumeMounts().get(1).getName(), is("kafka-metrics-and-logging"));
assertThat(cont.getVolumeMounts().get(1).getMountPath(), is("/opt/kafka/custom-config/"));
assertThat(cont.getVolumeMounts().get(2).getName(), is("my-secret"));
assertThat(cont.getVolumeMounts().get(2).getMountPath(), is(KafkaMirrorMaker2Cluster.TLS_CERTS_BASE_VOLUME_MOUNT + "my-secret"));
assertThat(cont.getVolumeMounts().get(3).getName(), is("my-secret"));
assertThat(cont.getVolumeMounts().get(3).getMountPath(), is(KafkaMirrorMaker2Cluster.PASSWORD_VOLUME_MOUNT + "my-secret"));
assertThat(cont.getVolumeMounts().get(4).getName(), is("target-my-secret"));
assertThat(cont.getVolumeMounts().get(4).getMountPath(), is(KafkaMirrorMaker2Cluster.MIRRORMAKER_2_TLS_CERTS_BASE_VOLUME_MOUNT + targetClusterAlias + "/my-secret"));
assertThat(cont.getVolumeMounts().get(5).getName(), is("target-my-secret"));
assertThat(cont.getVolumeMounts().get(5).getMountPath(), is(KafkaMirrorMaker2Cluster.MIRRORMAKER_2_PASSWORD_VOLUME_MOUNT + targetClusterAlias + "/my-secret"));
assertThat(AbstractModel.containerEnvVars(cont), hasEntry(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_SASL_PASSWORD_FILE, "my-secret/user1.password"));
assertThat(AbstractModel.containerEnvVars(cont), hasEntry(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_SASL_USERNAME, "user1"));
assertThat(AbstractModel.containerEnvVars(cont), hasEntry(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_SASL_MECHANISM, "scram-sha-512"));
assertThat(AbstractModel.containerEnvVars(cont), hasEntry(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_TLS, "true"));
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2ClusterTest method testImagePullSecretsBoth.
@ParallelTest
public void testImagePullSecretsBoth() {
LocalObjectReference secret1 = new LocalObjectReference("some-pull-secret");
LocalObjectReference secret2 = new LocalObjectReference("some-other-pull-secret");
KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withNewTemplate().withNewPod().withImagePullSecrets(secret2).endPod().endTemplate().endSpec().build();
KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, singletonList(secret1));
assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().size(), is(1));
assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().contains(secret1), is(false));
assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().contains(secret2), is(true));
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2ClusterTest method testGracePeriod.
@ParallelTest
public void testGracePeriod() {
KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withNewTemplate().withNewPod().withTerminationGracePeriodSeconds(123).endPod().endTemplate().endSpec().build();
KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
assertThat(dep.getSpec().getTemplate().getSpec().getTerminationGracePeriodSeconds(), is(Long.valueOf(123)));
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2ClusterTest method testGenerateServiceWithoutMetrics.
@ParallelTest
public void testGenerateServiceWithoutMetrics() {
KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withMetricsConfig(null).endSpec().build();
KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
Service svc = kmm2.generateService();
assertThat(svc.getSpec().getType(), is("ClusterIP"));
assertThat(svc.getMetadata().getLabels(), is(expectedLabels(kmm2.getServiceName())));
assertThat(svc.getSpec().getSelector(), is(expectedSelectorLabels()));
assertThat(svc.getSpec().getPorts().size(), is(1));
assertThat(svc.getSpec().getPorts().get(0).getPort(), is(Integer.valueOf(KafkaMirrorMaker2Cluster.REST_API_PORT)));
assertThat(svc.getSpec().getPorts().get(0).getName(), is(KafkaMirrorMaker2Cluster.REST_API_PORT_NAME));
assertThat(svc.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
assertThat(svc.getMetadata().getAnnotations().containsKey("prometheus.io/port"), is(false));
assertThat(svc.getMetadata().getAnnotations().containsKey("prometheus.io/scrape"), is(false));
assertThat(svc.getMetadata().getAnnotations().containsKey("prometheus.io/path"), is(false));
checkOwnerReference(kmm2.createOwnerReference(), svc);
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2ClusterTest method testExternalConfigurationConfigEnvs.
@ParallelTest
public void testExternalConfigurationConfigEnvs() {
ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder().withName("MY_ENV_VAR").withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-map").withKey("my-key").withOptional(false).build()).endValueFrom().build();
KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withNewExternalConfiguration().withEnv(env).endExternalConfiguration().endSpec().build();
KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
// Check Deployment
Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
List<EnvVar> envs = getContainer(dep).getEnv();
List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList());
assertThat(selected.size(), is(1));
assertThat(selected.get(0).getName(), is("MY_ENV_VAR"));
assertThat(selected.get(0).getValueFrom().getConfigMapKeyRef(), is(env.getValueFrom().getConfigMapKeyRef()));
}
Aggregations