diff --git a/config/crd/bases/batch.volcano.sh_jobs.yaml b/config/crd/bases/batch.volcano.sh_jobs.yaml index 4164a86f73..902dd36dff 100644 --- a/config/crd/bases/batch.volcano.sh_jobs.yaml +++ b/config/crd/bases/batch.volcano.sh_jobs.yaml @@ -7066,6 +7066,25 @@ spec: status: description: Current status of the volcano Job properties: + conditions: + description: Which conditions caused the current job state. + items: + description: JobCondition contains details for the current condition + of this job. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one phase + to another. + format: date-time + type: string + status: + description: Status is the new phase of job after performing + the state's action. + type: string + required: + - status + type: object + type: array controlledResources: additionalProperties: type: string diff --git a/config/crd/v1beta1/batch.volcano.sh_jobs.yaml b/config/crd/v1beta1/batch.volcano.sh_jobs.yaml index 37994a3f49..b0902a3dc4 100644 --- a/config/crd/v1beta1/batch.volcano.sh_jobs.yaml +++ b/config/crd/v1beta1/batch.volcano.sh_jobs.yaml @@ -6894,6 +6894,25 @@ spec: status: description: Current status of the volcano Job properties: + conditions: + description: Which conditions caused the current job state. + items: + description: JobCondition contains details for the current condition + of this job. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one phase + to another. + format: date-time + type: string + status: + description: Status is the new phase of job after performing the + state's action. + type: string + required: + - status + type: object + type: array controlledResources: additionalProperties: type: string diff --git a/go.mod b/go.mod index 3619bdff1b..2220248305 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( k8s.io/klog v1.0.0 k8s.io/kubernetes v1.19.11 sigs.k8s.io/yaml v1.2.0 - volcano.sh/apis v0.0.0-20210603070204-70005b2d502a + volcano.sh/apis v0.0.0-20210923020136-eb779276d17e ) replace ( diff --git a/go.sum b/go.sum index d53c702348..51fb548a4c 100644 --- a/go.sum +++ b/go.sum @@ -866,5 +866,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI= -volcano.sh/apis v0.0.0-20210603070204-70005b2d502a h1:h6c+NZglstX8JGuwLrU6/0/FnBcT26XO1S3PvtykRTk= -volcano.sh/apis v0.0.0-20210603070204-70005b2d502a/go.mod h1:UaeJ/s5Hyd+ZhFLc+Kw9YlgM8gRZ/5OzXqHa0yKOoXY= +volcano.sh/apis v0.0.0-20210923020136-eb779276d17e h1:F89sQUZt3YjQ6EYyeu1Nqecruc7V2/2N8Q1CiSLlGYE= +volcano.sh/apis v0.0.0-20210923020136-eb779276d17e/go.mod h1:UaeJ/s5Hyd+ZhFLc+Kw9YlgM8gRZ/5OzXqHa0yKOoXY= diff --git a/installer/helm/chart/volcano/crd/bases/batch.volcano.sh_jobs.yaml b/installer/helm/chart/volcano/crd/bases/batch.volcano.sh_jobs.yaml index 2706fc5d21..ff3ffcec18 100644 --- a/installer/helm/chart/volcano/crd/bases/batch.volcano.sh_jobs.yaml +++ b/installer/helm/chart/volcano/crd/bases/batch.volcano.sh_jobs.yaml @@ -7064,6 +7064,25 @@ spec: status: description: Current status of the volcano Job properties: + conditions: + description: Which conditions caused the current job state. + items: + description: JobCondition contains details for the current condition + of this job. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one phase + to another. + format: date-time + type: string + status: + description: Status is the new phase of job after performing + the state's action. + type: string + required: + - status + type: object + type: array controlledResources: additionalProperties: type: string diff --git a/installer/helm/chart/volcano/crd/v1beta1/batch.volcano.sh_jobs.yaml b/installer/helm/chart/volcano/crd/v1beta1/batch.volcano.sh_jobs.yaml index 5db1007ccb..f112de3a18 100644 --- a/installer/helm/chart/volcano/crd/v1beta1/batch.volcano.sh_jobs.yaml +++ b/installer/helm/chart/volcano/crd/v1beta1/batch.volcano.sh_jobs.yaml @@ -6892,6 +6892,25 @@ spec: status: description: Current status of the volcano Job properties: + conditions: + description: Which conditions caused the current job state. + items: + description: JobCondition contains details for the current condition + of this job. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one phase + to another. + format: date-time + type: string + status: + description: Status is the new phase of job after performing the + state's action. + type: string + required: + - status + type: object + type: array controlledResources: additionalProperties: type: string diff --git a/installer/volcano-development.yaml b/installer/volcano-development.yaml index 3364fdfeec..d0696ba17e 100644 --- a/installer/volcano-development.yaml +++ b/installer/volcano-development.yaml @@ -7249,6 +7249,25 @@ spec: status: description: Current status of the volcano Job properties: + conditions: + description: Which conditions caused the current job state. + items: + description: JobCondition contains details for the current condition + of this job. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one phase + to another. + format: date-time + type: string + status: + description: Status is the new phase of job after performing + the state's action. + type: string + required: + - status + type: object + type: array controlledResources: additionalProperties: type: string diff --git a/pkg/cli/job/view.go b/pkg/cli/job/view.go index 10f64c2e27..cc2a61546e 100644 --- a/pkg/cli/job/view.go +++ b/pkg/cli/job/view.go @@ -197,6 +197,14 @@ func PrintJobInfo(job *v1alpha1.Job, writer io.Writer) { WriteLine(writer, Level2, "%s: \t%s\n", key, value) } } + if len(job.Status.Conditions) > 0 { + WriteLine(writer, Level1, "Conditions:\n Status\tTransitionTime\n") + for _, c := range job.Status.Conditions { + WriteLine(writer, Level2, "%v \t%v \n", + c.Status, + c.LastTransitionTime) + } + } } // PrintEvents print event info to writer. diff --git a/pkg/controllers/job/job_controller_actions.go b/pkg/controllers/job/job_controller_actions.go index a14acfebbe..368cd0d0f4 100644 --- a/pkg/controllers/job/job_controller_actions.go +++ b/pkg/controllers/job/job_controller_actions.go @@ -116,6 +116,8 @@ func (cc *jobcontroller) killJob(jobInfo *apis.JobInfo, podRetainPhase state.Pha if updateStatus != nil { if updateStatus(&job.Status) { job.Status.State.LastTransitionTime = metav1.Now() + jobCondition := newCondition(job.Status.State.Phase, &job.Status.State.LastTransitionTime) + job.Status.Conditions = append(job.Status.Conditions, jobCondition) } } @@ -279,10 +281,13 @@ func (cc *jobcontroller) syncJob(jobInfo *apis.JobInfo, updateStatus state.Updat } } + var jobCondition batch.JobCondition if !syncTask { if updateStatus != nil { if updateStatus(&job.Status) { job.Status.State.LastTransitionTime = metav1.Now() + jobCondition = newCondition(job.Status.State.Phase, &job.Status.State.LastTransitionTime) + job.Status.Conditions = append(job.Status.Conditions, jobCondition) } } newJob, err := cc.vcClient.BatchV1alpha1().Jobs(job.Namespace).UpdateStatus(context.TODO(), job, metav1.UpdateOptions{}) @@ -421,12 +426,15 @@ func (cc *jobcontroller) syncJob(jobInfo *apis.JobInfo, updateStatus state.Updat MinAvailable: job.Spec.MinAvailable, TaskStatusCount: taskStatusCount, ControlledResources: job.Status.ControlledResources, + Conditions: job.Status.Conditions, RetryCount: job.Status.RetryCount, } if updateStatus != nil { if updateStatus(&job.Status) { job.Status.State.LastTransitionTime = metav1.Now() + jobCondition = newCondition(job.Status.State.Phase, &job.Status.State.LastTransitionTime) + job.Status.Conditions = append(job.Status.Conditions, jobCondition) } } newJob, err := cc.vcClient.BatchV1alpha1().Jobs(job.Namespace).UpdateStatus(context.TODO(), job, metav1.UpdateOptions{}) @@ -685,6 +693,8 @@ func (cc *jobcontroller) initJobStatus(job *batch.Job) (*batch.Job, error) { job.Status.State.Phase = batch.Pending job.Status.State.LastTransitionTime = metav1.Now() job.Status.MinAvailable = job.Spec.MinAvailable + jobCondition := newCondition(job.Status.State.Phase, &job.Status.State.LastTransitionTime) + job.Status.Conditions = append(job.Status.Conditions, jobCondition) newJob, err := cc.vcClient.BatchV1alpha1().Jobs(job.Namespace).UpdateStatus(context.TODO(), job, metav1.UpdateOptions{}) if err != nil { klog.Errorf("Failed to update status of Job %v/%v: %v", @@ -750,3 +760,10 @@ func isInitiated(job *batch.Job) bool { return true } + +func newCondition(status batch.JobPhase, lastTransitionTime *metav1.Time) batch.JobCondition { + return batch.JobCondition{ + Status: status, + LastTransitionTime: lastTransitionTime, + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 97789881bb..0b8e7e4891 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -845,7 +845,7 @@ sigs.k8s.io/structured-merge-diff/v4/value # sigs.k8s.io/yaml v1.2.0 ## explicit sigs.k8s.io/yaml -# volcano.sh/apis v0.0.0-20210603070204-70005b2d502a +# volcano.sh/apis v0.0.0-20210923020136-eb779276d17e ## explicit volcano.sh/apis/pkg/apis/batch/v1alpha1 volcano.sh/apis/pkg/apis/bus/v1alpha1 diff --git a/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/job.go b/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/job.go index b0ce1b80a1..7631508ff5 100644 --- a/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/job.go +++ b/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/job.go @@ -317,6 +317,12 @@ type JobStatus struct { // The resources that controlled by this job, e.g. Service, ConfigMap // +optional ControlledResources map[string]string `json:"controlledResources,omitempty" protobuf:"bytes,11,opt,name=controlledResources"` + + // Which conditions caused the current job state. + // +optional + // +patchMergeKey=status + // +patchStrategy=merge + Conditions []JobCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"status" protobuf:"bytes,12,rep,name=conditions"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -329,3 +335,12 @@ type JobList struct { Items []Job `json:"items" protobuf:"bytes,2,rep,name=items"` } + +// JobCondition contains details for the current condition of this job. +type JobCondition struct { + // Status is the new phase of job after performing the state's action. + Status JobPhase `json:"status" protobuf:"bytes,1,opt,name=status,casttype=JobPhase"` + // Last time the condition transitioned from one phase to another. + // +optional + LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,2,opt,name=lastTransitionTime"` +} diff --git a/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/zz_generated.deepcopy.go b/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/zz_generated.deepcopy.go index 4fb4886b8c..f9c95ac999 100644 --- a/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/zz_generated.deepcopy.go @@ -54,6 +54,26 @@ func (in *Job) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *JobCondition) DeepCopyInto(out *JobCondition) { + *out = *in + if in.LastTransitionTime != nil { + in, out := &in.LastTransitionTime, &out.LastTransitionTime + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JobCondition. +func (in *JobCondition) DeepCopy() *JobCondition { + if in == nil { + return nil + } + out := new(JobCondition) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JobList) DeepCopyInto(out *JobList) { *out = *in @@ -194,6 +214,13 @@ func (in *JobStatus) DeepCopyInto(out *JobStatus) { (*out)[key] = val } } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]JobCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return }