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

UpdateOrCreateToken get secrets err handling optimization
This commit is contained in:
Kubernetes Prow Robot 2023-01-12 19:57:12 -08:00 committed by GitHub
commit a66aad2d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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)
} }