Repository: kubeflow/kfp-tekton (language: python)

Issue:
Upgrade pipelineLoop controller to Tekton 0.27 and support timeout feature
/kind feature

**Description:**
Upgrade pipelineLoop controller to Tekton 0.27 and support the new timeout feature. We also need to make sure the pipelineLoop controller still backward compatible on Tekton 0.25 after the upgrade.

**Additional information:**
[Miscellaneous information that will assist in solving the issue.]



Discussion / hints:
/assign @ScrapCodes 

Fix patch:
diff --git a/tekton-catalog/pipeline-loops/cmd/webhook/main.go b/tekton-catalog/pipeline-loops/cmd/webhook/main.go
index 68d1042b5a..bdf8dd9a3f 100644
--- a/tekton-catalog/pipeline-loops/cmd/webhook/main.go
+++ b/tekton-catalog/pipeline-loops/cmd/webhook/main.go
@@ -120,8 +120,7 @@ func main() {
 		SecretName:  secretName,
 	})
 
-	sharedmain.WebhookMainWithConfig(ctx, WebhookLogKey,
-		sharedmain.ParseAndGetConfigOrDie(),
+	sharedmain.MainWithContext(ctx, WebhookLogKey,
 		certificates.NewController,
 		newDefaultingAdmissionController,
 		newValidationAdmissionController,
diff --git a/tekton-catalog/pipeline-loops/go.mod b/tekton-catalog/pipeline-loops/go.mod
index a9a00dae67..bf0f033628 100644
--- a/tekton-catalog/pipeline-loops/go.mod
+++ b/tekton-catalog/pipeline-loops/go.mod
@@ -3,19 +3,17 @@ module github.com/kubeflow/kfp-tekton/tekton-catalog/pipeline-loops
 go 1.13
 
 require (
-	github.com/google/go-cmp v0.5.5
+	contrib.go.opencensus.io/exporter/stackdriver v0.13.5 // indirect
+	github.com/go-openapi/validate v0.19.5 // indirect
+	github.com/google/go-cmp v0.5.6
 	github.com/hashicorp/go-multierror v1.1.0
-	github.com/tektoncd/pipeline v0.25.0
-	go.uber.org/zap v1.16.0
-	gomodules.xyz/jsonpatch/v2 v2.1.0
-	k8s.io/api v0.19.7
-	k8s.io/apimachinery v0.19.7
-	k8s.io/client-go v0.19.7
-	knative.dev/pkg v0.0.0-20210331065221-952fdd90dbb0
-)
-
-// Knative deps (release-0.20)
-replace (
-	contrib.go.opencensus.io/exporter/stackdriver => contrib.go.opencensus.io/exporter/stackdriver v0.13.4
-	github.com/Azure/azure-sdk-for-go => github.com/Azure/azure-sdk-for-go v38.2.0+incompatible
+	github.com/tektoncd/pipeline v0.27.1
+	go.uber.org/zap v1.18.1
+	gomodules.xyz/jsonpatch/v2 v2.2.0
+	gopkg.in/evanphx/json-patch.v4 v4.9.0 // indirect
+	honnef.co/go/tools v0.0.1-2020.1.5 // indirect
+	k8s.io/api v0.20.7
+	k8s.io/apimachinery v0.20.7
+	k8s.io/client-go v0.20.7
+	knative.dev/pkg v0.0.0-20210730172132-bb4aaf09c430
 )
diff --git a/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go b/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go
index 0ea63591ce..cb16ed9f6e 100644
--- a/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go
+++ b/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun.go
@@ -46,6 +46,7 @@ import (
 	"gomodules.xyz/jsonpatch/v2"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/labels"
+	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/apimachinery/pkg/types"
 	"knative.dev/pkg/apis"
 	"knative.dev/pkg/logging"
@@ -244,10 +245,19 @@ func (c *Reconciler) reconcile(ctx context.Context, run *v1alpha1.Run, status *p
 	// Run is cancelled, just cancel all the running instance and return
 	if run.IsCancelled() {
 		if len(failedPrs) > 0 {
-			run.Status.MarkRunFailed(pipelineloopv1alpha1.PipelineLoopRunReasonCancelled.String(),
+			run.Status.MarkRunFailed(pipelineloopv1alpha1.PipelineLoopRunReasonFailed.String(),
+				"Run %s/%s was failed",
+				run.Namespace, run.Name)
+		} else {
+			reason := pipelineloopv1alpha1.PipelineLoopRunReasonCancelled.String()
+			if run.HasTimedOut() { // This check is only possible if we are on tekton 0.27.0 +
+				reason = v1alpha1.RunReasonTimedOut
+			}
+			run.Status.MarkRunFailed(reason,
 				"Run %s/%s was cancelled",
 				run.Namespace, run.Name)
 		}
+
 		for _, currentRunningPr := range currentRunningPrs {
 			logger.Infof("Run %s/%s is cancelled.  Cancelling PipelineRun %s.", run.Namespace, run.Name, currentRunningPr.Name)
 			if _, err := c.pipelineClientSet.TektonV1beta1().PipelineRuns(run.Namespace).Patch(ctx, currentRunningPr.Name, types.JSONPatchType, cancelPatchBytes, metav1.PatchOptions{}); err != nil {
@@ -378,14 +388,14 @@ func (c *Reconciler) createPipelineRun(ctx context.Context, logger *zap.SugaredL
 
 	// Create name for PipelineRun from Run name plus iteration number.
 	prName := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("%s-%s", run.Name, fmt.Sprintf("%05d", iteration)))
-
 	pr := &v1beta1.PipelineRun{
 		ObjectMeta: metav1.ObjectMeta{
-			Name:            prName,
-			Namespace:       run.Namespace,
-			OwnerReferences: []metav1.OwnerReference{run.GetOwnerReference()},
-			Labels:          getPipelineRunLabels(run, strconv.Itoa(iteration)),
-			Annotations:     getPipelineRunAnnotations(run),
+			Name:      prName,
+			Namespace: run.Namespace,
+			OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(run,
+				schema.GroupVersionKind{Group: "tekton.dev", Version: "v1alpha1", Kind: "Run"})},
+			Labels:      getPipelineRunLabels(run, strconv.Itoa(iteration)),
+			Annotations: getPipelineRunAnnotations(run),
 		},
 		Spec: v1beta1.PipelineRunSpec{
 			Params:             getParameters(run, tls, iteration),


Test patch:
diff --git a/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun_test.go b/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun_test.go
index 5fd066a030..5cb1d8b91b 100644
--- a/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun_test.go
+++ b/tekton-catalog/pipeline-loops/pkg/reconciler/pipelinelooprun/pipelinelooprun_test.go
@@ -68,22 +68,6 @@ func loopRunning(run *v1alpha1.Run) *v1alpha1.Run {
 	return runWithStatus
 }
 
-func requestCancel(run *v1alpha1.Run) *v1alpha1.Run {
-	runWithCancelStatus := run.DeepCopy()
-	runWithCancelStatus.Spec.Status = v1alpha1.RunSpecStatusCancelled
-	return runWithCancelStatus
-}
-
-func running(tr *v1beta1.PipelineRun) *v1beta1.PipelineRun {
-	trWithStatus := tr.DeepCopy()
-	trWithStatus.Status.SetCondition(&apis.Condition{
-		Type:   apis.ConditionSucceeded,
-		Status: corev1.ConditionUnknown,
-		Reason: v1beta1.PipelineRunReasonRunning.String(),
-	})
-	return trWithStatus
-}
-
 func successful(pr *v1beta1.PipelineRun) *v1beta1.PipelineRun {
 	prWithStatus := pr.DeepCopy()
 	prWithStatus.Status.SetCondition(&apis.Condition{