From 1df61abb32c143c5f9f7c9573356534bd0692bc9 Mon Sep 17 00:00:00 2001 From: vinamra28 Date: Wed, 31 Aug 2022 13:56:03 +0530 Subject: [PATCH] Remove PipelineRun v1alpha1 support Signed-off-by: vinamra28 --- pkg/cmd/pipelinerun/cancel.go | 2 +- pkg/cmd/pipelinerun/cancel_test.go | 433 +---- pkg/cmd/pipelinerun/delete_test.go | 538 ------ pkg/cmd/pipelinerun/describe_test.go | 515 ++---- pkg/cmd/pipelinerun/list_test.go | 261 +-- pkg/cmd/pipelinerun/logs_test.go | 1606 ++--------------- ...tListPipelineRuns-Invalid_namespace.golden | 1 - ...stListPipelineRuns-all_in_namespace.golden | 6 - ...tListPipelineRuns-by_output_as_name.golden | 5 - ...stListPipelineRuns-by_pipeline_name.golden | 2 - .../TestListPipelineRuns-by_template.golden | 5 - ...neRuns-filter_pipelineruns_by_label.golden | 2 - ...pipelineruns_by_label_with_in_query.golden | 3 - ...elineruns_greater_than_maximum_case.golden | 6 - ...ns-limit_pipelineruns_negative_case.golden | 1 - ...ns-limit_pipelineruns_returned_to_1.golden | 2 - ...t_pipelineruns_with_output_flag_set.golden | 2 - ...ns-no_mixing_pipelinename_and_label.golden | 1 - ...stListPipelineRuns-print_in_reverse.golden | 6 - ...s-print_in_reverse_with_output_flag.golden | 5 - ...rint_pipelineruns_in_all_namespaces.golden | 3 - .../TestPipelineRunDescribe_last.golden | 17 - pkg/log/pipeline_reader.go | 4 +- pkg/pipelinerun/pipelinerun.go | 50 +- pkg/pipelinerun/pipelinerun_test.go | 233 --- pkg/pipelinerun/tracker.go | 32 +- 26 files changed, 334 insertions(+), 3407 deletions(-) delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-Invalid_namespace.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-all_in_namespace.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_output_as_name.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_pipeline_name.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_template.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label_with_in_query.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_greater_than_maximum_case.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_negative_case.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_returned_to_1.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_with_output_flag_set.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-no_mixing_pipelinename_and_label.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse_with_output_flag.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_pipelineruns_in_all_namespaces.golden delete mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden diff --git a/pkg/cmd/pipelinerun/cancel.go b/pkg/cmd/pipelinerun/cancel.go index 47dd9d112a..308e26807f 100644 --- a/pkg/cmd/pipelinerun/cancel.go +++ b/pkg/cmd/pipelinerun/cancel.go @@ -74,7 +74,7 @@ func cancelPipelineRun(p cli.Params, s *cli.Stream, prName string, graceCancelSt return fmt.Errorf("failed to create tekton client") } - pr, err := pipelinerun.GetV1beta1(cs, prName, metav1.GetOptions{}, p.Namespace()) + pr, err := pipelinerun.Get(cs, prName, metav1.GetOptions{}, p.Namespace()) if err != nil { return fmt.Errorf("failed to find PipelineRun: %s", prName) } diff --git a/pkg/cmd/pipelinerun/cancel_test.go b/pkg/cmd/pipelinerun/cancel_test.go index 8f085bf64b..d3c99d335d 100644 --- a/pkg/cmd/pipelinerun/cancel_test.go +++ b/pkg/cmd/pipelinerun/cancel_test.go @@ -22,10 +22,8 @@ import ( tu "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" pipelinev1beta1test "github.com/tektoncd/pipeline/test" - pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -34,12 +32,6 @@ import ( duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) -var ( - success = apis.Condition{Type: apis.ConditionSucceeded, Status: corev1.ConditionTrue} - failure = apis.Condition{Type: apis.ConditionSucceeded, Status: corev1.ConditionFalse} - cancel = apis.Condition{Status: corev1.ConditionFalse, Reason: "PipelineRunCancelled"} -) - func Test_cancel_invalid_namespace(t *testing.T) { ns := []*corev1.Namespace{ { @@ -51,7 +43,7 @@ func Test_cancel_invalid_namespace(t *testing.T) { prName := "test-pipeline-run-123" - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube} pRun := Command(p) @@ -61,91 +53,6 @@ func Test_cancel_invalid_namespace(t *testing.T) { tu.AssertOutput(t, expected, got) } -func Test_cancel_pipelinerun(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - prName := "test-pipeline-run-123" - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipelineName", - }, - ServiceAccountName: "test-sa", - Resources: []v1alpha1.PipelineResourceBinding{ - { - Name: "git-repo", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "some-repo", - }, - }, - { - Name: "build-image", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "some-image", - }, - }, - }, - Params: []v1alpha1.Param{ - { - Name: "pipeline-param-1", - Value: v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, - StringVal: "somethingmorefun", - }, - }, - { - Name: "somethingmorefun", - Value: v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, - StringVal: "revision1", - }, - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Type: apis.ConditionReady, - }, - }, - }, - }, - }, - } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - pRun := Command(p) - got, _ := tu.ExecuteCommand(pRun, "cancel", prName, "-n", "ns") - - expected := "PipelineRun cancelled: " + prName + "\n" - tu.AssertOutput(t, expected, got) -} - func Test_cancel_pipelinerun_not_found(t *testing.T) { ns := []*corev1.Namespace{ { @@ -157,7 +64,7 @@ func Test_cancel_pipelinerun_not_found(t *testing.T) { prName := "test-pipeline-run-123" - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube} pRun := Command(p) @@ -167,336 +74,6 @@ func Test_cancel_pipelinerun_not_found(t *testing.T) { tu.AssertOutput(t, expected, got) } -func Test_cancel_pipelinerun_client_err(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - prName := "test-pipeline-run-123" - errStr := "test generated error" - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipelineName", - }, - ServiceAccountName: "test-sa", - Resources: []v1beta1.PipelineResourceBinding{ - { - Name: "git-repo", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-repo", - }, - }, - { - Name: "build-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-image", - }, - }, - }, - Params: []v1beta1.Param{ - { - Name: "pipeline-param-1", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "somethingmorefun", - }, - }, - { - Name: "rev-param", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "revision1", - }, - }, - }, - }, - }, - } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{ - PrependReactors: []testDynamic.PrependOpt{ - { - Verb: "patch", - Resource: "pipelineruns", - Action: func(action k8stest.Action) (bool, runtime.Object, error) { - return true, nil, errors.New(errStr) - }}}} - dc, err := tdc.Client( - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - pRun := Command(p) - got, _ := tu.ExecuteCommand(pRun, "cancel", prName, "-n", "ns") - - expected := "Error: failed to cancel PipelineRun: " + prName + ": " + errStr + "\n" - tu.AssertOutput(t, expected, got) -} - -func Test_finished_pipelinerun_success(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - prName := "test-pipeline-run-123" - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipelineName", - }, - ServiceAccountName: "test-sa", - Resources: []v1beta1.PipelineResourceBinding{ - { - Name: "git-repo", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-repo", - }, - }, - { - Name: "build-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-image", - }, - }, - }, - Params: []v1beta1.Param{ - { - Name: "pipeline-param-1", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "somethingmorefun", - }, - }, - { - Name: "rev-param", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "revision1", - }, - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - success, - }, - }, - }, - }, - } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - pRun := Command(p) - got, _ := tu.ExecuteCommand(pRun, "cancel", prName, "-n", "ns") - - expected := "Error: failed to cancel PipelineRun " + prName + ": PipelineRun has already finished execution\n" - tu.AssertOutput(t, expected, got) -} - -func Test_finished_pipelinerun_failure(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - prName := "test-pipeline-run-123" - - prs := []*v1alpha1.PipelineRun{ - - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipelineName", - }, - ServiceAccountName: "test-sa", - Resources: []v1beta1.PipelineResourceBinding{ - { - Name: "git-repo", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-repo", - }, - }, - { - Name: "build-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-image", - }, - }, - }, - Params: []v1beta1.Param{ - { - Name: "pipeline-param-1", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "somethingmorefun", - }, - }, - { - Name: "rev-param", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "revision1", - }, - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - failure, - }, - }, - }, - }, - } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - pRun := Command(p) - got, _ := tu.ExecuteCommand(pRun, "cancel", prName, "-n", "ns") - - expected := "Error: failed to cancel PipelineRun " + prName + ": PipelineRun has already finished execution\n" - tu.AssertOutput(t, expected, got) -} - -func Test_finished_pipelinerun_cancel(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - prName := "test-pipeline-run-123" - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipelineName", - }, - ServiceAccountName: "test-sa", - Resources: []v1beta1.PipelineResourceBinding{ - { - Name: "git-repo", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-repo", - }, - }, - { - Name: "build-image", - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "some-image", - }, - }, - }, - Params: []v1beta1.Param{ - { - Name: "pipeline-param-1", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "somethingmorefun", - }, - }, - { - Name: "rev-param", - Value: v1beta1.ArrayOrString{ - Type: v1beta1.ParamTypeString, - StringVal: "revision1", - }, - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - cancel, - }, - }, - }, - }, - } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := &tu.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - - pRun := Command(p) - got, _ := tu.ExecuteCommand(pRun, "cancel", prName, "-n", "ns") - - expected := "Error: failed to cancel PipelineRun " + prName + ": PipelineRun has already finished execution\n" - tu.AssertOutput(t, expected, got) -} - func Test_cancel_pipelinerun_v1beta1(t *testing.T) { ns := []*corev1.Namespace{ { @@ -551,7 +128,7 @@ func Test_cancel_pipelinerun_v1beta1(t *testing.T) { }, }, }, - Status: v1alpha1.PipelineRunStatus{ + Status: v1beta1.PipelineRunStatus{ Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { @@ -1144,7 +721,7 @@ func Test_cancel_pipelinerun_with_grace_stopped(t *testing.T) { }, }, }, - Status: v1alpha1.PipelineRunStatus{ + Status: v1beta1.PipelineRunStatus{ Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { @@ -1229,7 +806,7 @@ func Test_cancel_pipelinerun_with_grace_cancelled(t *testing.T) { }, }, }, - Status: v1alpha1.PipelineRunStatus{ + Status: v1beta1.PipelineRunStatus{ Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { diff --git a/pkg/cmd/pipelinerun/delete_test.go b/pkg/cmd/pipelinerun/delete_test.go index 27f9076342..a1220cb268 100644 --- a/pkg/cmd/pipelinerun/delete_test.go +++ b/pkg/cmd/pipelinerun/delete_test.go @@ -24,10 +24,8 @@ import ( "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" pipelinev1beta1test "github.com/tektoncd/pipeline/test" - pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/dynamic" @@ -35,542 +33,6 @@ import ( ) func TestPipelineRunDelete(t *testing.T) { - version := "v1alpha1" - clock := clockwork.NewFakeClock() - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - pdata := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline", - Namespace: "ns", - // created 5 minutes back - CreationTimestamp: metav1.Time{Time: clock.Now().Add(-5 * time.Minute)}, - }, - }, - } - - prdata := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run-1", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clock.Now()}, - Labels: map[string]string{"tekton.dev/pipeline": "pipeline", "iam": "tobedeleted"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - // pipeline run starts now - StartTime: &metav1.Time{Time: clock.Now()}, - // takes 10 minutes to complete - CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run-2", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clock.Now()}, - Labels: map[string]string{"tekton.dev/pipeline": "pipeline", "iam": "tobedeleted"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - // pipeline run starts now - StartTime: &metav1.Time{Time: clock.Now()}, - // takes 10 minutes to complete - CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run-3", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clock.Now()}, - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - // pipeline run starts now - StartTime: &metav1.Time{Time: clock.Now()}, - // takes 10 minutes to complete - CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run-realnow", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clock.Now()}, - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - // pipeline run starts now - StartTime: &metav1.Time{Time: time.Now()}, - // takes 60 minutes to complete - CompletionTime: &metav1.Time{Time: time.Now().Add(60 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run-4", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clock.Now()}, - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonPending.String(), - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run-5", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clock.Now()}, - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - // pipeline run starts now - StartTime: &metav1.Time{Time: time.Now()}, - }, - }, - }, - } - - type clients struct { - pipelineClient pipelinetest.Clients - dynamicClient dynamic.Interface - } - - seeds := make([]clients, 0) - for i := 0; i < 13; i++ { - cs, _ := test.SeedTestData(t, pipelinetest.Data{ - Pipelines: pdata, - PipelineRuns: prdata, - Namespaces: ns, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prdata[0], version), - cb.UnstructuredPR(prdata[1], version), - cb.UnstructuredPR(prdata[2], version), - cb.UnstructuredPR(prdata[3], version), - cb.UnstructuredPR(prdata[4], version), - cb.UnstructuredPR(prdata[5], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - seeds = append(seeds, clients{cs, dc}) - } - - testParams := []struct { - name string - command []string - dynamic dynamic.Interface - input pipelinetest.Clients - inputStream io.Reader - wantError bool - want string - }{ - { - name: "Invalid namespace", - command: []string{"rm", "pipeline-run-1", "-n", "invalid"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: true, - want: "pipelineruns.tekton.dev \"pipeline-run-1\" not found", - }, - { - name: "With force delete flag (shorthand)", - command: []string{"rm", "pipeline-run-1", "-n", "ns", "-f"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: nil, - wantError: false, - want: "PipelineRuns deleted: \"pipeline-run-1\"\n", - }, - { - name: "With force delete flag", - command: []string{"rm", "pipeline-run-1", "-n", "ns", "--force"}, - dynamic: seeds[1].dynamicClient, - input: seeds[1].pipelineClient, - inputStream: nil, - wantError: false, - want: "PipelineRuns deleted: \"pipeline-run-1\"\n", - }, - { - name: "Without force delete flag, reply no", - command: []string{"rm", "pipeline-run-1", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: strings.NewReader("n"), - wantError: true, - want: "canceled deleting PipelineRun(s) \"pipeline-run-1\"", - }, - { - name: "Without force delete flag, reply yes", - command: []string{"rm", "pipeline-run-1", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Are you sure you want to delete PipelineRun(s) \"pipeline-run-1\" (y/n): PipelineRuns deleted: \"pipeline-run-1\"\n", - }, - { - name: "Remove non existent resource", - command: []string{"rm", "nonexistent", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "pipelineruns.tekton.dev \"nonexistent\" not found", - }, - { - name: "Remove multiple non existent resources", - command: []string{"rm", "nonexistent", "nonexistent2", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "pipelineruns.tekton.dev \"nonexistent\" not found; pipelineruns.tekton.dev \"nonexistent2\" not found", - }, - { - name: "Attempt remove forgetting to include pipelinerun names", - command: []string{"rm", "-n", "ns"}, - dynamic: seeds[2].dynamicClient, - input: seeds[2].pipelineClient, - inputStream: nil, - wantError: true, - want: "must provide PipelineRun name(s) or use --pipeline flag or --all flag to use delete", - }, - { - name: "Remove pipelineruns of a pipeline", - command: []string{"rm", "--pipeline", "pipeline", "-n", "ns"}, - dynamic: seeds[0].dynamicClient, - input: seeds[0].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Are you sure you want to delete all PipelineRuns related to Pipeline \"pipeline\" (y/n): All PipelineRuns(Completed) associated with Pipeline \"pipeline\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all with prompt", - command: []string{"delete", "--all", "-n", "ns"}, - dynamic: seeds[3].dynamicClient, - input: seeds[3].pipelineClient, - inputStream: strings.NewReader("y"), - wantError: false, - want: "Are you sure you want to delete all PipelineRuns in namespace \"ns\" (y/n): All PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Delete all with -f", - command: []string{"delete", "--all", "-f", "-n", "ns"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: false, - want: "All PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Delete all keeping 2", - command: []string{"delete", "-f", "--keep", "2", "-n", "ns"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: false, - want: "All but 2 PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Keep -1 is a no go", - command: []string{"delete", "-f", "--keep", "-1", "-n", "ns"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: true, - want: "keep option should not be lower than 0", - }, - { - name: "Delete all keeping 1 with --all flag", - command: []string{"delete", "-f", "--all", "--keep", "1", "-n", "ns"}, - dynamic: seeds[4].dynamicClient, - input: seeds[4].pipelineClient, - inputStream: nil, - wantError: false, - want: "All but 1 PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Error from using pipelinerun name with --all", - command: []string{"delete", "pipeline-run-1", "--all", "-n", "ns"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "--all flag should not have any arguments or flags specified with it", - }, - { - name: "Error from deleting PipelineRun with non-existing Pipeline", - command: []string{"delete", "pipeline-run-1", "-p", "non-existing-pipeline", "-n", "ns"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: true, - want: "no PipelineRuns associated with Pipeline \"non-existing-pipeline\"", - }, - { - name: "Remove pipelineruns of a pipeline using --keep", - command: []string{"rm", "--pipeline", "pipeline", "-n", "ns", "--keep", "2"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns related to Pipeline \"pipeline\" keeping 2 PipelineRuns (y/n): All but 2 PipelineRuns(Completed) associated with Pipeline \"pipeline\" deleted in namespace \"ns\"\n", - }, - { - name: "Error from using argument with --keep", - command: []string{"rm", "pipeline-run-1", "--keep", "2", "-n", "ns"}, - dynamic: seeds[6].dynamicClient, - input: seeds[6].pipelineClient, - inputStream: nil, - wantError: true, - want: "--keep flag should not have any arguments specified with it", - }, - { - name: "Delete all PipelineRuns older than 60mn", - command: []string{"delete", "-f", "--all", "--keep-since", "60", "-n", "ns"}, - dynamic: seeds[7].dynamicClient, - input: seeds[7].pipelineClient, - inputStream: nil, - wantError: false, - want: "3 expired PipelineRuns(Completed) has been deleted in namespace \"ns\", kept 1\n", - }, - { - name: "Delete all by labels", - command: []string{"rm", "--all", "-n", "ns", "--label", "iam=tobedeleted"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns in namespace \"ns\" (y/n): All PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Delete all by default ignore-running", - command: []string{"rm", "--all", "-n", "ns"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns in namespace \"ns\" (y/n): All PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Delete all by explicit ignore-running true", - command: []string{"rm", "--all", "-n", "ns", "--ignore-running=true"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns in namespace \"ns\" (y/n): All PipelineRuns(Completed) deleted in namespace \"ns\"\n", - }, - { - name: "Delete all by ignore-running false", - command: []string{"rm", "--all", "-n", "ns", "--ignore-running=false"}, - dynamic: seeds[5].dynamicClient, - input: seeds[5].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns in namespace \"ns\" (y/n): All PipelineRuns deleted in namespace \"ns\"\n", - }, - { - name: "Delete all PipelineRuns older than 60mn associated with Pipeline pipeline", - command: []string{"delete", "-f", "--pipeline", "pipeline", "--keep-since", "60", "-n", "ns"}, - dynamic: seeds[8].dynamicClient, - input: seeds[8].pipelineClient, - inputStream: nil, - wantError: false, - want: "All but 3 expired PipelineRuns(Completed) associated with Pipeline \"pipeline\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all PipelineRuns older than 60mn 0 expired", - command: []string{"delete", "-f", "--keep-since", "60", "--all", "-n", "ns"}, - dynamic: seeds[8].dynamicClient, - input: seeds[8].pipelineClient, - inputStream: nil, - wantError: false, - want: "0 expired PipelineRuns(Completed) has been deleted in namespace \"ns\", kept 1\n", - }, - { - name: "Error --keep-since less than zero", - command: []string{"delete", "-f", "--keep-since", "-1", "-n", "ns"}, - dynamic: seeds[7].dynamicClient, - input: seeds[7].pipelineClient, - inputStream: nil, - wantError: true, - want: "keep-since option should not be lower than 0", - }, - { - name: "Error --keep-since, --all and --task cannot be used", - command: []string{"delete", "-f", "--keep-since", "1", "--all", "-p", "foobar", "-n", "ns"}, - dynamic: seeds[7].dynamicClient, - input: seeds[7].pipelineClient, - inputStream: nil, - wantError: true, - want: "--keep or --keep-since, --all and --pipeline cannot be used together", - }, - { - name: "Delete the PipelineRun present and give error for non-existent PipelineRun", - command: []string{"delete", "nonexistent", "pipeline-run-1", "-n", "ns"}, - dynamic: seeds[9].dynamicClient, - input: seeds[9].pipelineClient, - inputStream: nil, - wantError: true, - want: "pipelineruns.tekton.dev \"nonexistent\" not found", - }, - { - name: "Delete all of a pipeline by default ignore-running", - command: []string{"rm", "-p", "pipeline", "-n", "ns"}, - dynamic: seeds[10].dynamicClient, - input: seeds[10].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns related to Pipeline \"pipeline\" (y/n): All PipelineRuns(Completed) associated with Pipeline \"pipeline\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all of a pipeline by explicit ignore-running true", - command: []string{"rm", "-p", "pipeline", "-n", "ns", "--ignore-running=true"}, - dynamic: seeds[11].dynamicClient, - input: seeds[11].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns related to Pipeline \"pipeline\" (y/n): All PipelineRuns(Completed) associated with Pipeline \"pipeline\" deleted in namespace \"ns\"\n", - }, - { - name: "Delete all of a pipeline by ignore-running false", - command: []string{"rm", "-p", "pipeline", "-n", "ns", "--ignore-running=false"}, - dynamic: seeds[12].dynamicClient, - input: seeds[12].pipelineClient, - inputStream: nil, - wantError: false, - want: "Are you sure you want to delete all PipelineRuns related to Pipeline \"pipeline\" (y/n): All PipelineRuns associated with Pipeline \"pipeline\" deleted in namespace \"ns\"\n", - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - p := &test.Params{Tekton: tp.input.Pipeline, Kube: tp.input.Kube, Dynamic: tp.dynamic} - pipelinerun := Command(p) - - if tp.inputStream != nil { - pipelinerun.SetIn(tp.inputStream) - } - - out, err := test.ExecuteCommand(pipelinerun, tp.command...) - if tp.wantError { - if err == nil { - t.Errorf("error expected here") - } else { - test.AssertOutput(t, tp.want, err.Error()) - } - } else { - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, tp.want, out) - } - }) - } -} - -func TestPipelineRunDelete_v1beta1(t *testing.T) { version := "v1beta1" clock := clockwork.NewFakeClock() diff --git a/pkg/cmd/pipelinerun/describe_test.go b/pkg/cmd/pipelinerun/describe_test.go index 11efb5b3ae..241bcc80f6 100644 --- a/pkg/cmd/pipelinerun/describe_test.go +++ b/pkg/cmd/pipelinerun/describe_test.go @@ -24,10 +24,8 @@ import ( "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" pipelinev1beta1test "github.com/tektoncd/pipeline/test" - pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" "gotest.tools/v3/golden" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -45,7 +43,7 @@ func TestPipelineRunDescribe_invalid_namespace(t *testing.T) { }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube} pipelinerun := Command(p) @@ -66,8 +64,8 @@ func TestPipelineRunDescribe_not_found(t *testing.T) { }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList("v1alpha1", []string{"pipelinerun"}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) + cs.Pipeline.Resources = cb.APIResourceList("v1beta1", []string{"pipelinerun"}) tdc := testDynamic.Options{} dynamic, err := tdc.Client() if err != nil { @@ -87,7 +85,7 @@ func TestPipelineRunDescribe_not_found(t *testing.T) { func TestPipelineRunDescribe_only_taskrun(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -110,7 +108,7 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -118,15 +116,15 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -152,16 +150,16 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -179,7 +177,7 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -222,7 +220,7 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -230,15 +228,15 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, "tr-2": {PipelineTaskName: "t-2", Status: &trs[1].Status}, }, @@ -265,17 +263,17 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), - cb.UnstructuredTR(trs[1], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), + cb.UnstructuredV1beta1TR(trs[1], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -294,7 +292,7 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -317,7 +315,7 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -325,15 +323,15 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-0": {PipelineTaskName: "t-0"}, "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, @@ -360,16 +358,16 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -387,7 +385,7 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { func TestPipelineRunDescribe_failed(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -411,7 +409,7 @@ func TestPipelineRunDescribe_failed(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -419,16 +417,16 @@ func TestPipelineRunDescribe_failed(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, ServiceAccountName: "test-sa", }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -455,16 +453,16 @@ func TestPipelineRunDescribe_failed(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -512,7 +510,7 @@ func TestPipelineRunDescribe_last_no_PipelineRun_present(t *testing.T) { func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -527,7 +525,7 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -535,16 +533,16 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, ServiceAccountName: "test-sa", }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -571,16 +569,16 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -598,7 +596,7 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -613,7 +611,7 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -621,16 +619,16 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, ServiceAccountName: "test-sa", }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -648,16 +646,16 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -675,7 +673,7 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -698,7 +696,7 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -706,13 +704,13 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, ServiceAccountName: "test-sa", - Resources: []v1alpha1.PipelineResourceBinding{ + Resources: []v1beta1.PipelineResourceBinding{ { Name: "test-resource", ResourceRef: &v1beta1.PipelineResourceRef{ @@ -720,19 +718,19 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { }, }, }, - Params: []v1alpha1.Param{ + Params: []v1beta1.Param{ { Name: "test-param", - Value: v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, StringVal: "param-value", }, }, }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -758,16 +756,16 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -785,7 +783,7 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { func TestPipelineRunDescribe_without_start_time(t *testing.T) { clock := clockwork.NewFakeClock() - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -793,9 +791,9 @@ func TestPipelineRunDescribe_without_start_time(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, @@ -810,15 +808,15 @@ func TestPipelineRunDescribe_without_start_time(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} @@ -834,7 +832,7 @@ func TestPipelineRunDescribe_without_start_time(t *testing.T) { func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { clock := clockwork.NewFakeClock() - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -853,15 +851,15 @@ func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} @@ -877,7 +875,7 @@ func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T) { clock := clockwork.NewFakeClock() - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -896,15 +894,15 @@ func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} p.SetNamespace("ns") @@ -920,7 +918,7 @@ func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T func TestPipelineRunDescribe_no_resourceref(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -943,7 +941,7 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -951,30 +949,30 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, ServiceAccountName: "test-sa", - Resources: []v1alpha1.PipelineResourceBinding{ + Resources: []v1beta1.PipelineResourceBinding{ { Name: "test-resource", }, }, - Params: []v1alpha1.Param{ + Params: []v1beta1.Param{ { Name: "test-param", - Value: v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, StringVal: "param-value", }, }, }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -1000,16 +998,16 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -1027,7 +1025,7 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -1050,7 +1048,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -1058,15 +1056,15 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -1093,16 +1091,16 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -1120,7 +1118,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { clock := clockwork.NewFakeClock() - trs := []*v1alpha1.TaskRun{ + trs := []*v1beta1.TaskRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "tr-1", @@ -1139,7 +1137,7 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { }, } - pipelineRuns := []*v1alpha1.PipelineRun{ + pipelineRuns := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", @@ -1147,15 +1145,15 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1alpha1.PipelineRef{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + Status: v1beta1.PipelineRunStatus{ + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, }, StartTime: &metav1.Time{Time: clock.Now()}, @@ -1180,16 +1178,16 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredTR(trs[0], version), + cb.UnstructuredV1beta1PR(pipelineRuns[0], version), + cb.UnstructuredV1beta1TR(trs[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -1205,14 +1203,14 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { } func TestPipelineRunDescribe_custom_timeout(t *testing.T) { - prun := []*v1alpha1.PipelineRun{ + prun := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pr-custom-timeout", Namespace: "ns", }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ + Spec: v1beta1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pr-custom-timeout", }, Timeout: &metav1.Duration{ @@ -1230,15 +1228,15 @@ func TestPipelineRunDescribe_custom_timeout(t *testing.T) { }, } - version := "v1alpha1" + version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(prun[0], version), + cb.UnstructuredV1beta1PR(prun[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1250,49 +1248,6 @@ func TestPipelineRunDescribe_custom_timeout(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunsDescribe_custom_output(t *testing.T) { - pipelinerunname := "pipeline-run" - expected := "pipelinerun.tekton.dev/" + pipelinerunname - - prun := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelinerunname, - Namespace: "ns", - }, - }, - } - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - version := "v1alpha1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredPR(prun[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - - pipelinerun := Command(p) - got, err := test.ExecuteCommand(pipelinerun, "desc", "-o", "name", "-n", "ns", pipelinerunname) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - got = strings.TrimSpace(got) - if got != expected { - t.Errorf("Result should be '%s' != '%s'", got, expected) - } -} - func TestPipelineRunDescribeV1beta1_custom_output(t *testing.T) { pipelinerunname := "pipeline-run" expected := "pipelinerun.tekton.dev/" + pipelinerunname @@ -1859,184 +1814,6 @@ func TestPipelineRunDescribe_lastV1beta1(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_last(t *testing.T) { - clock := clockwork.NewFakeClock() - - trs := []*v1alpha1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-1", - Namespace: "ns", - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Type: apis.ConditionSucceeded, - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-2", - Namespace: "ns", - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Type: apis.ConditionSucceeded, - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(9 * time.Minute)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-3", - Namespace: "ns", - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Type: apis.ConditionSucceeded, - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(9 * time.Minute)}, - }, - }, - }, - } - - pipelineRuns := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }, - "tr-2": { - PipelineTaskName: "t-2", - Status: &trs[1].Status, - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipeline-run2", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: clock.Now()}, - CompletionTime: &metav1.Time{Time: clock.Now().Add(15 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }, - "tr-3": { - PipelineTaskName: "t-3", - Status: &trs[1].Status, - }, - }, - }, - }, - }, - } - - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - version := "v1alpha1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredPR(pipelineRuns[0], version), - cb.UnstructuredPR(pipelineRuns[1], version), - cb.UnstructuredTR(trs[0], version), - cb.UnstructuredTR(trs[1], version), - cb.UnstructuredTR(trs[2], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, - TaskRuns: trs, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} - - pipelinerun := Command(p) - clock.Advance(10 * time.Minute) - actual, err := test.ExecuteCommand(pipelinerun, "desc", "--last", "-n", "ns") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) - -} - func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" @@ -2161,13 +1938,13 @@ func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { } func TestPipelineRunDescribe_zero_timeout(t *testing.T) { - prun := []*v1alpha1.PipelineRun{ + prun := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run-zero-timeout", Namespace: "ns", }, - Spec: v1alpha1.PipelineRunSpec{ + Spec: v1beta1.PipelineRunSpec{ PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline-zero-timeout", }, @@ -2189,13 +1966,13 @@ func TestPipelineRunDescribe_zero_timeout(t *testing.T) { version := "v1beta1" tdc := testDynamic.Options{} dynamic, err := tdc.Client( - cb.UnstructuredPR(prun[0], version), + cb.UnstructuredV1beta1PR(prun[0], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} diff --git a/pkg/cmd/pipelinerun/list_test.go b/pkg/cmd/pipelinerun/list_test.go index f26e612045..ab06f16ee3 100644 --- a/pkg/cmd/pipelinerun/list_test.go +++ b/pkg/cmd/pipelinerun/list_test.go @@ -25,10 +25,8 @@ import ( "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" pipelinev1beta1test "github.com/tektoncd/pipeline/test" - pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" "gotest.tools/v3/golden" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,250 +34,6 @@ import ( duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) -func TestListPipelineRuns(t *testing.T) { - version := "v1alpha1" - clock := clockwork.NewFakeClock() - runDuration := 1 * time.Minute - - pr1Started := clock.Now().Add(10 * time.Second) - pr2Started := clock.Now().Add(-2 * time.Hour) - pr3Started := clock.Now().Add(-1 * time.Hour) - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr0-1", - Namespace: "namespace", - Labels: map[string]string{"tekton.dev/pipeline": "random"}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr1-1", - Namespace: "namespace", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr1Started}, - CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr2-1", - Namespace: "namespace", - Labels: map[string]string{"tekton.dev/pipeline": "random"}, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr2Started}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr2-2", - Namespace: "namespace", - Labels: map[string]string{"tekton.dev/pipeline": "random", "viva": "galapagos"}, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionFalse, - Reason: v1beta1.PipelineRunReasonFailed.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr3Started}, - CompletionTime: &metav1.Time{Time: pr3Started.Add(runDuration)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr3-1", - Namespace: "namespace", - Labels: map[string]string{"tekton.dev/pipeline": "random", "viva": "wakanda"}, - }, - }, - } - - prsMultipleNs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr4-1", - Namespace: "namespace-tout", - Labels: map[string]string{"tekton.dev/pipeline": "random"}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pr4-2", - Namespace: "namespace-lacher", - Labels: map[string]string{"tekton.dev/pipeline": "random"}, - }, - }, - } - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - } - - tdc1 := testDynamic.Options{} - dc1, err := tdc1.Client( - cb.UnstructuredPR(prs[0], version), - cb.UnstructuredPR(prs[1], version), - cb.UnstructuredPR(prs[2], version), - cb.UnstructuredPR(prs[3], version), - cb.UnstructuredPR(prs[4], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - tdc2 := testDynamic.Options{} - dc2, err := tdc2.Client( - cb.UnstructuredPR(prsMultipleNs[0], version), - cb.UnstructuredPR(prsMultipleNs[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - tests := []struct { - name string - command *cobra.Command - args []string - wantError bool - }{ - { - name: "Invalid namespace", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "invalid"}, - wantError: true, - }, - { - name: "by pipeline name", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "pipeline", "-n", "namespace"}, - wantError: false, - }, - { - name: "by output as name", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "-o", "name"}, - wantError: false, - }, - { - name: "all in namespace", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace"}, - wantError: false, - }, - { - name: "by template", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "-o", "jsonpath={range .items[*]}{.metadata.name}{\"\\n\"}{end}"}, - wantError: false, - }, - { - name: "limit pipelineruns returned to 1", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "--limit", fmt.Sprintf("%d", 1)}, - wantError: false, - }, - { - name: "limit pipelineruns negative case", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "--limit", fmt.Sprintf("%d", -1)}, - wantError: true, - }, - { - name: "filter pipelineruns by label with in query", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "--label", "viva in (wakanda,galapagos)"}, - wantError: false, - }, - { - name: "filter pipelineruns by label", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "--label", "viva=wakanda"}, - wantError: false, - }, - { - name: "no mixing pipelinename and label", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "--label", "viva=wakanda", "pr3-1"}, - wantError: true, - }, - - { - name: "limit pipelineruns greater than maximum case", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "--limit", fmt.Sprintf("%d", 7)}, - wantError: false, - }, - { - name: "limit pipelineruns with output flag set", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "-n", "namespace", "-o", "jsonpath={range .items[*]}{.metadata.name}{\"\\n\"}{end}", "--limit", fmt.Sprintf("%d", 2)}, - wantError: false, - }, - { - name: "print in reverse", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "--reverse", "-n", "namespace"}, - wantError: false, - }, - { - name: "print in reverse with output flag", - command: commandV1alpha1(t, prs, clock.Now(), ns, version, dc1), - args: []string{"list", "--reverse", "-n", "namespace", "-o", "jsonpath={range .items[*]}{.metadata.name}{\"\\n\"}{end}"}, - wantError: false, - }, - { - name: "print pipelineruns in all namespaces", - command: commandV1alpha1(t, prsMultipleNs, clock.Now(), ns, version, dc2), - args: []string{"list", "--all-namespaces"}, - wantError: false, - }, - } - - for _, td := range tests { - t.Run(td.name, func(t *testing.T) { - got, err := test.ExecuteCommand(td.command, td.args...) - - if !td.wantError && err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, got, strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-")) - }) - } -} - func TestListPipelineRuns_v1beta1(t *testing.T) { version := "v1beta1" clock := clockwork.NewFakeClock() @@ -537,7 +291,7 @@ func TestListPipeline_empty(t *testing.T) { }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) cs.Pipeline.Resources = cb.APIResourceList("v1alpha1", []string{"pipelinerun"}) tdc := testDynamic.Options{} dc, err := tdc.Client() @@ -555,19 +309,6 @@ func TestListPipeline_empty(t *testing.T) { test.AssertOutput(t, "No PipelineRuns found\n", output) } -func commandV1alpha1(t *testing.T, prs []*v1alpha1.PipelineRun, now time.Time, ns []*corev1.Namespace, version string, dc dynamic.Interface) *cobra.Command { - // fake clock advanced by 1 hour - clock := clockwork.NewFakeClockAt(now) - clock.Advance(time.Duration(60) * time.Minute) - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - - return Command(p) -} - func commandV1beta1(t *testing.T, prs []*v1beta1.PipelineRun, now time.Time, ns []*corev1.Namespace, version string, dc dynamic.Interface) *cobra.Command { // fake clock advanced by 1 hour clock := clockwork.NewFakeClockAt(now) diff --git a/pkg/cmd/pipelinerun/logs_test.go b/pkg/cmd/pipelinerun/logs_test.go index b56b13fcb7..ac81e676ab 100644 --- a/pkg/cmd/pipelinerun/logs_test.go +++ b/pkg/cmd/pipelinerun/logs_test.go @@ -28,10 +28,8 @@ import ( "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" pipelinev1beta1test "github.com/tektoncd/pipeline/test" - pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -56,7 +54,7 @@ func TestLog_invalid_namespace(t *testing.T) { } tdc := testDynamic.Options{} dc, _ := tdc.Client() - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} cs.Pipeline.Resources = cb.APIResourceList("v1alpha1", []string{"pipelinerun"}) c := Command(p) @@ -80,7 +78,7 @@ func TestLog_invalid_limit(t *testing.T) { }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube} c := Command(p) @@ -104,7 +102,7 @@ func TestLog_no_pipelinerun_argument(t *testing.T) { }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube} c := Command(p) @@ -117,7 +115,7 @@ func TestLog_no_pipelinerun_argument(t *testing.T) { func TestLog_run_found(t *testing.T) { clock := clockwork.NewFakeClock() - pdata := []*v1alpha1.Pipeline{ + pdata := []*v1beta1.Pipeline{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline", @@ -126,7 +124,7 @@ func TestLog_run_found(t *testing.T) { }, }, } - prdata := []*v1alpha1.PipelineRun{ + prdata := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipelinerun1", @@ -134,12 +132,12 @@ func TestLog_run_found(t *testing.T) { CreationTimestamp: metav1.Time{Time: clock.Now()}, Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ + Spec: v1beta1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ Name: "pipeline", }, }, - Status: v1alpha1.PipelineRunStatus{ + Status: v1beta1.PipelineRunStatus{ Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { @@ -151,7 +149,7 @@ func TestLog_run_found(t *testing.T) { }, }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{ + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{ Pipelines: pdata, PipelineRuns: prdata, Namespaces: []*corev1.Namespace{ @@ -165,8 +163,8 @@ func TestLog_run_found(t *testing.T) { cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) tdc := testDynamic.Options{} dc, err := tdc.Client( - cb.UnstructuredP(pdata[0], versionA1), - cb.UnstructuredPR(prdata[0], versionA1), + cb.UnstructuredV1beta1P(pdata[0], versionA1), + cb.UnstructuredV1beta1PR(prdata[0], versionA1), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -182,14 +180,14 @@ func TestLog_run_found(t *testing.T) { } func TestLog_run_not_found(t *testing.T) { - pr := []*v1alpha1.PipelineRun{ + pr := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "output-pipeline-1", Namespace: "ns", Labels: map[string]string{"tekton.dev/pipeline": "output-pipeline-1"}, }, - Status: v1alpha1.PipelineRunStatus{ + Status: v1beta1.PipelineRunStatus{ Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { @@ -210,11 +208,11 @@ func TestLog_run_not_found(t *testing.T) { }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: pr, Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{PipelineRuns: pr, Namespaces: ns}) cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipelinerun"}) tdc := testDynamic.Options{} dc, err := tdc.Client( - cb.UnstructuredPR(pr[0], versionA1), + cb.UnstructuredV1beta1PR(pr[0], versionA1), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) @@ -374,1377 +372,41 @@ func TestPipelinerunLogs(t *testing.T) { Name: tr2Name, PipelineTaskName: task2Name, TypeMeta: runtime.TypeMeta{ - APIVersion: "tekton.dev/v1beta1", - Kind: "TaskRun", - }, - }, - }, - }, - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - }, - }, - } - pps := []*v1beta1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{ - { - Name: task1Name, - TaskRef: &v1beta1.TaskRef{ - Name: task1Name, - }, - }, - { - Name: task2Name, - TaskRef: &v1beta1.TaskRef{ - Name: task2Name, - }, - }, - }, - }, - }, - } - - p := []*corev1.Pod{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: tr1Pod, - Namespace: ns, - Labels: map[string]string{"tekton.dev/task": pipelineName}, - }, - Spec: corev1.PodSpec{ - InitContainers: []corev1.Container{ - { - Name: tr1InitStep1, - Image: "override-with-creds:latest", - }, - { - Name: tr1InitStep2, - Image: "override-with-tools:latest", - }, - }, - Containers: []corev1.Container{ - { - Name: tr1Step1Name, - Image: tr1Step1Name + ":latest", - }, - { - Name: nopStep, - Image: "override-with-nop:latest", - }, - }, - }, - Status: corev1.PodStatus{ - Phase: corev1.PodPhase(corev1.PodSucceeded), - InitContainerStatuses: []corev1.ContainerStatus{ - { - Name: tr1InitStep1, - Image: "override-with-creds:latest", - }, - { - Name: tr1InitStep2, - Image: "override-with-tools:latest", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: tr2Pod, - Namespace: ns, - Labels: map[string]string{"tekton.dev/task": pipelineName}, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: tr2Step1Name, - Image: tr1Step1Name + ":latest", - }, - { - Name: nopStep, - Image: "override-with-nop:latest", - }, - }, - }, - }, - } - - fakeLogs := fake.Logs( - fake.Task(tr1Pod, - fake.Step(tr1InitStep1, "initialized the credentials"), - fake.Step(tr1InitStep2, "place tools log"), - fake.Step(tr1Step1Name, "written a file"), - fake.Step(nopStep, "Build successful"), - ), - fake.Task(tr2Pod, - fake.Step(tr2Step1Name, "able to read a file"), - fake.Step(nopStep, "Build successful"), - ), - ) - - scenarios := []struct { - name string - allSteps bool - tasks []string - expectedLogs []string - prefixing bool - }{ - { - name: "for all tasks", - allSteps: false, - prefixing: true, - expectedLogs: []string{ - "[output-task : writefile-step] written a file\n", - "[output-task : nop] Build successful\n", - "[read-task : readfile-step] able to read a file\n", - "[read-task : nop] Build successful\n", - }, - }, { - name: "for all tasks", - allSteps: false, - prefixing: false, - expectedLogs: []string{ - "written a file\n", - "Build successful\n", - "able to read a file\n", - "Build successful\n", - }, - }, { - name: "for task1 only", - allSteps: false, - prefixing: true, - tasks: []string{task1Name}, - expectedLogs: []string{ - "[output-task : writefile-step] written a file\n", - "[output-task : nop] Build successful\n", - }, - }, { - name: "including init steps", - allSteps: true, - prefixing: true, - expectedLogs: []string{ - "[output-task : credential-initializer-mdzbr] initialized the credentials\n", - "[output-task : place-tools] place tools log\n", - "[output-task : writefile-step] written a file\n", - "[output-task : nop] Build successful\n", - "[read-task : readfile-step] able to read a file\n", - "[read-task : nop] Build successful\n", - }, - }, - } - - for _, s := range scenarios { - t.Run(s.name, func(t *testing.T) { - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{PipelineRuns: prs, Pipelines: pps, TaskRuns: trs, Pods: p, Namespaces: nsList}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredV1beta1P(pps[0], versionA1), - cb.UnstructuredV1beta1PR(prs[0], versionA1), - cb.UnstructuredV1beta1TR(trs[0], versionA1), - cb.UnstructuredV1beta1TR(trs[1], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - prlo := logOptsv1beta1(prName, ns, cs, dc, fake.Streamer(fakeLogs), s.allSteps, false, s.prefixing, s.tasks...) - output, _ := fetchLogs(prlo) - - expected := strings.Join(s.expectedLogs, "\n") + "\n" - - test.AssertOutput(t, expected, output) - }) - } -} - -// scenario, print logs for 1 completed taskruns out of 4 pipeline tasks -func TestPipelinerunLog_completed_taskrun_only(t *testing.T) { - var ( - pipelineName = "output-pipeline" - prName = "output-pipeline-1" - prstart = clockwork.NewFakeClock() - ns = "namespace" - - task1Name = "output-task" - tr1Name = "output-task-1" - tr1StartTime = prstart.Now().Add(20 * time.Second) - tr1CompletionTime = prstart.Now().Add(30 * time.Second) - tr1Pod = "output-task-pod-123456" - tr1Step1Name = "writefile-step" - - // these are pipeline tasks for which pipeline has not - // scheduled any taskrun - task2Name = "read-task" - - task3Name = "notify" - - task4Name = "teardown" - ) - - trdata := []*v1alpha1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: ns, - Name: tr1Name, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: task1Name, - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Type: apis.ConditionSucceeded, - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: tr1StartTime}, - PodName: tr1Pod, - Steps: []v1beta1.StepState{ - { - Name: tr1Step1Name, - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - ExitCode: 0, - }, - }, - }, - { - Name: "nop", - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - ExitCode: 0, - }, - }, - }, - }, - }, - }, - }, - } - pdata := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: task1Name, - TaskRef: &v1alpha1.TaskRef{ - Name: task1Name, - }, - }, - { - Name: task2Name, - TaskRef: &v1alpha1.TaskRef{ - Name: task2Name, - }, - }, - { - Name: task3Name, - TaskRef: &v1alpha1.TaskRef{ - Name: task3Name, - }, - }, - { - Name: task4Name, - TaskRef: &v1alpha1.TaskRef{ - Name: task4Name, - }, - }, - }, - }, - }, - } - prdata := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }, - }, - }, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - tr1Name: { - PipelineTaskName: task1Name, - Status: &v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: tr1StartTime}, - CompletionTime: &metav1.Time{Time: tr1CompletionTime}, - }, - }, - }, - }, - }, - }, - }, - } - // define pipeline in pipelineRef - cs, _ := test.SeedTestData(t, pipelinetest.Data{ - TaskRuns: trdata, - Pipelines: pdata, - PipelineRuns: prdata, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - }, - Pods: []*corev1.Pod{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: tr1Pod, - Namespace: ns, - Labels: map[string]string{"tekton.dev/task": pipelineName}, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: tr1Step1Name, - Image: tr1Step1Name + ":latest", - }, - { - Name: "nop", - Image: "override-with-nop:latest", - }, - }, - }, - }, - }, - }) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredTR(trdata[0], versionA1), - cb.UnstructuredP(pdata[0], versionA1), - cb.UnstructuredPR(prdata[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - tdata2 := []*v1alpha1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "output-task2", - Namespace: "ns", - CreationTimestamp: metav1.Time{Time: clockwork.NewFakeClock().Now()}, - }, - }, - } - trdata2 := []*v1alpha1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "output-taskrun2", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/task": "task"}, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: "output-task2", - }, - }, - Status: v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - PodName: "output-task-pod-embedded", - StartTime: &metav1.Time{Time: clockwork.NewFakeClock().Now()}, - Steps: []v1alpha1.StepState{ - { - Name: "test-step", - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - ExitCode: 0, - }, - }, - }, - }, - }, - }, - }, - } - prdata2 := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "embedded-pipeline-1", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "embedded-pipeline-1"}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineSpec: &v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: "output-task2", - TaskRef: &v1alpha1.TaskRef{ - Name: "output-task2", - }, - }, - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "output-taskrun2": {PipelineTaskName: "output-task2", Status: &v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{}, - TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: tr1StartTime}, - CompletionTime: &metav1.Time{Time: tr1CompletionTime}, - }, - }}, - }, - }, - }, - }, - } - // define embedded pipeline - cs2, _ := test.SeedTestData(t, pipelinetest.Data{ - Tasks: tdata2, - TaskRuns: trdata2, - PipelineRuns: prdata2, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - }, - Pods: []*corev1.Pod{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "output-task-pod-embedded", - Namespace: "ns", - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "test-step", - Image: "test-step1:latest", - }, - { - Name: "nop2", - Image: "override-with-nop:latest", - }, - }, - }, - Status: corev1.PodStatus{ - Phase: corev1.PodPhase(corev1.PodSucceeded), - }, - }, - }, - }) - cs2.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) - tdc2 := testDynamic.Options{} - dc2, err := tdc2.Client( - cb.Unstructuredv1alpha1T(tdata2[0], versionA1), - cb.UnstructuredTR(trdata2[0], versionA1), - cb.UnstructuredPR(prdata2[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - for _, tt := range []struct { - name string - pipelineRunName string - namespace string - dynamic dynamic.Interface - input pipelinetest.Clients - logs []fake.Log - want []string - }{ - { - name: "Test PipelineRef", - pipelineRunName: prName, - namespace: ns, - dynamic: dc, - input: cs, - logs: fake.Logs( - fake.Task(tr1Pod, - fake.Step(tr1Step1Name, "wrote a file"), - fake.Step("nop", "Build successful"), - ), - ), - want: []string{ - "[output-task : writefile-step] wrote a file\n", - "[output-task : nop] Build successful\n", - "", - }, - }, - { - name: "Test embedded Pipeline", - pipelineRunName: "embedded-pipeline-1", - namespace: "ns", - dynamic: dc2, - input: cs2, - logs: fake.Logs( - fake.Task("output-task-pod-embedded", - fake.Step("test-step", "test embedded"), - fake.Step("nop2", "Test successful"), - ), - ), - want: []string{ - "[output-task2 : test-step] test embedded\n", - "[output-task2 : nop2] Test successful\n", - "", - }, - }, - } { - t.Run(tt.name, func(t *testing.T) { - prlo := logOptsv1aplha1(tt.pipelineRunName, tt.namespace, tt.input, tt.dynamic, fake.Streamer(tt.logs), false, false, true) - output, _ := fetchLogs(prlo) - test.AssertOutput(t, strings.Join(tt.want, "\n"), output) - }) - } -} - -func TestPipelinerunLog_follow_mode(t *testing.T) { - var ( - pipelineName = "output-pipeline" - prName = "output-pipeline-1" - prstart = clockwork.NewFakeClock() - ns = "namespace" - - task1Name = "output-task" - tr1Name = "output-task-1" - tr1StartTime = prstart.Now().Add(20 * time.Second) - tr1Pod = "output-task-pod-123456" - tr1Step1Name = "writefile-step" - ) - - nsList := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - trs := []*v1alpha1.TaskRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: tr1Name, - Namespace: ns, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: &v1alpha1.TaskRef{ - Name: task1Name, - }, - }, - Status: v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Type: apis.ConditionSucceeded, - }, - }, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - PodName: tr1Pod, - StartTime: &metav1.Time{Time: tr1StartTime}, - Steps: []v1alpha1.StepState{ - { - Name: tr1Step1Name, - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - ExitCode: 0, - }, - }, - }, - { - Name: "nop", - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - ExitCode: 0, - }, - }, - }, - }, - }, - }, - }, - } - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - tr1Name: {PipelineTaskName: task1Name, Status: &trs[0].Status}, - }, - }, - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }, - }, - }, - }, - }, - } - - pps := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: task1Name, - TaskRef: &v1beta1.TaskRef{ - Name: task1Name, - }, - }, - }, - }, - }, - } - - p := []*corev1.Pod{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: tr1Pod, - Namespace: ns, - Labels: map[string]string{"tekton.dev/task": pipelineName}, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: tr1Step1Name, - Image: tr1Step1Name + ":latest", - }, - { - Name: "nop", - Image: "override-with-nop:latest", - }, - }, - }, - Status: corev1.PodStatus{ - Phase: corev1.PodPhase(corev1.PodSucceeded), - }, - }, - } - - fakeLogStream := fake.Logs( - fake.Task(tr1Pod, - fake.Step(tr1Step1Name, - "wrote a file1", - "wrote a file2", - "wrote a file3", - "wrote a file4", - ), - fake.Step("nop", "Build successful"), - ), - ) - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: pps, TaskRuns: trs, Pods: p, Namespaces: nsList}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredTR(trs[0], versionA1), - cb.UnstructuredPR(prs[0], versionA1), - cb.UnstructuredP(pps[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - prlo := logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer(fakeLogStream), false, true, true) - output, _ := fetchLogs(prlo) - - expectedLogs := []string{ - "[output-task : writefile-step] wrote a file1", - "[output-task : writefile-step] wrote a file2", - "[output-task : writefile-step] wrote a file3", - "[output-task : writefile-step] wrote a file4\n", - "[output-task : nop] Build successful\n", - } - expected := strings.Join(expectedLogs, "\n") + "\n" - - test.AssertOutput(t, expected, output) -} - -func TestLogs_error_log(t *testing.T) { - var ( - pipelineName = "errlogs-pipeline" - prName = "errlogs-run" - ns = "namespace" - taskName = "errlogs-task" - errMsg = "Pipeline tektoncd/errlog-pipeline can't be Run; it contains Tasks that don't exist: Couldn't retrieve Task errlog-tasks: task.tekton.dev errlog-tasks not found" - ) - - nsList := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - ts := []*v1alpha1.Task{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: taskName, - Namespace: ns, - }, - }, - } - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionFalse, - Message: errMsg, - }, - }, - }, - }, - }, - } - - ps := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, - }, - }, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Tasks: ts, Namespaces: nsList}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.Unstructuredv1alpha1T(ts[0], versionA1), - cb.UnstructuredP(ps[0], versionA1), - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - prlo := logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false, true) - output, err := fetchLogs(prlo) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - test.AssertOutput(t, errMsg+"\n", output) -} - -func TestLogs_nologs(t *testing.T) { - var ( - pipelineName = "nologs-pipeline" - prName = "nologs-run" - ns = "namespace" - taskName = "nologs-task" - ) - - nsList := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Message: "Running", - }, - }, - }, - }, - }, - } - - ps := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, - }, - }, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Namespaces: nsList}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredP(ps[0], versionA1), - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - prlo := logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false, true) - output, err := fetchLogs(prlo) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - test.AssertOutput(t, "PipelineRun is still running: Running\n", output) -} - -func TestLog_run_failed_with_and_without_follow(t *testing.T) { - var ( - pipelineName = "fail-pipeline" - prName = "fail-run" - ns = "namespace" - taskName = "fail-task" - failMessage = "Failed because I wanted" - ) - - nsList := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionFalse, - Type: apis.ConditionSucceeded, - Message: failMessage, - }, - }, - }, - }, - }, - } - - ps := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, - }, - }, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Namespaces: nsList}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredP(ps[0], versionA1), - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - // follow mode disabled - prlo := logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false, true) - output, err := fetchLogs(prlo) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - test.AssertOutput(t, failMessage+"\n", output) - - // follow mode enabled - prlo = logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, true, true) - output, err = fetchLogs(prlo) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - test.AssertOutput(t, failMessage+"\n", output) -} - -func TestLog_pipelinerun_still_running(t *testing.T) { - var ( - pipelineName = "inprogress-pipeline" - prName = "inprogress-run" - ns = "namespace" - taskName = "inprogress-task" - ) - - nsList := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - initialPRs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Type: apis.ConditionSucceeded, - Message: "Running", - }, - }, - }, - }, - }, - } - - finalPRs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Type: apis.ConditionSucceeded, - Message: "Running", - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Type: apis.ConditionSucceeded, - Message: "Completed", - }, - }, - }, - }, - }, - } - - ps := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, - }, - }, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: initialPRs, Pipelines: ps, Namespaces: nsList}) - watcher := watch.NewFake() - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"taskrun", "pipeline", "pipelinerun"}) - tdc := testDynamic.Options{WatchResource: "pipelineruns", Watcher: watcher} - dc, err := tdc.Client( - cb.UnstructuredP(ps[0], versionA1), - cb.UnstructuredPR(initialPRs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - prlo := logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false, true) - - updatePRv1alpha1(finalPRs, watcher) - - output, err := fetchLogs(prlo) - - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - test.AssertOutput(t, "Pipeline still running ..."+"\n", output) -} - -func TestLog_pipelinerun_status_done(t *testing.T) { - var ( - pipelineName = "done-pipeline" - prName = "done-run" - ns = "namespace" - taskName = "done-task" - ) - - nsList := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - prs := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": prName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Type: apis.ConditionSucceeded, - Message: "Running", - }, - }, - }, - }, - }, - } - - ps := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, - }, - }, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Namespaces: nsList}) - cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) - watcher := watch.NewFake() - tdc := testDynamic.Options{WatchResource: "pipelineruns", Watcher: watcher} - dc, err := tdc.Client( - cb.UnstructuredP(ps[0], versionA1), - cb.UnstructuredPR(prs[0], versionA1), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - prlo := logOptsv1aplha1(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false, true) - - go func() { - time.Sleep(time.Second * 1) - for _, pr := range prs { - pr.Status.Conditions[0].Status = corev1.ConditionTrue - pr.Status.Conditions[0].Message = "completed" - watcher.Modify(pr) - } - }() - - start := time.Now() - output, err := fetchLogs(prlo) - elapsed := time.Since(start).Seconds() - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - if elapsed > 10 { - t.Errorf("Timed out") - } - test.AssertOutput(t, "", output) -} - -func TestLog_pipelinerun_last(t *testing.T) { - version := "v1alpha1" - var ( - pipelineName = "pipeline1" - prName = "pr1" - prName2 = "pr2" - ns = "namespaces" - taskName = "task1" - ) - - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - pipelines := []*v1alpha1.Pipeline{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineName, - Namespace: ns, - }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ - { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, - }, - }, - }, - }, - }, - } - - pipelineruns := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName2, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": pipelineName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: time.Now().Add(time.Second)}, - }, - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Type: apis.ConditionSucceeded, - Message: "Running", - }, - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: prName, - Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": pipelineName}, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: time.Now()}, + APIVersion: "tekton.dev/v1beta1", + Kind: "TaskRun", + }, + }, + }, }, Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { - Status: corev1.ConditionUnknown, - Type: apis.ConditionSucceeded, - Message: "Running", + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), }, }, }, }, }, } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: pipelineruns, Pipelines: pipelines, Namespaces: namespaces}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(pipelineruns[0], version), - cb.UnstructuredPR(pipelineruns[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := test.Params{ - Kube: cs.Kube, - Tekton: cs.Pipeline, - Dynamic: dc, - } - p.SetNamespace(ns) - lopt := options.LogOptions{ - Params: &p, - Last: true, - Limit: len(pipelineruns), - } - err = askRunName(&lopt) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - test.AssertOutput(t, prName2, lopt.PipelineRunName) -} - -func TestLog_pipelinerun_only_one(t *testing.T) { - version := "v1alpha1" - var ( - pipelineName = "pipeline1" - prName = "pr1" - ns = "namespaces" - taskName = "task1" - ) - - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: ns, - }, - }, - } - - pipelines := []*v1alpha1.Pipeline{ + pps := []*v1beta1.Pipeline{ { ObjectMeta: metav1.ObjectMeta{ Name: pipelineName, Namespace: ns, }, - Spec: v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{ + Spec: v1beta1.PipelineSpec{ + Tasks: []v1beta1.PipelineTask{ { - Name: taskName, - TaskRef: &v1alpha1.TaskRef{ - Name: taskName, + Name: task1Name, + TaskRef: &v1beta1.TaskRef{ + Name: task1Name, + }, + }, + { + Name: task2Name, + TaskRef: &v1beta1.TaskRef{ + Name: task2Name, }, }, }, @@ -1752,68 +414,156 @@ func TestLog_pipelinerun_only_one(t *testing.T) { }, } - pipelineruns := []*v1alpha1.PipelineRun{ + p := []*corev1.Pod{ { ObjectMeta: metav1.ObjectMeta{ - Name: prName, + Name: tr1Pod, Namespace: ns, - Labels: map[string]string{"tekton.dev/pipeline": pipelineName}, + Labels: map[string]string{"tekton.dev/task": pipelineName}, }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: pipelineName, + Spec: corev1.PodSpec{ + InitContainers: []corev1.Container{ + { + Name: tr1InitStep1, + Image: "override-with-creds:latest", + }, + { + Name: tr1InitStep2, + Image: "override-with-tools:latest", + }, + }, + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: nopStep, + Image: "override-with-nop:latest", + }, }, }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionUnknown, - Type: apis.ConditionSucceeded, - Message: "Running", - }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + InitContainerStatuses: []corev1.ContainerStatus{ + { + Name: tr1InitStep1, + Image: "override-with-creds:latest", + }, + { + Name: tr1InitStep2, + Image: "override-with-tools:latest", + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr2Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr2Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: nopStep, + Image: "override-with-nop:latest", }, }, }, }, } - cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: pipelineruns, Pipelines: pipelines, Namespaces: namespaces}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(pipelineruns[0], version), + fakeLogs := fake.Logs( + fake.Task(tr1Pod, + fake.Step(tr1InitStep1, "initialized the credentials"), + fake.Step(tr1InitStep2, "place tools log"), + fake.Step(tr1Step1Name, "written a file"), + fake.Step(nopStep, "Build successful"), + ), + fake.Task(tr2Pod, + fake.Step(tr2Step1Name, "able to read a file"), + fake.Step(nopStep, "Build successful"), + ), ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - p := test.Params{ - Kube: cs.Kube, - Tekton: cs.Pipeline, - Dynamic: dc, - } - p.SetNamespace(ns) - lopt := options.LogOptions{ - Params: &p, - // This code https://git.io/JvCMV seems buggy so have to set the upper - // Limit.. but I guess that's another fight for another day. - Limit: len(pipelineruns), - } - err = askRunName(&lopt) - if err != nil { - t.Errorf("Unexpected error: %v", err) + scenarios := []struct { + name string + allSteps bool + tasks []string + expectedLogs []string + prefixing bool + }{ + { + name: "for all tasks", + allSteps: false, + prefixing: true, + expectedLogs: []string{ + "[output-task : writefile-step] written a file\n", + "[output-task : nop] Build successful\n", + "[read-task : readfile-step] able to read a file\n", + "[read-task : nop] Build successful\n", + }, + }, { + name: "for all tasks", + allSteps: false, + prefixing: false, + expectedLogs: []string{ + "written a file\n", + "Build successful\n", + "able to read a file\n", + "Build successful\n", + }, + }, { + name: "for task1 only", + allSteps: false, + prefixing: true, + tasks: []string{task1Name}, + expectedLogs: []string{ + "[output-task : writefile-step] written a file\n", + "[output-task : nop] Build successful\n", + }, + }, { + name: "including init steps", + allSteps: true, + prefixing: true, + expectedLogs: []string{ + "[output-task : credential-initializer-mdzbr] initialized the credentials\n", + "[output-task : place-tools] place tools log\n", + "[output-task : writefile-step] written a file\n", + "[output-task : nop] Build successful\n", + "[read-task : readfile-step] able to read a file\n", + "[read-task : nop] Build successful\n", + }, + }, } - test.AssertOutput(t, prName, lopt.PipelineRunName) -} -func updatePRv1alpha1(finalRuns []*v1alpha1.PipelineRun, watcher *watch.FakeWatcher) { - go func() { - for _, pr := range finalRuns { - time.Sleep(time.Second * 1) - watcher.Modify(pr) - } - }() + for _, s := range scenarios { + t.Run(s.name, func(t *testing.T) { + cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{PipelineRuns: prs, Pipelines: pps, TaskRuns: trs, Pods: p, Namespaces: nsList}) + cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) + tdc := testDynamic.Options{} + dc, err := tdc.Client( + cb.UnstructuredV1beta1P(pps[0], versionA1), + cb.UnstructuredV1beta1PR(prs[0], versionA1), + cb.UnstructuredV1beta1TR(trs[0], versionA1), + cb.UnstructuredV1beta1TR(trs[1], versionA1), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + prlo := logOptsv1beta1(prName, ns, cs, dc, fake.Streamer(fakeLogs), s.allSteps, false, s.prefixing, s.tasks...) + output, _ := fetchLogs(prlo) + + expected := strings.Join(s.expectedLogs, "\n") + "\n" + + test.AssertOutput(t, expected, output) + }) + } } func updatePRv1beta1(finalRuns []*v1beta1.PipelineRun, watcher *watch.FakeWatcher) { @@ -3355,26 +2105,6 @@ func TestPipelinerunLog_finally_v1beta1(t *testing.T) { test.AssertOutput(t, expected, output) } -func logOptsv1aplha1(name string, ns string, cs pipelinetest.Clients, dc dynamic.Interface, streamer stream.NewStreamerFunc, allSteps bool, follow bool, prefixing bool, tasks ...string) *options.LogOptions { - p := test.Params{ - Kube: cs.Kube, - Tekton: cs.Pipeline, - Dynamic: dc, - } - p.SetNamespace(ns) - - logOptions := options.LogOptions{ - PipelineRunName: name, - Tasks: tasks, - AllSteps: allSteps, - Follow: follow, - Params: &p, - Streamer: streamer, - Prefixing: prefixing, - } - - return &logOptions -} func logOptsv1beta1(name string, ns string, cs pipelinev1beta1test.Clients, dc dynamic.Interface, streamer stream.NewStreamerFunc, allSteps bool, follow bool, prefixing bool, tasks ...string) *options.LogOptions { p := test.Params{ Kube: cs.Kube, diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-Invalid_namespace.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-Invalid_namespace.golden deleted file mode 100644 index 583cbe10d7..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-Invalid_namespace.golden +++ /dev/null @@ -1 +0,0 @@ -No PipelineRuns found diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-all_in_namespace.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-all_in_namespace.golden deleted file mode 100644 index 1d40f7b7c2..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-all_in_namespace.golden +++ /dev/null @@ -1,6 +0,0 @@ -NAME STARTED DURATION STATUS -pr0-1 --- --- --- -pr3-1 --- --- --- -pr1-1 59 minutes ago 1m0s Succeeded -pr2-2 2 hours ago 1m0s Failed -pr2-1 3 hours ago --- Succeeded(Running) diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_output_as_name.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_output_as_name.golden deleted file mode 100644 index b4bf9919ab..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_output_as_name.golden +++ /dev/null @@ -1,5 +0,0 @@ -pipelinerun.tekton.dev/pr0-1 -pipelinerun.tekton.dev/pr3-1 -pipelinerun.tekton.dev/pr1-1 -pipelinerun.tekton.dev/pr2-2 -pipelinerun.tekton.dev/pr2-1 diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_pipeline_name.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_pipeline_name.golden deleted file mode 100644 index 657a924473..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_pipeline_name.golden +++ /dev/null @@ -1,2 +0,0 @@ -NAME STARTED DURATION STATUS -pr1-1 59 minutes ago 1m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_template.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_template.golden deleted file mode 100644 index 4ab8893ec3..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-by_template.golden +++ /dev/null @@ -1,5 +0,0 @@ -pr0-1 -pr3-1 -pr1-1 -pr2-2 -pr2-1 diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label.golden deleted file mode 100644 index d6090e15b8..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label.golden +++ /dev/null @@ -1,2 +0,0 @@ -NAME STARTED DURATION STATUS -pr3-1 --- --- --- diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label_with_in_query.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label_with_in_query.golden deleted file mode 100644 index edf13f27bc..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-filter_pipelineruns_by_label_with_in_query.golden +++ /dev/null @@ -1,3 +0,0 @@ -NAME STARTED DURATION STATUS -pr3-1 --- --- --- -pr2-2 2 hours ago 1m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_greater_than_maximum_case.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_greater_than_maximum_case.golden deleted file mode 100644 index 1d40f7b7c2..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_greater_than_maximum_case.golden +++ /dev/null @@ -1,6 +0,0 @@ -NAME STARTED DURATION STATUS -pr0-1 --- --- --- -pr3-1 --- --- --- -pr1-1 59 minutes ago 1m0s Succeeded -pr2-2 2 hours ago 1m0s Failed -pr2-1 3 hours ago --- Succeeded(Running) diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_negative_case.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_negative_case.golden deleted file mode 100644 index f03f7dbfed..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_negative_case.golden +++ /dev/null @@ -1 +0,0 @@ -Error: limit was -1 but must be a positive number diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_returned_to_1.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_returned_to_1.golden deleted file mode 100644 index 6d24f19973..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_returned_to_1.golden +++ /dev/null @@ -1,2 +0,0 @@ -NAME STARTED DURATION STATUS -pr0-1 --- --- --- diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_with_output_flag_set.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_with_output_flag_set.golden deleted file mode 100644 index 269e2c94ee..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-limit_pipelineruns_with_output_flag_set.golden +++ /dev/null @@ -1,2 +0,0 @@ -pr0-1 -pr3-1 diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-no_mixing_pipelinename_and_label.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-no_mixing_pipelinename_and_label.golden deleted file mode 100644 index 3186e8f347..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-no_mixing_pipelinename_and_label.golden +++ /dev/null @@ -1 +0,0 @@ -Error: failed to list PipelineRuns from namespace namespace: specifying a Pipeline and labels are not compatible diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse.golden deleted file mode 100644 index f28bab087f..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse.golden +++ /dev/null @@ -1,6 +0,0 @@ -NAME STARTED DURATION STATUS -pr2-1 3 hours ago --- Succeeded(Running) -pr2-2 2 hours ago 1m0s Failed -pr1-1 59 minutes ago 1m0s Succeeded -pr3-1 --- --- --- -pr0-1 --- --- --- diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse_with_output_flag.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse_with_output_flag.golden deleted file mode 100644 index 5b6959b6ef..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_in_reverse_with_output_flag.golden +++ /dev/null @@ -1,5 +0,0 @@ -pr2-1 -pr2-2 -pr1-1 -pr3-1 -pr0-1 diff --git a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_pipelineruns_in_all_namespaces.golden b/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_pipelineruns_in_all_namespaces.golden deleted file mode 100644 index 841d2e2523..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestListPipelineRuns-print_pipelineruns_in_all_namespaces.golden +++ /dev/null @@ -1,3 +0,0 @@ -NAMESPACE NAME STARTED DURATION STATUS -namespace-lacher pr4-2 --- --- --- -namespace-tout pr4-1 --- --- --- diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden deleted file mode 100644 index aaddcdaf10..0000000000 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden +++ /dev/null @@ -1,17 +0,0 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s -Labels: - tekton.dev/pipeline=pipeline - -Status - -STARTED DURATION STATUS -5 minutes ago 15m0s Succeeded - -Taskruns - - NAME TASK NAME STARTED DURATION STATUS - tr-2 t-2 5 minutes ago 4m0s Succeeded - tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/log/pipeline_reader.go b/pkg/log/pipeline_reader.go index 5cbf8898fb..331c302500 100644 --- a/pkg/log/pipeline_reader.go +++ b/pkg/log/pipeline_reader.go @@ -31,7 +31,7 @@ import ( ) func (r *Reader) readPipelineLog() (<-chan Log, <-chan error, error) { - pr, err := pipelinerun.GetV1beta1(r.clients, r.run, metav1.GetOptions{}, r.ns) + pr, err := pipelinerun.Get(r.clients, r.run, metav1.GetOptions{}, r.ns) if err != nil { return nil, nil, err } @@ -126,7 +126,7 @@ func (r *Reader) waitUntilAvailable() error { opts := metav1.ListOptions{ FieldSelector: fields.OneTermEqualSelector("metadata.name", r.run).String(), } - run, err := pipelinerun.GetV1beta1(r.clients, r.run, metav1.GetOptions{}, r.ns) + run, err := pipelinerun.Get(r.clients, r.run, metav1.GetOptions{}, r.ns) if err != nil { return err } diff --git a/pkg/pipelinerun/pipelinerun.go b/pkg/pipelinerun/pipelinerun.go index 742fa31faa..3357de68fb 100644 --- a/pkg/pipelinerun/pipelinerun.go +++ b/pkg/pipelinerun/pipelinerun.go @@ -24,7 +24,6 @@ import ( "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/formatted" prsort "github.com/tektoncd/cli/pkg/pipelinerun/sort" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" "k8s.io/apimachinery/pkg/api/errors" @@ -97,30 +96,8 @@ func List(c *cli.Clients, opts metav1.ListOptions, ns string) (*v1beta1.Pipeline return prList, nil } -// It will fetch the resource based on the api available and return v1beta1 form -func Get(c *cli.Clients, prname string, opts metav1.GetOptions, ns string) (*v1beta1.PipelineRun, error) { - gvr, err := actions.GetGroupVersionResource(prGroupResource, c.Tekton.Discovery()) - if err != nil { - return nil, err - } - - if gvr.Version == "v1alpha1" { - pipelinerun, err := getV1alpha1(c, prname, opts, ns) - if err != nil { - return nil, err - } - var pipelinerunConverted v1beta1.PipelineRun - err = pipelinerun.ConvertTo(context.Background(), &pipelinerunConverted) - if err != nil { - return nil, err - } - return &pipelinerunConverted, nil - } - return GetV1beta1(c, prname, opts, ns) -} - // It will fetch the resource in v1beta1 struct format -func GetV1beta1(c *cli.Clients, prname string, opts metav1.GetOptions, ns string) (*v1beta1.PipelineRun, error) { +func Get(c *cli.Clients, prname string, opts metav1.GetOptions, ns string) (*v1beta1.PipelineRun, error) { unstructuredPR, err := actions.Get(prGroupResource, c.Dynamic, c.Tekton.Discovery(), prname, ns, opts) if err != nil { return nil, err @@ -140,21 +117,6 @@ func GetV1beta1(c *cli.Clients, prname string, opts metav1.GetOptions, ns string return populatedPR, nil } -// It will fetch the resource in v1alpha1 struct format -func getV1alpha1(c *cli.Clients, prname string, opts metav1.GetOptions, ns string) (*v1alpha1.PipelineRun, error) { - unstructuredPR, err := actions.Get(prGroupResource, c.Dynamic, c.Tekton.Discovery(), prname, ns, opts) - if err != nil { - return nil, err - } - - var pipelinerun *v1alpha1.PipelineRun - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredPR.UnstructuredContent(), &pipelinerun); err != nil { - fmt.Fprintf(os.Stderr, "Failed to get pipelinerun from %s namespace \n", ns) - return nil, err - } - return pipelinerun, nil -} - func Watch(c *cli.Clients, opts metav1.ListOptions, ns string) (watch.Interface, error) { watch, err := actions.Watch(prGroupResource, c, ns, opts) if err != nil { @@ -198,16 +160,6 @@ func Create(c *cli.Clients, pr *v1beta1.PipelineRun, opts metav1.CreateOptions, return nil, err } - if gvr.Version == "v1alpha1" { - var pipelinerunConverted v1alpha1.PipelineRun - err = pipelinerunConverted.ConvertFrom(context.Background(), pr) - if err != nil { - return nil, err - } - pipelinerunConverted.Kind = "PipelineRun" - pipelinerunConverted.APIVersion = "tekton.dev/v1alpha1" - return createUnstructured(&pipelinerunConverted, c, opts, ns, gvr) - } return createUnstructured(pr, c, opts, ns, gvr) } diff --git a/pkg/pipelinerun/pipelinerun_test.go b/pkg/pipelinerun/pipelinerun_test.go index 3a6a04751d..819136b6d0 100644 --- a/pkg/pipelinerun/pipelinerun_test.go +++ b/pkg/pipelinerun/pipelinerun_test.go @@ -29,7 +29,6 @@ import ( pipelinev1beta1test "github.com/tektoncd/pipeline/test" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/parse" - pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -37,126 +36,6 @@ import ( ) func TestPipelineRunsList_with_single_run(t *testing.T) { - version := "v1alpha1" - clock := clockwork.NewFakeClock() - pr1Started := clock.Now().Add(10 * time.Second) - runDuration := 1 * time.Minute - - prdata := []*v1alpha1.PipelineRun{ - - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "random"}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun1", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr1Started}, - CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun2", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr1Started}, - CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{ - PipelineRuns: prdata, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prdata[0], version), - cb.UnstructuredPR(prdata[1], version), - cb.UnstructuredPR(prdata[2], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - p2 := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - p2.SetNamespace("unknown") - - testParams := []struct { - name string - params *test.Params - listOptions metav1.ListOptions - want []string - }{ - { - name: "Specify related pipeline", - params: p, - listOptions: metav1.ListOptions{LabelSelector: "tekton.dev/pipeline=pipeline"}, - want: []string{ - "pipelinerun1 started -10 seconds ago", - "pipelinerun2 started -10 seconds ago", - }, - }, - { - name: "Not specify related pipeline", - params: p, - listOptions: metav1.ListOptions{}, - want: []string{ - "pipelinerun started ---", - "pipelinerun1 started -10 seconds ago", - "pipelinerun2 started -10 seconds ago", - }, - }, - { - name: "Specify unknown namespace", - params: p2, - listOptions: metav1.ListOptions{}, - want: []string{}, - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - got, err := GetAllPipelineRuns(tp.params, tp.listOptions, 5) - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, tp.want, got) - }) - } -} - -func TestPipelineRunsV1beta1List_with_single_run(t *testing.T) { version := "v1beta1" clock := clockwork.NewFakeClock() pr1Started := clock.Now().Add(10 * time.Second) @@ -304,82 +183,6 @@ func TestPipelineRunsV1beta1List_with_single_run(t *testing.T) { } func TestPipelineRunGet(t *testing.T) { - version := "v1alpha1" - clock := clockwork.NewFakeClock() - pr1Started := clock.Now().Add(10 * time.Second) - runDuration := 1 * time.Minute - - prdata := []*v1alpha1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun1", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr1Started}, - CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun2", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: duckv1beta1.Conditions{ - { - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }, - }, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: pr1Started}, - CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, - }, - }, - }, - } - cs, _ := test.SeedTestData(t, pipelinetest.Data{ - PipelineRuns: prdata, - }) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client( - cb.UnstructuredPR(prdata[0], version), - cb.UnstructuredPR(prdata[1], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} - c, err := p.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - got, err := Get(c, "pipelinerun1", metav1.GetOptions{}, "ns") - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, "pipelinerun1", got.Name) -} - -func TestPipelineRunGet_v1beta1(t *testing.T) { version := "v1beta1" clock := clockwork.NewFakeClock() pr1Started := clock.Now().Add(10 * time.Second) @@ -836,42 +639,6 @@ status: } func TestPipelineRunCreate(t *testing.T) { - version := "v1alpha1" - prdata := v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun1", - Namespace: "ns", - Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, - }, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "pipeline", - }, - }, - } - - cs, _ := test.SeedTestData(t, pipelinetest.Data{}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) - tdc := testDynamic.Options{} - dc, err := tdc.Client() - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dc} - c, err := p.Clients() - if err != nil { - t.Errorf("unable to create client: %v", err) - } - - got, err := Create(c, &prdata, metav1.CreateOptions{}, "ns") - if err != nil { - t.Errorf("unexpected Error") - } - test.AssertOutput(t, "pipelinerun1", got.Name) -} - -func TestPipelineRunCreate_v1beta1(t *testing.T) { version := "v1beta1" prdata := v1beta1.PipelineRun{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/pipelinerun/tracker.go b/pkg/pipelinerun/tracker.go index 0157d928a1..05e36621f0 100644 --- a/pkg/pipelinerun/tracker.go +++ b/pkg/pipelinerun/tracker.go @@ -20,7 +20,6 @@ import ( "github.com/tektoncd/cli/pkg/actions" trh "github.com/tektoncd/cli/pkg/taskrun" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" informers "github.com/tektoncd/pipeline/pkg/client/informers/externalversions" @@ -79,29 +78,18 @@ func (t *Tracker) Monitor(allowed []string) <-chan []trh.Run { eventHandler := func(obj interface{}) { var pipelinerunConverted v1beta1.PipelineRun - switch gvr.Version { - case "v1alpha1": - pr, ok := obj.(*v1alpha1.PipelineRun) - if !ok || pr == nil { - return - } - if err := pr.ConvertTo(context.Background(), &pipelinerunConverted); err != nil { - return - } - case "v1beta1": - pr, ok := obj.(*v1beta1.PipelineRun) - if !ok || pr == nil { - return - } + pr, ok := obj.(*v1beta1.PipelineRun) + if !ok || pr == nil { + return + } - trMap, runMap, err := getFullPipelineTaskStatuses(context.Background(), t.Tekton, t.Ns, pr) - if err != nil { - return - } - pr.DeepCopyInto(&pipelinerunConverted) - pipelinerunConverted.Status.TaskRuns = trMap - pipelinerunConverted.Status.Runs = runMap + trMap, runMap, err := getFullPipelineTaskStatuses(context.Background(), t.Tekton, t.Ns, pr) + if err != nil { + return } + pr.DeepCopyInto(&pipelinerunConverted) + pipelinerunConverted.Status.TaskRuns = trMap + pipelinerunConverted.Status.Runs = runMap trC <- t.findNewTaskruns(&pipelinerunConverted, allowed)