func (p *DefaultJobParser) NewTrainingJob(job *paddlev1.TrainingJob) (*paddlev1.TrainingJob, error) {
	if err := setDefaultAndValidate(job); err != nil {
		return nil, err
	}
	useHostNetwork := job.Spec.HostNetwork
	if job.Spec.FaultTolerant {
		job.Spec.Master.ReplicaSpec = parseToMaster(job)
		if useHostNetwork {
			job.Spec.Master.ReplicaSpec.Spec.Template.Spec.HostNetwork = true
		}
	}
	job.Spec.Pserver.ReplicaSpec = parseToPserver(job, nil, true)
	job.Spec.Trainer.ReplicaSpec = parseToTrainer(job, nil, true)
	if useHostNetwork {
		job.Spec.Pserver.ReplicaSpec.Spec.Template.Spec.HostNetwork = true
		job.Spec.Trainer.ReplicaSpec.Spec.Template.Spec.HostNetwork = true
	}
	return job, nil
}
NewTrainingJob generates a whole structure of TrainingJob
package updater
import (
	"errors"
	"fmt"
	"strconv"
	"strings"
	batchv1 "k8s.io/api/batch/v1"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/api/extensions/v1beta1"
	apiresource "k8s.io/apimachinery/pkg/api/resource"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	paddlev1 "github.com/baidu/paddle-on-k8s-operator/pkg/apis/paddlepaddle/v1alpha1"
)
type PodType string
const (
	PSERVER      PodType = "pserver"
	TRAINER      PodType = "trainer"
	MASTER       PodType = "master"
	TrainerLabel         = "paddle-job"
	PserverLabel         = "paddle-job-pserver"
	MasterLabel          = "paddle-job-master"
)
const (
	imagePullPolicy = "Always"
)
type DefaultJobParser struct {
}
func setDefaultAndValidate(job *paddlev1.TrainingJob) error {
	if job.Spec.Port == 0 {
		job.Spec.Port = 7164
	}
	if job.Spec.PortsNum == 0 {
		job.Spec.PortsNum = 1
	}
	if job.Spec.PortsNumForSparse == 0 {
		job.Spec.PortsNumForSparse = 1
	}
	if job.Spec.Image == "" {
		job.Spec.Image = "paddlepaddle/paddlecloud-job:0.11.0"
	}
	if job.Spec.Passes == 0 {
		job.Spec.Passes = 1
	}
	if !job.Spec.FaultTolerant && job.Elastic() {
		return errors.New("max-instances should be equal to min-instances when fault_tolerant is disabled")
	}
	return nil
}