Skip to content

Commit

Permalink
Merge pull request #1430 from alvaroaleman/deflake
Browse files Browse the repository at this point in the history
🐛 Deflake should update CRDs if already present in the cluster
  • Loading branch information
k8s-ci-robot committed Mar 16, 2021
2 parents df2c43d + 7dc9c0f commit 82c68b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/envtest/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
Expand Down Expand Up @@ -266,8 +267,13 @@ func CreateCRDs(config *rest.Config, crds []client.Object) error {
return err
default:
log.V(1).Info("CRD already exists, updating", "crd", crd.GetName())
crd.SetResourceVersion(existingCrd.GetResourceVersion())
if err := cs.Update(context.TODO(), crd); err != nil {
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
if err := cs.Get(context.TODO(), client.ObjectKey{Name: crd.GetName()}, existingCrd); err != nil {
return err
}
crd.SetResourceVersion(existingCrd.GetResourceVersion())
return cs.Update(context.TODO(), crd)
}); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/envtest/envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var _ = Describe("Test", func() {
Eventually(func() bool {
err := c.Get(context.TODO(), crdObjectKey, &placeholder)
return apierrors.IsNotFound(err)
}, 1*time.Second).Should(BeTrue())
}, 5*time.Second).Should(BeTrue())
}
close(done)
}, teardownTimeoutSeconds)
Expand Down

0 comments on commit 82c68b9

Please sign in to comment.