Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job conditions (status&lastTransitionTime) #1764

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions config/crd/bases/batch.volcano.sh_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions config/crd/v1beta1/batch.volcano.sh_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
19 changes: 19 additions & 0 deletions installer/helm/chart/volcano/crd/bases/batch.volcano.sh_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions installer/volcano-development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/cli/job/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions pkg/controllers/job/job_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions vendor/volcano.sh/apis/pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.