mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Add a RateLimiter for the gce altTokenSource.
This commit is contained in:
parent
66d2e1cb92
commit
be0d24824d
@ -21,17 +21,28 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
"code.google.com/p/google-api-go-client/googleapi"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
const (
|
||||
// Max QPS to allow through to the token URL.
|
||||
tokenURLQPS = 1
|
||||
// Maximum burst of requests to token URL before limiting.
|
||||
tokenURLBurst = 3
|
||||
)
|
||||
|
||||
type altTokenSource struct {
|
||||
oauthClient *http.Client
|
||||
tokenURL string
|
||||
throttle util.RateLimiter
|
||||
}
|
||||
|
||||
func (a *altTokenSource) Token() (*oauth2.Token, error) {
|
||||
a.throttle.Accept()
|
||||
req, err := http.NewRequest("GET", a.tokenURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -62,6 +73,7 @@ func newAltTokenSource(tokenURL string) oauth2.TokenSource {
|
||||
a := &altTokenSource{
|
||||
oauthClient: client,
|
||||
tokenURL: tokenURL,
|
||||
throttle: util.NewTokenBucketRateLimiter(tokenURLQPS, tokenURLBurst),
|
||||
}
|
||||
return oauth2.ReuseTokenSource(nil, a)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user