Skip to content

Commit

Permalink
[Access-tokens] Update access-tokens to version v0.0.6
Browse files Browse the repository at this point in the history
Changelog:
* Remove client rate limiter
* Make requests cheaper with  ResourceVersion:0
* Make worker asynchronus
  • Loading branch information
jprzychodzen committed Feb 4, 2020
1 parent 3db5e04 commit 8c45705
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion util-images/access-tokens/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT ?= k8s-testimages
IMG = gcr.io/$(PROJECT)/perf-tests-util/access-tokens
TAG = v0.0.5
TAG = v0.0.6

all: push

Expand Down
21 changes: 14 additions & 7 deletions util-images/access-tokens/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
certutil "k8s.io/client-go/util/cert"
flowcontrol "k8s.io/client-go/util/flowcontrol"
"k8s.io/klog"
)

Expand Down Expand Up @@ -68,17 +69,21 @@ func initFlagsAndKlog() {
flag.Parse()
}

func makeRequest(id int, client kubernetes.Interface) {
klog.V(4).Infof("Worker %v sends request\n", id)
svcAccount, err := client.CoreV1().ServiceAccounts(*namespace).Get("default", metav1.GetOptions{ResourceVersion: "0"})
if err != nil {
klog.Warningf("Got error when getting default svcAccount: %v", err)
} else {
klog.V(4).Infof("Worker %v fetched %s svcAccount in namespace %s\n", id, svcAccount.Name, svcAccount.Namespace)
}
}

func worker(id int, client kubernetes.Interface, qps float64) {
duration := time.Duration(float64(int64(time.Second)) / qps)
ticker := time.NewTicker(duration)
for {
klog.V(4).Infof("Worker %v sends request\n", id)
svcAccount, err := client.CoreV1().ServiceAccounts(*namespace).Get("default", metav1.GetOptions{})
if err != nil {
klog.Warningf("Got error when getting default svcAccount: %v", err)
} else {
klog.V(4).Infof("Worker %v fetched %s svcAccount in namespace %s\n", id, svcAccount.Name, svcAccount.Namespace)
}
go makeRequest(id, client)
<-ticker.C
}
}
Expand All @@ -103,5 +108,7 @@ func newConfig(tokenFile, rootCAFile string) (*rest.Config, error) {
TLSClientConfig: tlsClientConfig,
BearerToken: string(token),
BearerTokenFile: tokenFile,
// We are already rate limiting in func worker - we do not need another limiter here
RateLimiter: flowcontrol.NewFakeAlwaysRateLimiter(),
}, nil
}
2 changes: 1 addition & 1 deletion util-images/access-tokens/example/example.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ spec:
image: gcr.io/${PROJECT}/perf-tests-util/access-tokens:latest
args:
- --access-token-dirs=/var/tokens/access-token
- --qps-per-worker=1
- --qps-per-worker=10
- --namespace=access-tokens
resources:
limits:
Expand Down

0 comments on commit 8c45705

Please sign in to comment.