use of io.strimzi.api.kafka.model.ContainerEnvVarBuilder in project strimzi-kafka-operator by strimzi.
the class ListenersST method testSendMessagesTlsScramSha.
/**
* Test sending messages over tls transport using scram sha auth
*/
@ParallelNamespaceTest
@Tag(ACCEPTANCE)
@Tag(INTERNAL_CLIENTS_USED)
void testSendMessagesTlsScramSha(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
final String kafkaUsername = mapWithTestUsers.get(extensionContext.getDisplayName());
final int passwordLength = 25;
// Use a Kafka with plain listener disabled
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9096).withTls(true).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).endKafka().editEntityOperator().editOrNewTemplate().editOrNewUserOperatorContainer().addToEnv(new ContainerEnvVarBuilder().withName("STRIMZI_SCRAM_SHA_PASSWORD_LENGTH").withValue(String.valueOf(passwordLength)).build()).endUserOperatorContainer().endTemplate().endEntityOperator().endSpec().build());
resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(clusterName, topicName).build());
KafkaUser kafkaUser = KafkaUserTemplates.scramShaUser(clusterName, kafkaUsername).build();
resourceManager.createResource(extensionContext, kafkaUser);
resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(namespaceName, true, clusterName + "-" + Constants.KAFKA_CLIENTS, kafkaUser).build());
final String kafkaClientsPodName = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, clusterName + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();
InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder().withUsingPodName(kafkaClientsPodName).withTopicName(topicName).withNamespaceName(namespaceName).withClusterName(clusterName).withKafkaUsername(kafkaUsername).withMessageCount(MESSAGE_COUNT).withListenerName(Constants.TLS_LISTENER_DEFAULT_NAME).build();
// Check brokers availability
LOGGER.info("Checking produced and consumed messages to pod:{}", kafkaClientsPodName);
internalKafkaClient.checkProducedAndConsumedMessages(internalKafkaClient.sendMessagesTls(), internalKafkaClient.receiveMessagesTls());
LOGGER.info("Checking if generated password has {} characters", passwordLength);
String password = kubeClient().namespace(namespaceName).getSecret(kafkaUsername).getData().get("password");
String decodedPassword = new String(Base64.getDecoder().decode(password));
assertEquals(decodedPassword.length(), passwordLength);
Service kafkaService = kubeClient(namespaceName).getService(namespaceName, KafkaResources.bootstrapServiceName(clusterName));
String kafkaServiceDiscoveryAnnotation = kafkaService.getMetadata().getAnnotations().get("strimzi.io/discovery");
JsonArray serviceDiscoveryArray = new JsonArray(kafkaServiceDiscoveryAnnotation);
assertThat(serviceDiscoveryArray, is(StUtils.expectedServiceDiscoveryInfo(9096, "kafka", "scram-sha-512", true)));
}
use of io.strimzi.api.kafka.model.ContainerEnvVarBuilder 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));
}
use of io.strimzi.api.kafka.model.ContainerEnvVarBuilder in project strimzi by strimzi.
the class ListenersST method testSendMessagesTlsScramSha.
/**
* Test sending messages over tls transport using scram sha auth
*/
@ParallelNamespaceTest
@Tag(ACCEPTANCE)
@Tag(INTERNAL_CLIENTS_USED)
void testSendMessagesTlsScramSha(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
final String kafkaUsername = mapWithTestUsers.get(extensionContext.getDisplayName());
final int passwordLength = 25;
// Use a Kafka with plain listener disabled
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9096).withTls(true).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).endKafka().editEntityOperator().editOrNewTemplate().editOrNewUserOperatorContainer().addToEnv(new ContainerEnvVarBuilder().withName("STRIMZI_SCRAM_SHA_PASSWORD_LENGTH").withValue(String.valueOf(passwordLength)).build()).endUserOperatorContainer().endTemplate().endEntityOperator().endSpec().build());
resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(clusterName, topicName).build());
KafkaUser kafkaUser = KafkaUserTemplates.scramShaUser(clusterName, kafkaUsername).build();
resourceManager.createResource(extensionContext, kafkaUser);
resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(namespaceName, true, clusterName + "-" + Constants.KAFKA_CLIENTS, kafkaUser).build());
final String kafkaClientsPodName = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, clusterName + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();
InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder().withUsingPodName(kafkaClientsPodName).withTopicName(topicName).withNamespaceName(namespaceName).withClusterName(clusterName).withKafkaUsername(kafkaUsername).withMessageCount(MESSAGE_COUNT).withListenerName(Constants.TLS_LISTENER_DEFAULT_NAME).build();
// Check brokers availability
LOGGER.info("Checking produced and consumed messages to pod:{}", kafkaClientsPodName);
internalKafkaClient.checkProducedAndConsumedMessages(internalKafkaClient.sendMessagesTls(), internalKafkaClient.receiveMessagesTls());
LOGGER.info("Checking if generated password has {} characters", passwordLength);
String password = kubeClient().namespace(namespaceName).getSecret(kafkaUsername).getData().get("password");
String decodedPassword = new String(Base64.getDecoder().decode(password));
assertEquals(decodedPassword.length(), passwordLength);
Service kafkaService = kubeClient(namespaceName).getService(namespaceName, KafkaResources.bootstrapServiceName(clusterName));
String kafkaServiceDiscoveryAnnotation = kafkaService.getMetadata().getAnnotations().get("strimzi.io/discovery");
JsonArray serviceDiscoveryArray = new JsonArray(kafkaServiceDiscoveryAnnotation);
assertThat(serviceDiscoveryArray, is(StUtils.expectedServiceDiscoveryInfo(9096, "kafka", "scram-sha-512", true)));
}
use of io.strimzi.api.kafka.model.ContainerEnvVarBuilder 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));
}
Aggregations