diff --git a/test/e2e/framework/assertions.go b/test/e2e/framework/assertions.go index f632e68c..8b4fa6fb 100644 --- a/test/e2e/framework/assertions.go +++ b/test/e2e/framework/assertions.go @@ -25,7 +25,7 @@ import ( // default ForeverTestTimeout is 30, some test fails because they take more than 30s // change to custom in order to let the test finish withouth errors -const CustomForeverTestTimeout = 40 * time.Second +const DefaultTestTimeout = 40 * time.Second type AssertOption struct { PollInterval time.Duration @@ -46,11 +46,11 @@ func WithPollInterval(d time.Duration) OptionFn { } } -// AssertResourceNeverExists asserts that a statefulset is never created for the duration of customForeverTestTimeout +// AssertResourceNeverExists asserts that a statefulset is never created for the duration of DefaultTestTimeout func (f *Framework) AssertResourceNeverExists(name, namespace string, resource client.Object, fns ...OptionFn) func(t *testing.T) { option := AssertOption{ PollInterval: 5 * time.Second, - WaitTimeout: CustomForeverTestTimeout, + WaitTimeout: DefaultTestTimeout, } for _, fn := range fns { fn(&option) @@ -62,12 +62,12 @@ func (f *Framework) AssertResourceNeverExists(name, namespace string, resource c Name: name, Namespace: namespace, } - if err := f.K8sClient.Get(ctx, key, resource); errors.IsNotFound(err) { + if err := f.K8sClient.Get(context.Background(), key, resource); errors.IsNotFound(err) { return false, nil } return true, fmt.Errorf("resource %s/%s should not have been created", namespace, name) - }); wait.Interrupted(err) { + }); !wait.Interrupted(err) { t.Fatal(err) } } @@ -77,7 +77,7 @@ func (f *Framework) AssertResourceNeverExists(name, namespace string, resource c func (f *Framework) AssertResourceEventuallyExists(name, namespace string, resource client.Object, fns ...OptionFn) func(t *testing.T) { option := AssertOption{ PollInterval: 5 * time.Second, - WaitTimeout: CustomForeverTestTimeout, + WaitTimeout: DefaultTestTimeout, } for _, fn := range fns { fn(&option) @@ -103,16 +103,16 @@ func (f *Framework) AssertResourceEventuallyExists(name, namespace string, resou func (f *Framework) AssertStatefulsetReady(name, namespace string, fns ...OptionFn) func(t *testing.T) { option := AssertOption{ PollInterval: 5 * time.Second, - WaitTimeout: CustomForeverTestTimeout, + WaitTimeout: DefaultTestTimeout, } for _, fn := range fns { fn(&option) } return func(t *testing.T) { key := types.NamespacedName{Name: name, Namespace: namespace} - if err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, option.WaitTimeout, true, func(ctx context.Context) (bool, error) { + if err := wait.PollUntilContextTimeout(context.Background(), 5+time.Second, option.WaitTimeout, true, func(ctx context.Context) (done bool, err error) { pod := &appsv1.StatefulSet{} - err := f.K8sClient.Get(context.Background(), key, pod) + err = f.K8sClient.Get(context.Background(), key, pod) return err == nil && pod.Status.ReadyReplicas == *pod.Spec.Replicas, nil }); err != nil { t.Fatal(err) @@ -121,7 +121,7 @@ func (f *Framework) AssertStatefulsetReady(name, namespace string, fns ...Option } func (f *Framework) GetResourceWithRetry(t *testing.T, name, namespace string, obj client.Object) { - err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { key := types.NamespacedName{Name: name, Namespace: namespace} if err := f.K8sClient.Get(context.Background(), key, obj); errors.IsNotFound(err) { @@ -226,7 +226,7 @@ func (f *Framework) GetOperatorMetrics(t *testing.T) []byte { stopChan := make(chan struct{}) defer close(stopChan) - if err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + if err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { err := f.StartPortForward(pod.Name, pod.Namespace, "8080", stopChan) return err == nil, nil }); err != nil { @@ -266,7 +266,7 @@ func (f *Framework) GetStackWhenAvailable(t *testing.T, name, namespace string) } var lastErr error - err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { lastErr = nil err := f.K8sClient.Get(context.Background(), key, &ms) if err != nil { @@ -292,7 +292,7 @@ func (f *Framework) AssertAlertmanagerAbsent(t *testing.T, name, namespace strin Name: name, Namespace: namespace, } - err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { err := f.K8sClient.Get(context.Background(), key, &am) if errors.IsNotFound(err) { return true, nil diff --git a/test/e2e/monitoring_stack_controller_test.go b/test/e2e/monitoring_stack_controller_test.go index 5f242318..7709ed84 100644 --- a/test/e2e/monitoring_stack_controller_test.go +++ b/test/e2e/monitoring_stack_controller_test.go @@ -50,9 +50,7 @@ func assertCRDExists(t *testing.T, crds ...string) { func TestMonitoringStackController(t *testing.T) { err := stack.AddToScheme(scheme.Scheme) - if err != nil { - return - } + assert.NilError(t, err, "adding stack to scheme failed") assertCRDExists(t, "prometheuses.monitoring.rhobs", "alertmanagers.monitoring.rhobs", @@ -151,7 +149,7 @@ func nilResrouceSelectorPropagatesToPrometheus(t *testing.T) { assert.NilError(t, err, "failed to patch monitoring stack with nil resource selector") prometheus := monv1.Prometheus{} - err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { if err := f.K8sClient.Get(context.Background(), types.NamespacedName{Name: updatedMS.Name, Namespace: updatedMS.Namespace}, &prometheus); errors.IsNotFound(err) { return false, nil } @@ -299,7 +297,7 @@ func reconcileRevertsManualChanges(t *testing.T) { err = f.K8sClient.Update(context.Background(), modified) assert.NilError(t, err, "failed to update a prometheus") - err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { reconciled := monv1.Prometheus{} key := types.NamespacedName{Name: ms.Name, Namespace: ms.Namespace} @@ -586,7 +584,7 @@ func prometheusScaleDown(t *testing.T) { ms.Spec.PrometheusConfig.Replicas = &numOfRep err = f.K8sClient.Update(context.Background(), ms) assert.NilError(t, err, "failed to update a monitoring stack") - err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { if err := f.K8sClient.Get(context.Background(), key, &prom); errors.IsNotFound(err) { return false, nil } @@ -743,8 +741,6 @@ func getAlertmanagerAlerts() ([]alert, error) { } func newAlerts(t *testing.T) *monv1.PrometheusRule { - durationTenSec := monv1.Duration("10s") - durationOneSec := monv1.Duration("1s") rule := &monv1.PrometheusRule{ TypeMeta: metav1.TypeMeta{ APIVersion: monv1.SchemeGroupVersion.String(), @@ -758,17 +754,17 @@ func newAlerts(t *testing.T) *monv1.PrometheusRule { Groups: []monv1.RuleGroup{ { Name: "Test", - Interval: &durationTenSec, + Interval: ptr.To(monv1.Duration("10s")), Rules: []monv1.Rule{ { Alert: "AlwaysOn", Expr: intstr.FromString("vector(1)"), - For: &durationOneSec, + For: ptr.To(monv1.Duration("1s")), }, { Alert: "NeverOn", Expr: intstr.FromString("vector(1) == 0"), - For: &durationOneSec, + For: ptr.To(monv1.Duration("1s")), }, }, }, @@ -821,7 +817,7 @@ func newMonitoringStack(t *testing.T, name string, mods ...stackModifier) *stack } func waitForStackDeletion(name string) error { - return wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.CustomForeverTestTimeout, true, func(ctx context.Context) (bool, error) { + return wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.DefaultTestTimeout, true, func(ctx context.Context) (bool, error) { key := types.NamespacedName{Name: name, Namespace: e2eTestNamespace} var ms stack.MonitoringStack err := f.K8sClient.Get(context.Background(), key, &ms) diff --git a/test/e2e/po_admission_webhook_test.go b/test/e2e/po_admission_webhook_test.go index cf21aea8..d10d32b2 100644 --- a/test/e2e/po_admission_webhook_test.go +++ b/test/e2e/po_admission_webhook_test.go @@ -8,6 +8,7 @@ import ( "gotest.tools/v3/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/utils/ptr" ) func TestPrometheusRuleWebhook(t *testing.T) { @@ -42,7 +43,6 @@ func invalidPrometheusRuleIsRejected(t *testing.T) { } func newSinglePrometheusRule(t *testing.T, name, expr string) *monv1.PrometheusRule { - durationFifteenMinutes := monv1.Duration("15m") rule := &monv1.PrometheusRule{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -54,7 +54,7 @@ func newSinglePrometheusRule(t *testing.T, name, expr string) *monv1.PrometheusR Rules: []monv1.Rule{{ Alert: "alert name", Expr: intstr.FromString(expr), - For: &durationFifteenMinutes, + For: ptr.To(monv1.Duration("15m")), }}, }}, }, diff --git a/test/e2e/thanos_querier_controller_test.go b/test/e2e/thanos_querier_controller_test.go index dae291b9..4b25bce8 100644 --- a/test/e2e/thanos_querier_controller_test.go +++ b/test/e2e/thanos_querier_controller_test.go @@ -75,12 +75,7 @@ func singleStackWithSidecar(t *testing.T) { // Assert prometheus instance can be queried stopChan := make(chan struct{}) defer close(stopChan) -<<<<<<< Updated upstream - //nolint - if err := wait.Poll(5*time.Second, 2*time.Minute, func() (bool, error) { -======= if err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 2*time.Minute, true, func(ctx context.Context) (bool, error) { ->>>>>>> Stashed changes err = f.StartServicePortForward(name, e2eTestNamespace, "9090", stopChan) return err == nil, nil }); wait.Interrupted(err) { @@ -91,12 +86,7 @@ func singleStackWithSidecar(t *testing.T) { expectedResults := map[string]int{ "prometheus_build_info": 2, // must return from both prometheus pods } -<<<<<<< Updated upstream - //nolint - if err := wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) { -======= if err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 5*time.Minute, true, func(ctx context.Context) (bool, error) { ->>>>>>> Stashed changes correct := 0 for query, value := range expectedResults { result, err := promClient.Query(query) @@ -147,14 +137,8 @@ func newThanosQuerier(t *testing.T, name string, selector map[string]string) *ms } func waitForThanosQuerierDeletion(tq *msov1.ThanosQuerier) error { -<<<<<<< Updated upstream - //nolint - return wait.Poll(5*time.Second, wait.ForeverTestTimeout, func() (bool, error) { - err := f.K8sClient.Get(context.Background(), -======= return wait.PollUntilContextTimeout(context.Background(), 5*time.Second, wait.ForeverTestTimeout, true, func(ctx context.Context) (done bool, err error) { err = f.K8sClient.Get(context.Background(), ->>>>>>> Stashed changes types.NamespacedName{Name: tq.Name, Namespace: tq.Namespace}, tq) return errors.IsNotFound(err), nil @@ -162,12 +146,7 @@ func waitForThanosQuerierDeletion(tq *msov1.ThanosQuerier) error { } func waitForDeploymentDeletion(name string) error { -<<<<<<< Updated upstream - //nolint - return wait.Poll(5*time.Second, wait.ForeverTestTimeout, func() (bool, error) { -======= return wait.PollUntilContextTimeout(context.Background(), 5*time.Second, wait.ForeverTestTimeout, true, func(ctx context.Context) (done bool, err error) { ->>>>>>> Stashed changes var dep appsv1.Deployment err = f.K8sClient.Get(context.Background(), types.NamespacedName{Name: name, Namespace: e2eTestNamespace}, @@ -177,12 +156,7 @@ func waitForDeploymentDeletion(name string) error { } func waitForServiceDeletion(name string) error { -<<<<<<< Updated upstream - //nolint - return wait.Poll(5*time.Second, wait.ForeverTestTimeout, func() (bool, error) { -======= return wait.PollUntilContextTimeout(context.Background(), 5*time.Second, wait.ForeverTestTimeout, true, func(ctx context.Context) (done bool, err error) { ->>>>>>> Stashed changes var svc corev1.Service err = f.K8sClient.Get(context.Background(), types.NamespacedName{Name: name, Namespace: e2eTestNamespace},