when UpdateOrCreateTokens get secrets, if the error is not a NotFound, the error is thrown in time

Signed-off-by: helen <haitao.zhang@daocloud.io>
This commit is contained in:
helen 2023-01-12 11:52:32 +08:00
parent 14c2d7b39b
commit e6591d24ce

View File

@ -21,6 +21,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
bootstraputil "k8s.io/cluster-bootstrap/token/util" bootstraputil "k8s.io/cluster-bootstrap/token/util"
@ -41,7 +42,10 @@ func UpdateOrCreateTokens(client clientset.Interface, failIfExists bool, tokens
secretName := bootstraputil.BootstrapTokenSecretName(token.Token.ID) secretName := bootstraputil.BootstrapTokenSecretName(token.Token.ID)
secret, err := client.CoreV1().Secrets(metav1.NamespaceSystem).Get(context.TODO(), secretName, metav1.GetOptions{}) 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 errors.Errorf("a token with id %q already exists", token.Token.ID) return errors.Errorf("a token with id %q already exists", token.Token.ID)
} }