Skip to content

Commit

Permalink
[Access-tokens][ClusterLoader2] Add standalone test
Browse files Browse the repository at this point in the history
Add standalone test for ClusterLoader2 that allows benchmarking and
testing access tokens thresholds.

This test is based on Mateusz's code from github.com/mm4tt/k8s-util.
  • Loading branch information
jprzychodzen committed Feb 6, 2020
1 parent 213b876 commit 6b07414
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 0 deletions.
137 changes: 137 additions & 0 deletions clusterloader2/testing/access-tokens/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Stress testing access token validation
#
# Targeting 2 000 tokens with 20 000 total QPS for 5k node cluster, so 10 QPS per token.
# For smaller cluster, we want to scale down lineary QPS per token to 10 * (Number of nodes)/(5 000).
#
# Number of tokens = ${namespaces} * ${serviceAccounts} * ${tokensPerServiceAccount}
# Total QPS = Number of tokens * ${replicas} * ${qpsPerWorker}
#
# For default values in 5k cluster this means:
# Number of tokens = 1 * 80 * 25 = 2000
# Total QPS = 2000 * 1 * 10 = 20000
{{$namespaces := DefaultParam .CL2_ACCESS_TOKENS_NAMESPACES 1}}
{{$serviceAccounts := DefaultParam .CL2_ACCESS_TOKENS_SERVICE_ACCOUNTS 80}}
{{$tokensPerServiceAccount := DefaultParam .CL2_ACCESS_TOKENS_TOKENS_PER_SERVICE_ACCOUNT 25}}
{{$replicas := DefaultParam .CL2_ACCESS_TOKENS_REPLICAS 1}}
{{$qpsPerWorker := DefaultParam .CL2_ACCESS_TOKENS_QPS (MultiplyFloat 10 (DivideFloat .Nodes 5000))}}

name: access-tokens
automanagedNamespaces: {{$namespaces}}
tuningSets:
- name: Sequence
parallelismLimitedLoad:
parallelismLimit: 1
steps:
- name: Starting measurements
measurements:
- Identifier: APIResponsivenessPrometheus
Method: APIResponsivenessPrometheus
Params:
action: start

- name: Creating ServiceAccounts
phases:
- namespaceRange:
min: 1
max: {{$namespaces}}
replicasPerNamespace: 1
tuningSet: Sequence
objectBundle:
- basename: service-account-getter
objectTemplatePath: role.yaml
- namespaceRange:
min: 1
max: {{$namespaces}}
replicasPerNamespace: {{$serviceAccounts}}
tuningSet: Sequence
objectBundle:
- basename: account
objectTemplatePath: serviceAccount.yaml
- basename: account
objectTemplatePath: roleBinding.yaml
templateFillMap:
RoleName: service-account-getter

- name: Creating Tokens
phases:
{{range $i := Loop $serviceAccounts}}
- namespaceRange:
min: 1
max: {{$namespaces}}
replicasPerNamespace: {{$tokensPerServiceAccount}}
tuningSet: Sequence
objectBundle:
- basename: account-{{$i}}
objectTemplatePath: token.yaml
{{end}}


- name: Starting measurement for waiting for pods
measurements:
- Identifier: WaitForRunningPods
Method: WaitForControlledPodsRunning
Params:
action: start
apiVersion: apps/v1
kind: Deployment
labelSelector: group = access-tokens
operationTimeout: 15m

- name: Creating pods
phases:
- namespaceRange:
min: 1
max: {{$namespaces}}
replicasPerNamespace: {{$serviceAccounts}}
tuningSet: Sequence
objectBundle:
- basename: account
objectTemplatePath: deployment.yaml
templateFillMap:
QpsPerWorker: {{$qpsPerWorker}}
Replicas: {{$replicas}}
Tokens: {{$tokensPerServiceAccount}}

- name: Waiting for pods to be running
measurements:
- Identifier: WaitForRunningPods
Method: WaitForControlledPodsRunning
Params:
action: gather

- name: Wait 5min
measurements:
- Identifier: Wait
Method: Sleep
Params:
duration: 5m

- name: Deleting pods
phases:
- namespaceRange:
min: 1
max: {{$namespaces}}
replicasPerNamespace: 0
tuningSet: Sequence
objectBundle:
- basename: account
objectTemplatePath: deployment.yaml
templateFillMap:
QpsPerWorker: {{$qpsPerWorker}}
Replicas: {{$replicas}}
Tokens: {{$tokensPerServiceAccount}}

- name: Waiting for pods to be deleted
measurements:
- Identifier: WaitForRunningPods
Method: WaitForControlledPodsRunning
Params:
action: gather

- name: Collecting measurements
measurements:
- Identifier: APIResponsivenessPrometheus
Method: APIResponsivenessPrometheus
Params:
action: gather
enableViolations: true
45 changes: 45 additions & 0 deletions clusterloader2/testing/access-tokens/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{$name := .Name}}

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.Name}}
labels:
group: access-tokens
spec:
selector:
matchLabels:
group: access-tokens
name: {{.Name}}
replicas: {{.Replicas}}
template:
metadata:
labels:
group: access-tokens
name: {{.Name}}
spec:
imagePullPolicy: Always
containers:
- name: access-tokens
image: gcr.io/k8s-testimages/perf-tests-util/access-tokens:v0.0.6
args:
{{range $tokenId := Loop .Tokens}}
- --access-token-dirs=/var/tokens/{{$name}}-{{$tokenId}}
{{end}}
- --namespace={{.Namespace}}
- --qps-per-worker={{.QpsPerWorker}}
resources:
requests:
cpu: {{AddInt 10 (MultiplyFloat .Tokens .QpsPerWorker)}}m # 1mCpu per Token * per QPS
memory: {{AddInt 50 (MultiplyInt .Tokens 5)}}Mi
volumeMounts:
{{range $j := Loop .Tokens}}
- name: {{$name}}-{{$j}}
mountPath: /var/tokens/{{$name}}-{{$j}}
{{end}}
volumes:
{{range $j := Loop .Tokens}}
- name: {{$name}}-{{$j}}
secret:
secretName: {{$name}}-{{$j}}
{{end}}
11 changes: 11 additions & 0 deletions clusterloader2/testing/access-tokens/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{.Name}}
rules:
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- get
12 changes: 12 additions & 0 deletions clusterloader2/testing/access-tokens/roleBinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{.Name}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{.RoleName}}-0
subjects:
- kind: ServiceAccount
name: {{.Name}}
namespace: {{.Namespace}}
4 changes: 4 additions & 0 deletions clusterloader2/testing/access-tokens/serviceAccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{.Name}}
7 changes: 7 additions & 0 deletions clusterloader2/testing/access-tokens/token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{.Name}}
annotations:
kubernetes.io/service-account.name: {{.BaseName}}
type: kubernetes.io/service-account-token

0 comments on commit 6b07414

Please sign in to comment.