Search in sources :

Example 1 with ContainerEnvVarBuilder

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)));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Service(io.fabric8.kubernetes.api.model.Service) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 2 with ContainerEnvVarBuilder

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));
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) Reconciliation(io.strimzi.operator.common.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 3 with ContainerEnvVarBuilder

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)));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Service(io.fabric8.kubernetes.api.model.Service) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 4 with ContainerEnvVarBuilder

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));
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) Reconciliation(io.strimzi.operator.common.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

ContainerEnvVarBuilder (io.strimzi.api.kafka.model.ContainerEnvVarBuilder)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Pod (io.fabric8.kubernetes.api.model.Pod)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 Service (io.fabric8.kubernetes.api.model.Service)2 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)2 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)2 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)2 KafkaConnectBuilder (io.strimzi.api.kafka.model.KafkaConnectBuilder)2 KafkaUser (io.strimzi.api.kafka.model.KafkaUser)2 PluginBuilder (io.strimzi.api.kafka.model.connect.build.PluginBuilder)2 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)2 InternalKafkaClient (io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient)2 ParallelTest (io.strimzi.test.annotations.ParallelTest)2 JsonArray (io.vertx.core.json.JsonArray)2 Tag (org.junit.jupiter.api.Tag)2