Skip to content

Commit

Permalink
Retry cert creating because of webhook not ready
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz committed Dec 30, 2020
1 parent e9a3ed2 commit 17a6947
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/verify/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func WaitForTestCertificate(ctx context.Context, dynamicClient dynamic.Interface
defer cleanupTestResources(dynamicClient, resources)

for _, res := range resources {
err := createResource(dynamicClient, res)
// we need to retry here because cert-manager webhook might not be ready yet
err := createWithRetry(ctx, res, dynamicClient)
if err != nil {
return err
}
Expand All @@ -52,6 +53,23 @@ func WaitForTestCertificate(ctx context.Context, dynamicClient dynamic.Interface
return wait.PollImmediateUntil(defaultPollInterval, poller.certificateReady, ctx.Done())
}

func createWithRetry(ctx context.Context, res *unstructured.Unstructured, dynamicClient dynamic.Interface) error {
for {
select {
case <-ctx.Done():
return fmt.Errorf("Timeout reached: %v", ctx.Err())
default:
err := createResource(dynamicClient, res)
if err != nil {
logrus.Debugf("Retrying create of resource %s, error: %v\n", res.GetName(), err)
} else {
logrus.Debugf("Resource %s created \n", res.GetName())
return nil
}
}
}
}

type certPoller struct {
dynamicClient dynamic.Interface
certificate *unstructured.Unstructured
Expand Down

0 comments on commit 17a6947

Please sign in to comment.