From 4a65f03978967d5058e1e8d6d87f6543b90200f7 Mon Sep 17 00:00:00 2001 From: Nikhil Thomas Date: Wed, 1 Jun 2022 14:43:30 +0530 Subject: [PATCH] Fix a buggy package reference Make the Poll functions use the correct Timeout and Interval values Signed-off-by: Nikhil Thomas --- test/resources/common.go | 4 +++- test/resources/rbac.go | 8 ++++---- test/resources/tektonaddons.go | 4 ++-- test/resources/tektonchains.go | 7 ++++--- test/resources/tektonconfigs.go | 4 ++-- test/resources/tektondashboards.go | 4 ++-- test/resources/tektonpipelines.go | 4 ++-- test/resources/tektonresources.go | 10 ---------- test/resources/tektonresults.go | 4 ++-- test/resources/tektontriggers.go | 4 ++-- test/resources/verify.go | 2 +- 11 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 test/resources/tektonresources.go diff --git a/test/resources/common.go b/test/resources/common.go index 06ca6b47c8..8f88a77c23 100644 --- a/test/resources/common.go +++ b/test/resources/common.go @@ -19,6 +19,8 @@ package resources import ( "context" "fmt" + + "github.com/tektoncd/operator/test/utils" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1" v1 "k8s.io/api/core/v1" @@ -43,7 +45,7 @@ func ReplaceConfigMap(kubeClient kubernetes.Interface, configMap *v1.ConfigMap) // WaitForTaskRunHappy polls the status of the TaskRun called name from client // every `interval` seconds till it becomes happy with the condition function func WaitForTaskRunHappy(client pipelinev1beta1.TaskRunInterface, name string, conditionFunc func(taskRun *v1beta1.TaskRun) (bool, error)) error { - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { taskRun, err := client.Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { return false, err diff --git a/test/resources/rbac.go b/test/resources/rbac.go index 107672d838..83a8ac4785 100644 --- a/test/resources/rbac.go +++ b/test/resources/rbac.go @@ -33,7 +33,7 @@ func EnsureTestNamespaceExists(clients *utils.Clients, name string) (*corev1.Nam func AssertServiceAccount(t *testing.T, clients *utils.Clients, ns, targetSA string) { t.Helper() - err := wait.Poll(Interval, Timeout, func() (bool, error) { + err := wait.Poll(utils.Interval, utils.Timeout, func() (bool, error) { saList, err := clients.KubeClient.CoreV1().ServiceAccounts(ns).List(context.TODO(), metav1.ListOptions{}) if err != nil { return false, err @@ -53,7 +53,7 @@ func AssertServiceAccount(t *testing.T, clients *utils.Clients, ns, targetSA str func AssertRoleBinding(t *testing.T, clients *utils.Clients, ns, roleBindingName string) { t.Helper() - err := wait.Poll(Interval, Timeout, func() (bool, error) { + err := wait.Poll(utils.Interval, utils.Timeout, func() (bool, error) { rbList, err := clients.KubeClient.RbacV1().RoleBindings(ns).List(context.TODO(), metav1.ListOptions{}) if err != nil { return false, err @@ -73,7 +73,7 @@ func AssertRoleBinding(t *testing.T, clients *utils.Clients, ns, roleBindingName func AssertConfigMap(t *testing.T, clients *utils.Clients, ns, configMapName string) { t.Helper() - err := wait.Poll(Interval, Timeout, func() (bool, error) { + err := wait.Poll(utils.Interval, utils.Timeout, func() (bool, error) { rbList, err := clients.KubeClient.CoreV1().ConfigMaps(ns).List(context.TODO(), metav1.ListOptions{}) if err != nil { return false, err @@ -93,7 +93,7 @@ func AssertConfigMap(t *testing.T, clients *utils.Clients, ns, configMapName str func AssertClusterRole(t *testing.T, clients *utils.Clients, clusterRoleName string) { t.Helper() - err := wait.Poll(Interval, Timeout, func() (bool, error) { + err := wait.Poll(utils.Interval, utils.Timeout, func() (bool, error) { rbList, err := clients.KubeClient.RbacV1().ClusterRoles().List(context.TODO(), metav1.ListOptions{}) if err != nil { return false, err diff --git a/test/resources/tektonaddons.go b/test/resources/tektonaddons.go index 93e69c48d9..a9fca0408f 100644 --- a/test/resources/tektonaddons.go +++ b/test/resources/tektonaddons.go @@ -70,7 +70,7 @@ func WaitForTektonAddonState(clients addonv1alpha1.TektonAddonInterface, name st defer span.End() var lastState *v1alpha1.TektonAddon - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -131,7 +131,7 @@ func TektonAddonCRDelete(t *testing.T, clients *utils.Clients, crNames utils.Res if err := clients.TektonAddon().Delete(context.TODO(), crNames.TektonAddon, metav1.DeleteOptions{}); err != nil { t.Fatalf("TektonAddon %q failed to delete: %v", crNames.TektonAddon, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonAddon().Get(context.TODO(), crNames.TektonAddon, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/tektonchains.go b/test/resources/tektonchains.go index 7746e7eb11..8258414ca7 100644 --- a/test/resources/tektonchains.go +++ b/test/resources/tektonchains.go @@ -20,11 +20,12 @@ import ( "context" "errors" "fmt" - "k8s.io/client-go/kubernetes" "path/filepath" "runtime" "testing" + "k8s.io/client-go/kubernetes" + mfc "github.com/manifestival/client-go-client" mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" @@ -65,7 +66,7 @@ func WaitForTektonChainState(clients typedv1alpha1.TektonChainInterface, name st defer span.End() var lastState *v1alpha1.TektonChain - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -94,7 +95,7 @@ func TektonChainCRDelete(t *testing.T, clients *utils.Clients, crNames utils.Res if err := clients.TektonChains().Delete(context.TODO(), crNames.TektonChain, metav1.DeleteOptions{}); err != nil { t.Fatalf("TektonChain %q failed to delete: %v", crNames.TektonChain, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonChains().Get(context.TODO(), crNames.TektonChain, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/tektonconfigs.go b/test/resources/tektonconfigs.go index 3fae915d9e..761f18aef2 100644 --- a/test/resources/tektonconfigs.go +++ b/test/resources/tektonconfigs.go @@ -99,7 +99,7 @@ func WaitForTektonConfigState(clients configv1alpha1.TektonConfigInterface, name defer span.End() var lastState *v1alpha1.TektonConfig - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -130,7 +130,7 @@ func EnsureNoTektonConfigInstance(t *testing.T, clients *utils.Clients, crNames } t.Fatalf("TektonConfig %q failed to delete: %v", crNames.TektonConfig, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonConfig().Get(context.TODO(), crNames.TektonConfig, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/tektondashboards.go b/test/resources/tektondashboards.go index 50c6507e8b..ff9c1f8efe 100644 --- a/test/resources/tektondashboards.go +++ b/test/resources/tektondashboards.go @@ -67,7 +67,7 @@ func WaitForTektonDashboardState(clients dashboardv1alpha1.TektonDashboardInterf defer span.End() var lastState *v1alpha1.TektonDashboard - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -101,7 +101,7 @@ func TektonDashboardCRDelete(t *testing.T, clients *utils.Clients, crNames utils if err := clients.TektonDashboard().Delete(context.TODO(), crNames.TektonDashboard, metav1.DeleteOptions{}); err != nil { t.Fatalf("TektonDashboard %q failed to delete: %v", crNames.TektonDashboard, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonDashboard().Get(context.TODO(), crNames.TektonDashboard, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/tektonpipelines.go b/test/resources/tektonpipelines.go index fcb9b47964..c6a89df833 100644 --- a/test/resources/tektonpipelines.go +++ b/test/resources/tektonpipelines.go @@ -70,7 +70,7 @@ func WaitForTektonPipelineState(clients pipelinev1alpha1.TektonPipelineInterface defer span.End() var lastState *v1alpha1.TektonPipeline - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -99,7 +99,7 @@ func TektonPipelineCRDelete(t *testing.T, clients *utils.Clients, crNames utils. if err := clients.TektonPipeline().Delete(context.TODO(), crNames.TektonPipeline, metav1.DeleteOptions{}); err != nil { t.Fatalf("TektonPipeline %q failed to delete: %v", crNames.TektonPipeline, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonPipeline().Get(context.TODO(), crNames.TektonPipeline, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/tektonresources.go b/test/resources/tektonresources.go deleted file mode 100644 index f24c69c2cc..0000000000 --- a/test/resources/tektonresources.go +++ /dev/null @@ -1,10 +0,0 @@ -package resources - -import "time" - -const ( - // Interval specifies the time between two polls. - Interval = 10 * time.Second - // Timeout specifies the timeout for the function PollImmediate to reach a certain status. - Timeout = 5 * time.Minute -) diff --git a/test/resources/tektonresults.go b/test/resources/tektonresults.go index b99db93a0b..f78278297f 100644 --- a/test/resources/tektonresults.go +++ b/test/resources/tektonresults.go @@ -70,7 +70,7 @@ func WaitForTektonResultState(clients resultv1alpha1.TektonResultInterface, name defer span.End() var lastState *v1alpha1.TektonResult - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -99,7 +99,7 @@ func TektonResultCRDDelete(t *testing.T, clients *utils.Clients, crNames utils.R if err := clients.TektonResult().Delete(context.TODO(), crNames.TektonResult, metav1.DeleteOptions{}); err != nil { t.Fatalf("TektonResult %q failed to delete: %v", crNames.TektonResult, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonResult().Get(context.TODO(), crNames.TektonResult, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/tektontriggers.go b/test/resources/tektontriggers.go index 20c2b7d7ba..241e39f839 100644 --- a/test/resources/tektontriggers.go +++ b/test/resources/tektontriggers.go @@ -67,7 +67,7 @@ func WaitForTektonTriggerState(clients triggerv1alpha1.TektonTriggerInterface, n defer span.End() var lastState *v1alpha1.TektonTrigger - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -96,7 +96,7 @@ func TektonTriggerCRDelete(t *testing.T, clients *utils.Clients, crNames utils.R if err := clients.TektonTrigger().Delete(context.TODO(), crNames.TektonTrigger, metav1.DeleteOptions{}); err != nil { t.Fatalf("TektonTrigger %q failed to delete: %v", crNames.TektonTrigger, err) } - err := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + err := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { _, err := clients.TektonTrigger().Get(context.TODO(), crNames.TektonTrigger, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/test/resources/verify.go b/test/resources/verify.go index 811bfcf8a5..7cddd09e06 100644 --- a/test/resources/verify.go +++ b/test/resources/verify.go @@ -48,7 +48,7 @@ func DeleteAndVerifyDeployments(t *testing.T, clients *utils.Clients, namespace, t.Fatalf("Failed to delete deployment %s/%s: %v", deployment.Namespace, deployment.Name, err) } - waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(utils.Interval, utils.Timeout, func() (bool, error) { dep, err := clients.KubeClient. AppsV1().Deployments(deployment.Namespace).Get(context.TODO(), deployment.Name, metav1.GetOptions{}) if err != nil {