Skip to content

Commit

Permalink
dag: refactoring, take PipelineTask instead of the whole Pipeline ⛏
Browse files Browse the repository at this point in the history
… and rename the package from resources to dag

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester authored and knative-prow-robot committed Mar 6, 2019
1 parent 1f42004 commit 70c0c14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package pipeline
package dag

import (
"fmt"
Expand Down Expand Up @@ -193,17 +193,17 @@ func addLink(pt v1alpha1.PipelineTask, previousTask string, nodes map[string]*No
}

// Build returns a valid pipeline DAG. Returns error if the pipeline is invalid
func Build(p *v1alpha1.Pipeline) (*DAG, error) {
func Build(tasks []v1alpha1.PipelineTask) (*DAG, error) {
d := new()

// Add all Tasks mentioned in the `PipelineSpec`
for _, pt := range p.Spec.Tasks {
for _, pt := range tasks {
if _, err := d.addPipelineTask(pt); err != nil {
return nil, fmt.Errorf("task %s is already present in graph, can't add it again: %v", pt.Name, err)
}
}
// Process all from and runAfter constraints to add task dependency
for _, pt := range p.Spec.Tasks {
for _, pt := range tasks {
for _, previousTask := range pt.RunAfter {
if err := addLink(pt, previousTask, d.Nodes); err != nil {
return nil, fmt.Errorf("couldn't add link between %s and %s: %v", pt.Name, previousTask, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package pipeline
package dag

import (
"testing"
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestBuild_Parallel(t *testing.T) {
"c": {Task: c},
},
}
g, err := Build(p)
g, err := Build(p.Spec.Tasks)
if err != nil {
t.Fatalf("didn't expect error creating valid Pipeline %v but got %v", p, err)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestBuild_JoinMultipleRoots(t *testing.T) {
Tasks: []v1alpha1.PipelineTask{a, xDependsOnA, yDependsOnARunsAfterB, zDependsOnX, b, c},
},
}
g, err := Build(p)
g, err := Build(p.Spec.Tasks)
if err != nil {
t.Fatalf("didn't expect error creating valid Pipeline %v but got %v", p, err)
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestBuild_FanInFanOut(t *testing.T) {
Tasks: []v1alpha1.PipelineTask{a, dDependsOnA, eRunsAfterA, fDependsOnDAndE, gRunsAfterF},
},
}
g, err := Build(p)
g, err := Build(p.Spec.Tasks)
if err != nil {
t.Fatalf("didn't expect error creating valid Pipeline %v but got %v", p, err)
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestBuild_Invalid(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: tc.name},
Spec: tc.spec,
}
if _, err := Build(p); err == nil {
if _, err := Build(p.Spec.Tasks); err == nil {
t.Errorf("expected to see an error for invalid DAG in pipeline %v but had none", tc.spec)
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
informers "github.com/knative/build-pipeline/pkg/client/informers/externalversions/pipeline/v1alpha1"
listers "github.com/knative/build-pipeline/pkg/client/listers/pipeline/v1alpha1"
"github.com/knative/build-pipeline/pkg/reconciler"
dag "github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/pipeline/resources"
"github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/pipeline/dag"
"github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/pipelinerun/config"
"github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/pipelinerun/resources"
"github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/taskrun"
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er

p = p.DeepCopy()

d, err := dag.Build(p)
d, err := dag.Build(p.Spec.Tasks)
if err != nil {
// This Run has failed, so we need to mark it as failed and stop reconciling it
pr.Status.SetCondition(&duckv1alpha1.Condition{
Expand Down

0 comments on commit 70c0c14

Please sign in to comment.