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

refactor - dropping named return value from IsDone() functions #2870

Merged
merged 1 commit into from
Jun 29, 2020
Merged
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
dropping named return value from IsDone() function
  • Loading branch information
pritidesai committed Jun 26, 2020
commit 874a6236a773e76515dcd6def00f0d68f0f0c405
28 changes: 10 additions & 18 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@ type ResolvedPipelineRunTask struct {
// state of the PipelineRun.
type PipelineRunState []*ResolvedPipelineRunTask

func (t ResolvedPipelineRunTask) IsDone() (isDone bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻

func (t ResolvedPipelineRunTask) IsDone() bool {
if t.TaskRun == nil || t.PipelineTask == nil {
return
return false
}

status := t.TaskRun.Status.GetCondition(apis.ConditionSucceeded)
retriesDone := len(t.TaskRun.Status.RetriesStatus)
retries := t.PipelineTask.Retries
isDone = status.IsTrue() || status.IsFalse() && retriesDone >= retries
return
return status.IsTrue() || status.IsFalse() && retriesDone >= retries
}

// IsSuccessful returns true only if the taskrun itself has completed successfully
Expand Down Expand Up @@ -152,18 +151,13 @@ func (state PipelineRunState) ToMap() map[string]*ResolvedPipelineRunTask {

// IsDone returns true when all pipeline tasks have respective taskRun created and
// that taskRun has either succeeded or failed after all possible retry attempts
func (state PipelineRunState) IsDone() (isDone bool) {
isDone = true
func (state PipelineRunState) IsDone() bool {
for _, t := range state {
if t.TaskRun == nil || t.PipelineTask == nil {
if !t.IsDone() {
return false
}
isDone = isDone && t.IsDone()
if !isDone {
return
}
}
return
return true
}

// IsBeforeFirstTaskRun returns true if the PipelineRun has not yet started its first TaskRun
Expand Down Expand Up @@ -249,8 +243,7 @@ func (state PipelineRunState) isDAGTasksStopped(d *dag.Graph) bool {

// checkTasksDone returns true if all tasks from the specified graph are finished executing
// a task is considered done if it has failed/succeeded/skipped
func (state PipelineRunState) checkTasksDone(d *dag.Graph) (isDone bool) {
isDone = true
func (state PipelineRunState) checkTasksDone(d *dag.Graph) bool {
stateMap := state.ToMap()
for _, t := range state {
if _, ok := d.Nodes[t.PipelineTask.Name]; ok {
Expand All @@ -263,13 +256,12 @@ func (state PipelineRunState) checkTasksDone(d *dag.Graph) (isDone bool) {
}
return false
}
isDone = isDone && t.IsDone()
if !isDone {
return
if !t.IsDone() {
return false
}
}
}
return
return true
}

// GetFinalTasks returns a list of final tasks without any taskRun associated with it
Expand Down