Retry on conflicts when labeling namespaces in tests
We're seeing this error:
```
broker_test_helper.go:216: Error annotating namespace: Operation cannot be fulfilled on namespaces "eventing-e2e7": the object has been modified; please apply your changes to the latest version and try again
```
@@ -23,16 +23,19 @@ import (
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/client-go/util/retry"
pkgTest "knative.dev/pkg/test"
+ duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
+
"knative.dev/eventing/test/lib/duck"
"knative.dev/eventing/test/lib/resources"
- duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)
// LabelNamespace labels the given namespace with the labels map.
func (c *Client) LabelNamespace(labels map[string]string) error {
namespace := c.Namespace
+ err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
nsSpec, err := c.Kube.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
if err != nil {
return err
@@ -45,6 +48,8 @@ func (c *Client) LabelNamespace(labels map[string]string) error {
}
_, err = c.Kube.CoreV1().Namespaces().Update(context.Background(), nsSpec, metav1.UpdateOptions{})
return err
+ })
+ return err
}
// GetAddressableURI returns the URI of the addressable resource.
