mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #115000 from helen-frank/feature/UpdateOrCreateTokenAddErrProcessing
UpdateOrCreateToken get secrets err handling optimization
This commit is contained in:
commit
a66aad2d80
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user