Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eks/*: allow duplicate create calls #133

Closed
wants to merge 1 commit into from
Closed

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented Jul 20, 2020

c.f. #123

@gyuho
Copy link
Contributor Author

gyuho commented Jul 20, 2020

On second thought, this kind of change is getting too manual... Seems better to go with generic wrapper for Create + Update calls:

https://github.com/aws/aws-k8s-tester/blob/master/pkg/k8s-client/k8s.go#L206-L225

// CreateNamespace creates a single namespace with given name.
func CreateNamespace(lg *zap.Logger, c clientset.Interface, namespace string) error {
createFunc := func() error {
lg.Info("creating namespace", zap.String("namespace", namespace))
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
_, err := c.CoreV1().Namespaces().Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
cancel()
if err == nil {
lg.Info("created namespace", zap.String("namespace", namespace))
return nil
}
if apierrs.IsAlreadyExists(err) {
lg.Info("namespace already exists", zap.String("namespace", namespace), zap.Error(err))
return nil
}
lg.Warn("failed to create namespace", zap.String("namespace", namespace), zap.Error(err))
return err
}
return RetryWithExponentialBackOff(RetryFunction(createFunc, Allow(apierrs.IsAlreadyExists)))
}

@gyuho gyuho closed this Jul 28, 2020
@gyuho gyuho deleted the apiserrs branch July 28, 2020 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant