private Job getJob()

in computer-k8s-operator/src/main/java/org/apache/hugegraph/computer/k8s/operator/controller/ComputerJobDeployer.java [296:364]


    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();
    }