Search in sources :

Example 6 with JobBuilder

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

the class BridgeClients method consumerStrimziBridge.

public Job consumerStrimziBridge() {
    Map<String, String> consumerLabels = new HashMap<>();
    consumerLabels.put("app", this.getConsumerName());
    consumerLabels.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(consumerLabels).withName(this.getConsumerName()).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withLabels(consumerLabels).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("OnFailure").addNewContainer().withName(this.getConsumerName()).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_HTTP_CONSUMER_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("POLL_INTERVAL").withValue(Integer.toString(pollInterval)).endEnv().addNewEnv().withName("MESSAGE_COUNT").withValue(Integer.toString(this.getMessageCount())).endEnv().addNewEnv().withName("GROUP_ID").withValue(this.getConsumerGroup()).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 7 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi-kafka-operator 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 8 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi-kafka-operator 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 9 with JobBuilder

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

the class KafkaClients method defaultProducerStrimzi.

public JobBuilder defaultProducerStrimzi() {
    if (producerName == null || producerName.isEmpty()) {
        throw new InvalidParameterException("Producer name is not set.");
    }
    Map<String, String> producerLabels = new HashMap<>();
    producerLabels.put("app", producerName);
    producerLabels.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(producerLabels).withName(producerName).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withName(producerName).withNamespace(this.getNamespaceName()).withLabels(producerLabels).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("Never").withContainers().addNewContainer().withName(producerName).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_PRODUCER_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("MESSAGE").withValue(message).endEnv().addNewEnv().withName("PRODUCER_ACKS").withValue("all").endEnv().addNewEnv().withName("ADDITIONAL_CONFIG").withValue(this.getAdditionalConfig()).endEnv().addNewEnv().withName("BLOCKING_PRODUCER").withValue("true").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 10 with JobBuilder

use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project hugegraph-computer by hugegraph.

the class ComputerJobDeployer method getJob.

private Job getJob(String crName, ObjectMeta meta, ComputerJobSpec spec, int instances, List<Container> containers) {
    List<Volume> volumes = spec.getVolumes();
    if (volumes == null) {
        volumes = new ArrayList<>();
    } else {
        volumes = Lists.newArrayList(volumes);
    }
    volumes.addAll(this.getConfigMapAndSecretVolumes(spec));
    String configMapName = KubeUtil.configMapName(crName);
    Volume configVolume = this.getComputerConfigVolume(configMapName);
    volumes.add(configVolume);
    // Support PodSpec template
    PodTemplateSpec podTemplateSpec = spec.getPodTemplateSpec();
    if (podTemplateSpec == null) {
        podTemplateSpec = new PodTemplateSpec();
    } else {
        podTemplateSpec = Serialization.clone(podTemplateSpec);
    }
    ObjectMeta metadata = podTemplateSpec.getMetadata();
    if (metadata == null) {
        metadata = new ObjectMeta();
    }
    metadata = new ObjectMetaBuilder(metadata).addToLabels(meta.getLabels()).addToAnnotations(meta.getAnnotations()).build();
    podTemplateSpec.setMetadata(metadata);
    PodSpec podSpec = podTemplateSpec.getSpec();
    if (podSpec == null) {
        podSpec = new PodSpec();
    }
    podSpec.setVolumes(volumes);
    podSpec.setContainers(containers);
    podSpec.setRestartPolicy(JOB_RESTART_POLICY);
    if (podSpec.getTerminationGracePeriodSeconds() == null) {
        podSpec.setTerminationGracePeriodSeconds(TERMINATION_GRACE_PERIOD);
    }
    if (CollectionUtils.isEmpty(podSpec.getImagePullSecrets())) {
        podSpec.setImagePullSecrets(spec.getPullSecrets());
    }
    if (CollectionUtils.isEmpty(podSpec.getTopologySpreadConstraints())) {
        // Pod topology spread constraints default by node
        LabelSelector labelSelector = new LabelSelector();
        labelSelector.setMatchLabels(meta.getLabels());
        TopologySpreadConstraint spreadConstraint = new TopologySpreadConstraint(labelSelector, MAX_SKEW, TOPOLOGY_KEY, SCHEDULE_ANYWAY);
        podSpec.setTopologySpreadConstraints(Lists.newArrayList(spreadConstraint));
    }
    podTemplateSpec.setSpec(podSpec);
    return new JobBuilder().withMetadata(meta).withNewSpec().withParallelism(instances).withCompletions(instances).withBackoffLimit(JOB_BACKOFF_LIMIT).withTemplate(podTemplateSpec).endSpec().build();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Volume(io.fabric8.kubernetes.api.model.Volume) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder)

Aggregations

JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)27 HashMap (java.util.HashMap)13 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)12 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)12 Test (org.junit.jupiter.api.Test)9 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)7 InvalidParameterException (java.security.InvalidParameterException)4 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)3 Pod (io.fabric8.kubernetes.api.model.Pod)3 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)3 Container (io.fabric8.kubernetes.api.model.Container)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 PodList (io.fabric8.kubernetes.api.model.PodList)2 PodTemplate (io.fabric8.kubernetes.api.model.PodTemplate)2 PodTemplateBuilder (io.fabric8.kubernetes.api.model.PodTemplateBuilder)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 ReplicationControllerBuilder (io.fabric8.kubernetes.api.model.ReplicationControllerBuilder)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 DaemonSet (io.fabric8.kubernetes.api.model.apps.DaemonSet)2 DaemonSetBuilder (io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder)2