Merge pull request #3040 from helen-frank/feature/UpdateOrCreateTokenAddErrProcessing

UpdateOrCreateToken get secrets err handling optimization
This commit is contained in:
karmada-bot 2023-01-13 09:40:05 +08:00 committed by GitHub
commit d02a4eed11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import (
"time"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
kubeclient "k8s.io/client-go/kubernetes"
@ -318,7 +319,10 @@ func CreateNewToken(client kubeclient.Interface, token *BootstrapToken) error {
func UpdateOrCreateToken(client kubeclient.Interface, failIfExists bool, token *BootstrapToken) error {
secretName := bootstraputil.BootstrapTokenSecretName(token.Token.ID)
secret, err := client.CoreV1().Secrets(metav1.NamespaceSystem).Get(context.TODO(), secretName, metav1.GetOptions{})
if secret != nil && err == nil && failIfExists {
if err != nil && !apierrors.IsNotFound(err) {
return err
}
if secret != nil && failIfExists {
return fmt.Errorf("a token with id %q already exists", token.Token.ID)
}