Search in sources :

Example 11 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project fabric8-maven-plugin by fabric8io.

the class TriggersAnnotationEnricherTest method testNoEnrichment.

@Test
public void testNoEnrichment() {
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new JobBuilder().withNewMetadata().addToAnnotations("dummy", "annotation").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(createContainers("c1", "is1:latest", "c2", "is2:latest")).endSpec().endTemplate().endSpec().build());
    TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context);
    enricher.enrich(PlatformMode.kubernetes, builder);
    Job res = (Job) builder.build().getItems().get(0);
    String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers");
    assertNull(triggers);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.JobBuilder) Job(io.fabric8.kubernetes.api.model.batch.Job) Test(org.junit.Test)

Example 12 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.

the class KafkaAdminClients method defaultAdmin.

public Job defaultAdmin() {
    Map<String, String> adminLabels = new HashMap<>();
    adminLabels.put("app", adminName);
    adminLabels.put(Constants.KAFKA_ADMIN_CLIENT_LABEL_KEY, Constants.KAFKA_ADMIN_CLIENT_LABEL_VALUE);
    PodSpecBuilder podSpecBuilder = new PodSpecBuilder();
    if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
        List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
        podSpecBuilder.withImagePullSecrets(imagePullSecrets);
    }
    return new JobBuilder().withNewMetadata().withNamespace(this.getNamespaceName()).withLabels(adminLabels).withName(adminName).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withName(adminName).withNamespace(this.getNamespaceName()).withLabels(adminLabels).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("Never").withContainers().addNewContainer().withName(adminName).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_ADMIN_IMAGE).addNewEnv().withName("BOOTSTRAP_SERVERS").withValue(this.getBootstrapAddress()).endEnv().addNewEnv().withName("TOPIC").withValue(this.getTopicName()).endEnv().addNewEnv().withName("TOPIC_OPERATION").withValue(topicOperation).endEnv().addNewEnv().withName("REPLICATION_FACTOR").withValue(String.valueOf(replicationFactor)).endEnv().addNewEnv().withName("PARTITIONS").withValue(String.valueOf(partitions)).endEnv().addNewEnv().withName("TOPICS_COUNT").withValue(String.valueOf(topicCount)).endEnv().addNewEnv().withName("TOPIC_OFFSET").withValue(String.valueOf(topicOffset)).endEnv().addNewEnv().withName("LOG_LEVEL").withValue("DEBUG").endEnv().addNewEnv().withName("ADDITIONAL_CONFIG").withValue(this.getAdditionalConfig()).endEnv().endContainer().endSpec().endTemplate().endSpec().build();
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)

Example 13 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.

the class BridgeClients method producerStrimziBridge.

public Job producerStrimziBridge() {
    Map<String, String> producerLabels = new HashMap<>();
    producerLabels.put("app", this.getProducerName());
    producerLabels.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_BRIDGE_CLIENTS_LABEL_VALUE);
    PodSpecBuilder podSpecBuilder = new PodSpecBuilder();
    if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
        List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
        podSpecBuilder.withImagePullSecrets(imagePullSecrets);
    }
    return new JobBuilder().withNewMetadata().withNamespace(this.getNamespaceName()).withLabels(producerLabels).withName(this.getProducerName()).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withLabels(producerLabels).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("OnFailure").addNewContainer().withName(this.getProducerName()).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_HTTP_PRODUCER_IMAGE).addNewEnv().withName("HOSTNAME").withValue(this.getBootstrapAddress()).endEnv().addNewEnv().withName("PORT").withValue(Integer.toString(port)).endEnv().addNewEnv().withName("TOPIC").withValue(this.getTopicName()).endEnv().addNewEnv().withName("DELAY_MS").withValue(String.valueOf(this.getDelayMs())).endEnv().addNewEnv().withName("MESSAGE_COUNT").withValue(Integer.toString(this.getMessageCount())).endEnv().endContainer().endSpec().endTemplate().endSpec().build();
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)

Example 14 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.

the class KafkaClients method defaultConsumerStrimzi.

