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

fix ejob nil pointer bug #1016

Merged
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
2 changes: 1 addition & 1 deletion apis/apps/v1alpha1/ephemeraljob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type EphemeralJobSpec struct {

// Replicas indicates a part of the quantity from matched pods by selector.
// Usually it is used for gray scale working.
// if Replicas exceeded the matched number by selector, replicas will not work.
// if Replicas exceeded the matched number by selector or not be set, replicas will not work.
Replicas *int32 `json:"replicas,omitempty"`

// Parallelism specifies the maximum desired number of pods which matches running ephemeral containers.
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/apps.kruise.io_ephemeraljobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ spec:
replicas:
description: Replicas indicates a part of the quantity from matched
pods by selector. Usually it is used for gray scale working. if
Replicas exceeded the matched number by selector, replicas will
not work.
Replicas exceeded the matched number by selector or not be set,
replicas will not work.
format: int32
type: integer
selector:
Expand Down
15 changes: 11 additions & 4 deletions pkg/controller/ephemeraljob/ephemeraljob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (r *ReconcileEphemeralJob) filterPods(job *appsv1alpha1.EphemeralJob) ([]*v
continue
}

if len(targetPods) < int(*job.Spec.Replicas) {
if job.Spec.Replicas == nil || len(targetPods) < int(*job.Spec.Replicas) {
targetPods = append(targetPods, &podList.Items[i])
}
}
Expand Down Expand Up @@ -375,20 +375,27 @@ func (r *ReconcileEphemeralJob) calculateStatus(job *appsv1alpha1.EphemeralJob,
return err
}

var replicas int32
if job.Spec.Replicas == nil {
replicas = job.Status.Matches
} else {
replicas = *job.Spec.Replicas
}

if job.Status.Matches == 0 {
job.Status.Phase = appsv1alpha1.EphemeralJobWaiting
job.Status.Conditions = addConditions(job.Status.Conditions, appsv1alpha1.EJobMatchedEmpty, "MatchEmpty", "job match no pods")
} else if job.Status.Succeeded == *job.Spec.Replicas && job.Status.Succeeded > 0 {
} else if job.Status.Succeeded == replicas && job.Status.Succeeded > 0 {
job.Status.CompletionTime = timeNow()
job.Status.Phase = appsv1alpha1.EphemeralJobSucceeded
job.Status.Conditions = addConditions(job.Status.Conditions, appsv1alpha1.EJobSucceeded, "JobSucceeded", "job success to run all tasks")
} else if job.Status.Running > 0 {
job.Status.Phase = appsv1alpha1.EphemeralJobRunning
} else if job.Status.Failed == *job.Spec.Replicas {
} else if job.Status.Failed == replicas {
job.Status.CompletionTime = timeNow()
job.Status.Phase = appsv1alpha1.EphemeralJobFailed
job.Status.Conditions = addConditions(job.Status.Conditions, appsv1alpha1.EJobFailed, "JobFailed", "job failed to run all tasks")
} else if job.Status.Waiting == *job.Spec.Replicas {
} else if job.Status.Waiting == replicas {
job.Status.Phase = appsv1alpha1.EphemeralJobWaiting
} else {
job.Status.Phase = appsv1alpha1.EphemeralJobUnknown
Expand Down