Skip to content

Commit

Permalink
Replace deprecated wait.PollImmediate function
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaSchwarze0 committed Mar 4, 2024
1 parent 0ad334a commit 2bc6ffc
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 190 deletions.
2 changes: 1 addition & 1 deletion test/e2e/v1alpha1/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (b buildPrototype) Create() (build *buildv1alpha1.Build, err error) {
return nil, err
}

err = wait.PollImmediate(pollCreateInterval, pollCreateTimeout, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(ctx, pollCreateInterval, pollCreateTimeout, true, func(ctx context.Context) (done bool, err error) {
build, err = testBuild.BuildClientSet.ShipwrightV1alpha1().Builds(b.build.Namespace).Get(ctx, b.build.Name, meta.GetOptions{})
if err != nil {
return false, err
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/v1beta1/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (b buildPrototype) Create() (build *buildv1beta1.Build, err error) {
return nil, err
}

err = wait.PollImmediate(pollCreateInterval, pollCreateTimeout, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(ctx, pollCreateInterval, pollCreateTimeout, true, func(ctx context.Context) (done bool, err error) {
build, err = testBuild.BuildClientSet.ShipwrightV1beta1().Builds(b.build.Namespace).Get(ctx, b.build.Name, meta.GetOptions{})
if err != nil {
return false, err
Expand Down
3 changes: 2 additions & 1 deletion test/integration/buildruns_to_sa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package integration_test

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -151,7 +152,7 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() {
Expect(contains(sa.Secrets, *buildObject.Spec.Output.PushSecret)).To(BeTrue())

// cancel the br
err = wait.PollImmediate(1*time.Second, 4*time.Second, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(tb.Context, 1*time.Second, 4*time.Second, true, func(_ context.Context) (done bool, err error) {
bro, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
GinkgoT().Logf("error on br get: %s\n", err.Error())
Expand Down
4 changes: 2 additions & 2 deletions test/integration/buildruns_to_taskruns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
}

timeout := int64(tb.TimeOut.Seconds())
buildRunWatcher, err := tb.BuildClientSet.ShipwrightV1beta1().BuildRuns(tb.Namespace).Watch(context.TODO(), metav1.ListOptions{TimeoutSeconds: &timeout})
buildRunWatcher, err := tb.BuildClientSet.ShipwrightV1beta1().BuildRuns(tb.Namespace).Watch(tb.Context, metav1.ListOptions{TimeoutSeconds: &timeout})
Expect(err).To(BeNil())

buildObject, err = tb.Catalog.LoadBuildWithNameAndStrategy(BUILD+tb.Namespace, strategyName, buildDef)
Expand Down Expand Up @@ -401,7 +401,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {

Expect(tb.CreateBR(buildRunObject)).To(BeNil())

err := wait.PollImmediate(1*time.Second, 4*time.Second, func() (done bool, err error) {
err := wait.PollUntilContextTimeout(tb.Context, 1*time.Second, 4*time.Second, true, func(_ context.Context) (done bool, err error) {
bro, err := tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
GinkgoT().Logf("error on br get: %s\n", err.Error())
Expand Down
56 changes: 28 additions & 28 deletions test/utils/v1alpha1/buildruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func (t *TestBuild) CreateBR(buildRun *v1alpha1.BuildRun) error {
brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

_, err := brInterface.Create(context.TODO(), buildRun, metav1.CreateOptions{})
_, err := brInterface.Create(t.Context, buildRun, metav1.CreateOptions{})
if err != nil {
return err
}
Expand All @@ -34,7 +34,7 @@ func (t *TestBuild) CreateBR(buildRun *v1alpha1.BuildRun) error {
// UpdateBR updates a BuildRun on the current test namespace
func (t *TestBuild) UpdateBR(buildRun *v1alpha1.BuildRun) error {
brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)
_, err := brInterface.Update(context.TODO(), buildRun, metav1.UpdateOptions{})
_, err := brInterface.Update(t.Context, buildRun, metav1.UpdateOptions{})
if err != nil {
return err
}
Expand All @@ -46,7 +46,7 @@ func (t *TestBuild) UpdateBR(buildRun *v1alpha1.BuildRun) error {
func (t *TestBuild) GetBR(name string) (*v1alpha1.BuildRun, error) {
brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

br, err := brInterface.Get(context.TODO(), name, metav1.GetOptions{})
br, err := brInterface.Get(t.Context, name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -57,7 +57,7 @@ func (t *TestBuild) GetBR(name string) (*v1alpha1.BuildRun, error) {
func (t *TestBuild) DeleteBR(name string) error {
brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

if err := brInterface.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil {
if err := brInterface.Delete(t.Context, name, metav1.DeleteOptions{}); err != nil {
return err
}

Expand All @@ -83,11 +83,11 @@ func (t *TestBuild) GetBRReason(name string) (string, error) {
func (t *TestBuild) GetBRTillCompletion(name string) (*v1alpha1.BuildRun, error) {

var (
pollBRTillCompletion = func() (bool, error) {
pollBRTillCompletion = func(ctx context.Context) (bool, error) {

bInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

buildRun, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
buildRun, err := bInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -101,22 +101,22 @@ func (t *TestBuild) GetBRTillCompletion(name string) (*v1alpha1.BuildRun, error)

brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

err := wait.PollImmediate(t.Interval, t.TimeOut, pollBRTillCompletion)
err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBRTillCompletion)
if err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}

// GetBRTillNotFound waits for the buildrun to get deleted. It returns an error if BuildRun is not found
func (t *TestBuild) GetBRTillNotFound(name string, interval time.Duration, timeout time.Duration) (*v1alpha1.BuildRun, error) {

var (
GetBRTillNotFound = func() (bool, error) {
GetBRTillNotFound = func(ctx context.Context) (bool, error) {

bInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)
_, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
_, err := bInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && apierrors.IsNotFound(err) {
return true, err
}
Expand All @@ -126,12 +126,12 @@ func (t *TestBuild) GetBRTillNotFound(name string, interval time.Duration, timeo

brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

err := wait.PollImmediate(interval, timeout, GetBRTillNotFound)
err := wait.PollUntilContextTimeout(t.Context, interval, timeout, true, GetBRTillNotFound)
if err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}

// GetBRTillNotOwner returns a BuildRun that has not an owner.
Expand All @@ -142,9 +142,9 @@ func (t *TestBuild) GetBRTillNotOwner(name string, owner string) (*v1alpha1.Buil
brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

var (
pollBRTillNotOwner = func() (bool, error) {
pollBRTillNotOwner = func(ctx context.Context) (bool, error) {

buildRun, err := brInterface.Get(context.TODO(), name, metav1.GetOptions{})
buildRun, err := brInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -159,11 +159,11 @@ func (t *TestBuild) GetBRTillNotOwner(name string, owner string) (*v1alpha1.Buil
}
)

if err := wait.PollImmediate(t.Interval, t.TimeOut, pollBRTillNotOwner); err != nil {
if err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBRTillNotOwner); err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}

// GetBRTillOwner returns a BuildRun that has an owner.
Expand All @@ -174,9 +174,9 @@ func (t *TestBuild) GetBRTillOwner(name string, owner string) (*v1alpha1.BuildRu
brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

var (
pollBRTillOwner = func() (bool, error) {
pollBRTillOwner = func(ctx context.Context) (bool, error) {

buildRun, err := brInterface.Get(context.TODO(), name, metav1.GetOptions{})
buildRun, err := brInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -191,11 +191,11 @@ func (t *TestBuild) GetBRTillOwner(name string, owner string) (*v1alpha1.BuildRu
}
)

if err := wait.PollImmediate(t.Interval, t.TimeOut, pollBRTillOwner); err != nil {
if err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBRTillOwner); err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}

// GetBRTillStartTime returns a BuildRun that have a StartTime set.
Expand All @@ -204,11 +204,11 @@ func (t *TestBuild) GetBRTillOwner(name string, owner string) (*v1alpha1.BuildRu
func (t *TestBuild) GetBRTillStartTime(name string) (*v1alpha1.BuildRun, error) {

var (
pollBRTillCompletion = func() (bool, error) {
pollBRTillCompletion = func(ctx context.Context) (bool, error) {

bInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

buildRun, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
buildRun, err := bInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -231,18 +231,18 @@ func (t *TestBuild) GetBRTillStartTime(name string) (*v1alpha1.BuildRun, error)

brInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

err := wait.PollImmediate(t.Interval, t.TimeOut, pollBRTillCompletion)
err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBRTillCompletion)
if err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}

// GetBRTillDesiredReason polls until a BuildRun gets a particular Reason
// it exit if an error happens or the timeout is reached
func (t *TestBuild) GetBRTillDesiredReason(buildRunname string, reason string) (currentReason string, err error) {
err = wait.PollImmediate(t.Interval, t.TimeOut, func() (bool, error) {
err = wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, func(_ context.Context) (bool, error) {
currentReason, err = t.GetBRReason(buildRunname)
if err != nil {
return false, err
Expand All @@ -262,19 +262,19 @@ func (t *TestBuild) GetBRTillDesiredReason(buildRunname string, reason string) (
func (t *TestBuild) GetBRTillDeletion(name string) (bool, error) {

var (
pollBRTillCompletion = func() (bool, error) {
pollBRTillCompletion = func(ctx context.Context) (bool, error) {

bInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildRuns(t.Namespace)

_, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
_, err := bInterface.Get(ctx, name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
return true, nil
}
return false, nil
}
)

err := wait.PollImmediate(t.Interval, t.TimeOut, pollBRTillCompletion)
err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBRTillCompletion)
if err != nil {
return false, err
}
Expand Down
26 changes: 13 additions & 13 deletions test/utils/v1alpha1/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
func (t *TestBuild) CreateBuild(build *v1alpha1.Build) error {
bInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)

_, err := bInterface.Create(context.TODO(), build, metav1.CreateOptions{})
_, err := bInterface.Create(t.Context, build, metav1.CreateOptions{})
return err
}

// DeleteBuild deletes a Build on the desired namespace
func (t *TestBuild) DeleteBuild(name string) error {
bInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)

err := bInterface.Delete(context.TODO(), name, metav1.DeleteOptions{})
err := bInterface.Delete(t.Context, name, metav1.DeleteOptions{})

return err
}
Expand All @@ -40,7 +40,7 @@ func (t *TestBuild) DeleteBuild(name string) error {
// Deprecated: Use LookupBuild instead
func (t *TestBuild) GetBuild(name string) (*v1alpha1.Build, error) {
return t.BuildClientSet.ShipwrightV1alpha1().
Builds(t.Namespace).Get(context.TODO(), name, metav1.GetOptions{})
Builds(t.Namespace).Get(t.Context, name, metav1.GetOptions{})
}

// ListBuilds returns existing Builds from the desired namespace
Expand All @@ -56,7 +56,7 @@ func (t *TestBuild) PatchBuild(buildName string, data []byte) (*v1alpha1.Build,
// PatchBuildWithPatchType patches an existing Build and allows specifying the patch type
func (t *TestBuild) PatchBuildWithPatchType(buildName string, data []byte, pt types.PatchType) (*v1alpha1.Build, error) {
bInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)
b, err := bInterface.Patch(context.TODO(), buildName, pt, data, metav1.PatchOptions{})
b, err := bInterface.Patch(t.Context, buildName, pt, data, metav1.PatchOptions{})
if err != nil {
return nil, err
}
Expand All @@ -67,7 +67,7 @@ func (t *TestBuild) PatchBuildWithPatchType(buildName string, data []byte, pt ty
// it´s registered field. If timeout is reached or an error is found, it will
// return with an error
func (t *TestBuild) GetBuildTillValidation(name string) (build *v1alpha1.Build, err error) {
err = wait.PollImmediate(t.Interval, t.TimeOut, func() (bool, error) {
err = wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, func(_ context.Context) (bool, error) {
build, err = t.LookupBuild(types.NamespacedName{Namespace: t.Namespace, Name: name})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
Expand All @@ -90,11 +90,11 @@ func (t *TestBuild) GetBuildTillValidation(name string) (build *v1alpha1.Build,
func (t *TestBuild) GetBuildTillRegistration(name string, condition corev1.ConditionStatus) (*v1alpha1.Build, error) {

var (
pollBuildTillRegistration = func() (bool, error) {
pollBuildTillRegistration = func(ctx context.Context) (bool, error) {

bInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)

buildRun, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
buildRun, err := bInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -109,11 +109,11 @@ func (t *TestBuild) GetBuildTillRegistration(name string, condition corev1.Condi

brInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)

if err := wait.PollImmediate(t.Interval, t.TimeOut, pollBuildTillRegistration); err != nil {
if err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBuildTillRegistration); err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}

// GetBuildTillMessageContainsSubstring polls until a Build message contains the desired
Expand All @@ -122,11 +122,11 @@ func (t *TestBuild) GetBuildTillRegistration(name string, condition corev1.Condi
func (t *TestBuild) GetBuildTillMessageContainsSubstring(name string, partOfMessage string) (*v1alpha1.Build, error) {

var (
pollBuildTillMessageContainsSubString = func() (bool, error) {
pollBuildTillMessageContainsSubString = func(ctx context.Context) (bool, error) {

bInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)

buildRun, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
buildRun, err := bInterface.Get(ctx, name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -141,9 +141,9 @@ func (t *TestBuild) GetBuildTillMessageContainsSubstring(name string, partOfMess

brInterface := t.BuildClientSet.ShipwrightV1alpha1().Builds(t.Namespace)

if err := wait.PollImmediate(t.Interval, t.TimeOut, pollBuildTillMessageContainsSubString); err != nil {
if err := wait.PollUntilContextTimeout(t.Context, t.Interval, t.TimeOut, true, pollBuildTillMessageContainsSubString); err != nil {
return nil, err
}

return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
return brInterface.Get(t.Context, name, metav1.GetOptions{})
}
6 changes: 2 additions & 4 deletions test/utils/v1alpha1/buildstrategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package utils

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
Expand All @@ -18,7 +16,7 @@ import (
func (t *TestBuild) CreateBuildStrategy(bs *v1alpha1.BuildStrategy) error {
bsInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildStrategies(t.Namespace)

_, err := bsInterface.Create(context.TODO(), bs, metav1.CreateOptions{})
_, err := bsInterface.Create(t.Context, bs, metav1.CreateOptions{})
if err != nil {
return err
}
Expand All @@ -29,5 +27,5 @@ func (t *TestBuild) CreateBuildStrategy(bs *v1alpha1.BuildStrategy) error {
func (t *TestBuild) DeleteBuildStrategy(name string) error {
bsInterface := t.BuildClientSet.ShipwrightV1alpha1().BuildStrategies(t.Namespace)

return bsInterface.Delete(context.TODO(), name, metav1.DeleteOptions{})
return bsInterface.Delete(t.Context, name, metav1.DeleteOptions{})
}
Loading

0 comments on commit 2bc6ffc

Please sign in to comment.