Skip to content

Commit

Permalink
Add retry logic to namespace creation
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
  • Loading branch information
rsevilla87 committed Mar 30, 2021
1 parent 0dc008e commit 0105eaa
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pkg/burner/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package burner

import (
"context"
"fmt"
"time"

"github.com/cloud-bulldozer/kube-burner/log"
Expand All @@ -32,16 +31,22 @@ func createNamespace(clientset *kubernetes.Clientset, namespaceName string, nsLa
ns := v1.Namespace{
ObjectMeta: metav1.ObjectMeta{Name: namespaceName, Labels: nsLabels},
}
log.Infof("Creating namespace %s", ns.Name)
_, err := clientset.CoreV1().Namespaces().Create(context.TODO(), &ns, metav1.CreateOptions{})
if errors.IsForbidden(err) {
log.Fatalf("Authorization error creating namespace %s: %s", ns.Name, err)
}
if errors.IsAlreadyExists(err) {
log.Warnf("Namespace %s already exists", ns.Name)
} else if err != nil {
return fmt.Errorf("Unexpected error creating namespace: %s", err)
}
RetryWithExponentialBackOff(func() (done bool, err error) {
_, err = clientset.CoreV1().Namespaces().Create(context.TODO(), &ns, metav1.CreateOptions{})
if errors.IsForbidden(err) {
log.Fatalf("Authorization error creating namespace %s: %s", ns.Name, err)
return false, err
}
if errors.IsAlreadyExists(err) {
log.Warnf("Namespace %s already exists", ns.Name)
return true, err
} else if err != nil {
log.Errorf("Unexpected error creating namespace %s: %s", ns.Name, err)
return false, err
}
log.Infof("Created namespace: %s", ns.Name)
return true, err
})
return nil
}

Expand Down

0 comments on commit 0105eaa

Please sign in to comment.