public JobBuilder defaultConsumerStrimzi() {
    if (consumerName == null || consumerName.isEmpty()) {
        throw new InvalidParameterException("Consumer name is not set.");
    }
    Map<String, String> consumerLabels = new HashMap<>();
    consumerLabels.put("app", consumerName);
    consumerLabels.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);
    PodSpecBuilder podSpecBuilder = new PodSpecBuilder();
    if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
        List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
        podSpecBuilder.withImagePullSecrets(imagePullSecrets);
    }
    return new JobBuilder().withNewMetadata().withNamespace(this.getNamespaceName()).withLabels(consumerLabels).withName(consumerName).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withLabels(consumerLabels).withNamespace(this.getNamespaceName()).withName(consumerName).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("Never").withContainers().addNewContainer().withName(consumerName).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_CONSUMER_IMAGE).addNewEnv().withName("BOOTSTRAP_SERVERS").withValue(this.getBootstrapAddress()).endEnv().addNewEnv().withName("TOPIC").withValue(this.getTopicName()).endEnv().addNewEnv().withName("DELAY_MS").withValue(String.valueOf(delayMs)).endEnv().addNewEnv().withName("LOG_LEVEL").withValue("DEBUG").endEnv().addNewEnv().withName("MESSAGE_COUNT").withValue(String.valueOf(messageCount)).endEnv().addNewEnv().withName("GROUP_ID").withValue(consumerGroup).endEnv().addNewEnv().withName("ADDITIONAL_CONFIG").withValue(this.getAdditionalConfig()).endEnv().endContainer().endSpec().endTemplate().endSpec();
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) InvalidParameterException(java.security.InvalidParameterException) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)

Example 15 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.

the class MirrorMaker2IsolatedST method testMirrorMaker2CorrectlyMirrorsHeaders.

@ParallelNamespaceTest
void testMirrorMaker2CorrectlyMirrorsHeaders(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    String kafkaClusterSourceName = clusterName + "-source";
    String kafkaClusterTargetName = clusterName + "-target";
    String sourceProducerName = clusterName + "-source-producer";
    String targetConsumerName = clusterName + "-target-consumer";
    String sourceExampleTopic = clusterName + "-source-example-topic";
    String targetExampleTopic = kafkaClusterSourceName + "." + sourceExampleTopic;
    // Deploy source kafka
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterSourceName, 1, 1).build());
    // Deploy target kafka
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterTargetName, 1, 1).build());
    // Deploy Topic for example clients
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(kafkaClusterSourceName, sourceExampleTopic).build());
    resourceManager.createResource(extensionContext, KafkaMirrorMaker2Templates.kafkaMirrorMaker2(clusterName, kafkaClusterTargetName, kafkaClusterSourceName, 1, false).build());
    // deploying example clients for checking if mm2 will mirror messages with headers
    KafkaClients targetKafkaClientsJob = new KafkaClientsBuilder().withConsumerName(targetConsumerName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(kafkaClusterTargetName)).withTopicName(targetExampleTopic).withMessageCount(MESSAGE_COUNT).withDelayMs(1000).build();
    resourceManager.createResource(extensionContext, targetKafkaClientsJob.consumerStrimzi());
    KafkaClients sourceKafkaClientsJob = new KafkaClientsBuilder().withProducerName(sourceProducerName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(kafkaClusterSourceName)).withTopicName(sourceExampleTopic).withMessageCount(MESSAGE_COUNT).withDelayMs(1000).build();
    resourceManager.createResource(extensionContext, new JobBuilder(sourceKafkaClientsJob.producerStrimzi()).editSpec().editTemplate().editSpec().editContainer(0).addNewEnv().withName("HEADERS").withValue("header_key_one=header_value_one, header_key_two=header_value_two").endEnv().endContainer().endSpec().endTemplate().endSpec().build());
    ClientUtils.waitTillContinuousClientsFinish(sourceProducerName, targetConsumerName, namespaceName, MESSAGE_COUNT);
    LOGGER.info("Checking log of {} job if the headers are correct", targetConsumerName);
    String header1 = "key: header_key_one, value: header_value_one";
    String header2 = "key: header_key_two, value: header_value_two";
    String log = StUtils.getLogFromPodByTime(namespaceName, kubeClient(namespaceName).listPodsByPrefixInName(targetConsumerName).get(0).getMetadata().getName(), "", MESSAGE_COUNT + "s");
    assertThat(log, containsString(header1));
    assertThat(log, containsString(header2));
}
Also used : KafkaClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder) KafkaClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Aggregations

JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)15 HashMap (java.util.HashMap)13 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)12 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)12 InvalidParameterException (java.security.InvalidParameterException)4 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)2 KafkaClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients)2 KafkaClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonValue (com.fasterxml.jackson.annotation.JsonValue)1 Bind (com.spotify.docker.client.messages.HostConfig.Bind)1 DockerContainer (io.elastest.epm.client.DockerContainer)1 DockerProject (io.elastest.epm.client.json.DockerProject)1 UtilTools (io.elastest.epm.client.utils.UtilTools)1 Capabilities (io.fabric8.kubernetes.api.model.Capabilities)1 CapabilitiesBuilder (io.fabric8.kubernetes.api.model.CapabilitiesBuilder)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1