Skip to content

Commit

Permalink
add updateConditionAndPhase comment
Browse files Browse the repository at this point in the history
  • Loading branch information
googs1025 committed Jun 7, 2024
1 parent 25396be commit 9e78074
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,13 @@ func setCondition(js *jobset.JobSet, condOpts *conditionOpts, updateStatusOpts *
enqueueEvent(updateStatusOpts, event)
}

// updateConditionAndPhase accepts a given condition and does one of the following:
// updateConditionAndPhase accepts a condition and a phase, and does the following:
// 1. If an identical condition already exists, do nothing and return false (indicating
// no change was made).
// 2. If a condition of the same type exists but with a different status, update
// the condition in place and return true (indicating a condition change was made).
// 3. If the specified phase is different from the current phase of the JobSet,
// update the JobSet Status Phase
func updateConditionAndPhase(js *jobset.JobSet, opts *conditionOpts) bool {
if opts == nil || opts.condition == nil {
return false
Expand Down Expand Up @@ -943,7 +945,7 @@ func updateConditionAndPhase(js *jobset.JobSet, opts *conditionOpts) bool {
shouldUpdate = true
}

// Update the JobSet phase if necessary.
// Update the JobSet Status Phase if necessary.
if opts.phase != "" && js.Status.Phase != opts.phase {
js.Status.Phase = opts.phase
shouldUpdate = true
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/jobset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func TestUpdateConditions(t *testing.T) {
ReplicatedJob(testutils.MakeReplicatedJob(replicatedJobName).
Job(testutils.MakeJobTemplate(jobName, ns).Obj()).
Replicas(1).
Obj()).Obj(),
Obj()).Phase(jobset.JobSetRunning).Obj(),
opts: makeCompletedConditionsOpts(),
expectedUpdate: true,
},
Expand All @@ -706,7 +706,7 @@ func TestUpdateConditions(t *testing.T) {
ReplicatedJob(testutils.MakeReplicatedJob(replicatedJobName).
Job(testutils.MakeJobTemplate(jobName, ns).Obj()).
Replicas(1).
Obj()).Obj(),
Obj()).Phase(jobset.JobSetRunning).Obj(),
opts: makeSuspendedConditionOpts(),
expectedUpdate: true,
},
Expand All @@ -716,7 +716,7 @@ func TestUpdateConditions(t *testing.T) {
ReplicatedJob(testutils.MakeReplicatedJob(replicatedJobName).
Job(testutils.MakeJobTemplate(jobName, ns).Obj()).
Replicas(1).
Obj()).
Obj()).Phase(jobset.JobSetRunning).
Conditions([]metav1.Condition{
// JobSet is currrently suspended.
{
Expand All @@ -736,7 +736,7 @@ func TestUpdateConditions(t *testing.T) {
ReplicatedJob(testutils.MakeReplicatedJob(replicatedJobName).
Job(testutils.MakeJobTemplate(jobName, ns).Obj()).
Replicas(1).
Obj()).Phase(string(jobset.JobSetCompleted)).
Obj()).Phase(jobset.JobSetCompleted).
Conditions([]metav1.Condition{
// JobSet is completed..
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (j *JobSetWrapper) FailedCondition(failedAt metav1.Time) *JobSetWrapper {
}

// Phase sets the value of JobSet.Status.Phase.
func (j *JobSetWrapper) Phase(phase string) *JobSetWrapper {
j.Status.Phase = phase
func (j *JobSetWrapper) Phase(phase jobset.JobSetConditionType) *JobSetWrapper {
j.Status.Phase = string(phase)
return j
}

Expand Down

0 comments on commit 9e78074

Please sign in to comment.