diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go index b6cef00be9d..7b740c82fac 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go @@ -246,7 +246,8 @@ func (pr *PipelineRun) IsCancelled() bool { // GetRunKey return the pipelinerun key for timeout handler map func (pr *PipelineRun) GetRunKey() string { - return fmt.Sprintf("%s/%s/%s", pipelineRunControllerName, pr.Namespace, pr.Name) + // The address of the pointer is a threadsafe unique identifier for the pipelinerun + return fmt.Sprintf("%s/%p", pipelineRunControllerName, pr) } // IsTimedOut returns true if a pipelinerun has exceeded its spec.Timeout based on its status.Timeout diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go index 83ed60cb75c..6df40728fc5 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1_test import ( + "fmt" "testing" "time" @@ -130,13 +131,8 @@ func TestPipelineRunIsCancelled(t *testing.T) { } func TestPipelineRunKey(t *testing.T) { - pr := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "prunname", - Namespace: "testns", - }, - } - expectedKey := "PipelineRun/testns/prunname" + pr := tb.PipelineRun("prunname", "testns") + expectedKey := fmt.Sprintf("PipelineRun/%p", pr) if pr.GetRunKey() != expectedKey { t.Fatalf("Expected taskrun key to be %s but got %s", expectedKey, pr.GetRunKey()) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_types.go b/pkg/apis/pipeline/v1alpha1/taskrun_types.go index ae60cfd2049..1273e72f6dd 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_types.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_types.go @@ -291,5 +291,6 @@ func (tr *TaskRun) IsCancelled() bool { // GetRunKey return the taskrun key for timeout handler map func (tr *TaskRun) GetRunKey() string { - return fmt.Sprintf("%s/%s/%s", "TaskRun", tr.Namespace, tr.Name) + // The address of the pointer is a threadsafe unique identifier for the taskrun + return fmt.Sprintf("%s/%p", "TaskRun", tr) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go index 0b0e46ea942..fa535144743 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1_test import ( + "fmt" "testing" "time" @@ -112,8 +113,8 @@ func TestTaskRunIsCancelled(t *testing.T) { } func TestTaskRunKey(t *testing.T) { - tr := tb.TaskRun("taskrunname", "testns") - expectedKey := "TaskRun/testns/taskrunname" + tr := tb.TaskRun("taskrunname", "") + expectedKey := fmt.Sprintf("TaskRun/%p", tr) if tr.GetRunKey() != expectedKey { t.Fatalf("Expected taskrun key to be %s but got %s", expectedKey, tr.GetRunKey()) } diff --git a/pkg/reconciler/timeout_handler.go b/pkg/reconciler/timeout_handler.go index 9341ae15400..2e9132fefa1 100644 --- a/pkg/reconciler/timeout_handler.go +++ b/pkg/reconciler/timeout_handler.go @@ -170,7 +170,6 @@ func backoffDuration(count uint, jf jitterFunc) time.Duration { func (t *TimeoutSet) checkPipelineRunTimeouts(namespace string, pipelineclientset clientset.Interface) { pipelineRuns, err := pipelineclientset.TektonV1alpha1().PipelineRuns(namespace).List(metav1.ListOptions{}) if err != nil { - t.logger.Errorf("Can't get pipelinerun list in namespace %s: %s", namespace, err) return } for _, pipelineRun := range pipelineRuns.Items { @@ -189,7 +188,6 @@ func (t *TimeoutSet) checkPipelineRunTimeouts(namespace string, pipelineclientse func (t *TimeoutSet) CheckTimeouts(kubeclientset kubernetes.Interface, pipelineclientset clientset.Interface) { namespaces, err := kubeclientset.CoreV1().Namespaces().List(metav1.ListOptions{}) if err != nil { - t.logger.Errorf("Can't get namespaces list: %s", err) return } for _, namespace := range namespaces.Items { @@ -203,7 +201,6 @@ func (t *TimeoutSet) CheckTimeouts(kubeclientset kubernetes.Interface, pipelinec func (t *TimeoutSet) checkTaskRunTimeouts(namespace string, pipelineclientset clientset.Interface) { taskruns, err := pipelineclientset.TektonV1alpha1().TaskRuns(namespace).List(metav1.ListOptions{}) if err != nil { - t.logger.Errorf("Can't get taskrun list in namespace %s: %s", namespace, err) return } for _, taskrun := range taskruns.Items { @@ -245,14 +242,12 @@ func (t *TimeoutSet) WaitPipelineRun(pr *v1alpha1.PipelineRun, startTime *metav1 func (t *TimeoutSet) waitRun(runObj StatusKey, timeout time.Duration, startTime *metav1.Time, callback func(interface{})) { if startTime == nil { - t.logger.Errorf("startTime must be specified in order for a timeout to be calculated accurately for %s", runObj.GetRunKey()) return } if callback == nil { callback = defaultFunc } runtime := time.Since(startTime.Time) - t.logger.Infof("About to start timeout timer for %s. started at %s, timeout is %s, running for %s", runObj.GetRunKey(), startTime.Time, timeout, runtime) defer t.Release(runObj) t.setTimer(runObj, timeout-runtime, callback) } @@ -267,7 +262,6 @@ func (t *TimeoutSet) waitRun(runObj StatusKey, timeout time.Duration, startTime func (t *TimeoutSet) SetTaskRunTimer(tr *v1alpha1.TaskRun, d time.Duration) { callback := t.taskRunCallbackFunc if callback == nil { - t.logger.Errorf("attempted to set a timer for %q but no task run callback has been assigned", tr.Name) return } t.setTimer(tr, d, callback) @@ -275,16 +269,12 @@ func (t *TimeoutSet) SetTaskRunTimer(tr *v1alpha1.TaskRun, d time.Duration) { func (t *TimeoutSet) setTimer(runObj StatusKey, timeout time.Duration, callback func(interface{})) { finished := t.getOrCreateFinishedChan(runObj) - started := time.Now() select { case <-t.stopCh: - t.logger.Infof("stopping timer for %q", runObj.GetRunKey()) return case <-finished: - t.logger.Infof("%q finished, stopping timer", runObj.GetRunKey()) return case <-time.After(timeout): - t.logger.Infof("timer for %q has activated after %s", runObj.GetRunKey(), time.Since(started).String()) callback(runObj) } } diff --git a/test/controller.go b/test/controller.go index e8b28d77f74..cf1aa374c63 100644 --- a/test/controller.go +++ b/test/controller.go @@ -35,22 +35,12 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" fakepipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake" informersv1alpha1 "github.com/tektoncd/pipeline/pkg/client/informers/externalversions/pipeline/v1alpha1" - "go.uber.org/zap/zaptest/observer" corev1 "k8s.io/api/core/v1" coreinformers "k8s.io/client-go/informers/core/v1" fakekubeclientset "k8s.io/client-go/kubernetes/fake" "knative.dev/pkg/controller" ) -// GetLogMessages returns a list of all string logs in logs. -func GetLogMessages(logs *observer.ObservedLogs) []string { - messages := []string{} - for _, l := range logs.All() { - messages = append(messages, l.Message) - } - return messages -} - // Data represents the desired state of the system (i.e. existing resources) to seed controllers // with. type Data struct { @@ -86,7 +76,6 @@ type Informers struct { // TestAssets holds references to the controller, logs, clients, and informers. type TestAssets struct { Controller *controller.Impl - Logs *observer.ObservedLogs Clients Clients }