diff --git a/pkg/reconciler/v1alpha1/pipeline/resources/dag.go b/pkg/reconciler/v1alpha1/pipeline/dag/dag.go similarity index 97% rename from pkg/reconciler/v1alpha1/pipeline/resources/dag.go rename to pkg/reconciler/v1alpha1/pipeline/dag/dag.go index 766a1596fc7..cf06adc0759 100644 --- a/pkg/reconciler/v1alpha1/pipeline/resources/dag.go +++ b/pkg/reconciler/v1alpha1/pipeline/dag/dag.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package pipeline +package dag import ( "fmt" @@ -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) diff --git a/pkg/reconciler/v1alpha1/pipeline/resources/dag_test.go b/pkg/reconciler/v1alpha1/pipeline/dag/dag_test.go similarity index 98% rename from pkg/reconciler/v1alpha1/pipeline/resources/dag_test.go rename to pkg/reconciler/v1alpha1/pipeline/dag/dag_test.go index 3fbcef6ea66..b517bccf504 100644 --- a/pkg/reconciler/v1alpha1/pipeline/resources/dag_test.go +++ b/pkg/reconciler/v1alpha1/pipeline/dag/dag_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package pipeline +package dag import ( "testing" @@ -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) } @@ -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) } @@ -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) } @@ -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) } }) diff --git a/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go b/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go index 71f412f8185..78553d1ac3f 100644 --- a/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go @@ -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" @@ -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{