---
# Source: locust/templates/master-serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: locust-master
  labels:
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
---
# Source: locust/templates/worker-serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: locust-worker
  labels:
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
---
# Source: locust/templates/configmap-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: locust-config
  labels:
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
data:
  docker-entrypoint.sh: |
    #!/bin/sh

    set -eu

    exec /opt/venv/bin/locust $@
---
# Source: locust/templates/configmap-locust-lib.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-lib
  labels:
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
data:
  __init__.py: |
    # -*- coding: utf-8 -*-
  example_functions.py: |
    # -*- coding: utf-8 -*-
  
    import random
  
  
    def choose_random_page():
        pages = [
            '/api/v1/web/nuvolaris/default/echo0?name=call1',
            '/api/v1/web/nuvolaris/default/echo1?name=call2',
            '/api/v1/web/nuvolaris/default/echo2?name=call3',
            '/api/v1/web/nuvolaris/default/echo3?name=call4',
            '/api/v1/web/nuvolaris/default/echo4?name=call5',
            '/api/v1/web/nuvolaris/default/redis0',
            '/api/v1/web/nuvolaris/default/redis1',
            '/api/v1/web/nuvolaris/default/redis2',
            '/api/v1/web/nuvolaris/default/redis3',
            '/api/v1/web/nuvolaris/default/redis4',
            '/api/v1/web/nuvolaris/default/postgres0',
            '/api/v1/web/nuvolaris/default/postgres1',
            '/api/v1/web/nuvolaris/default/postgres2',
            '/api/v1/web/nuvolaris/default/postgres3',
            '/api/v1/web/nuvolaris/default/postgres4'                        
        ]
  
        return random.choice(pages)
---
# Source: locust/templates/configmap-locust-locustfile.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-locustfile
  labels:
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
data:
  main.py: |
    # -*- coding: utf-8 -*-
  
    from locust import HttpUser, task, between
    from lib.example_functions import choose_random_page
  
    default_headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}
  
  
    class WebsiteUser(HttpUser):
        wait_time = between(1, 2)
  
        @task(1)
        def get_index(self):
            self.client.get("/", headers=default_headers)
  
        @task(3)
        def get_random_page(self):
            self.client.get(choose_random_page(), headers=default_headers)
---
# Source: locust/templates/master-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: locust
  labels:
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
    component: "master"
spec:
  type: ClusterIP
  ports:
  - name: master-p1
    port: 5557
    protocol: TCP
    targetPort: 5557
  - name: master-p2
    port: 5558
    protocol: TCP
    targetPort: 5558
  - name: master-p3
    port: 8089
    protocol: TCP
    targetPort: 8089
  selector:
    component: master
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
---
# Source: locust/templates/master-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: locust-master
  labels:
    component: master
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
spec:
  selector:
    matchLabels:
      component: master
      app.kubernetes.io/name: locust
      app.kubernetes.io/instance: locust
      load_test: example
  replicas: 1
  strategy:
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/config-locust-lib: 11c642231170fa1b5e10aa04c620bd3c99f9608585636773b9db2b15e184ce23
        checksum/config-locust-locustfile: 4eb6e87d2d38fd9804e45d87115499590a0c87768df3032e060d55c5e94a6e45
        checksum/config-config: 6e010ffbb07a7d3337f1fc2f53a8e2b40b3bf4ad494ad819e7c294f13cf4e298
        checksum/config-secret: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
      labels:
        component: master
        app.kubernetes.io/name: locust
        app.kubernetes.io/instance: locust
        load_test: example
        app.kubernetes.io/version: "2.15.1"
    spec:
      securityContext:
        {}
      serviceAccountName: locust-master
      containers:
      - name: locust
        securityContext:
            {}
        image: "locustio/locust:2.15.1"
        command:
        - sh
        - /config/docker-entrypoint.sh
        args:
          - --master
        imagePullPolicy: IfNotPresent
        resources:
          {}
        volumeMounts:
          - name: locustfile
            mountPath: "/mnt/locust"
          - name: lib
            mountPath: "/mnt/locust/lib"
          - name: config
            mountPath: /config
        env:
          - name: LOCUST_HOST
            value: "http://controller.nuvolaris:3233"
          - name: LOCUST_LOGLEVEL
            value: "INFO"
          - name: LOCUST_LOCUSTFILE
            value: "/mnt/locust/main.py"
        ports:
          - containerPort: 8089
            name: loc-master-web
            protocol: TCP
          - containerPort: 5557
            name: loc-master-p1
            protocol: TCP
          - containerPort: 5558
            name: loc-master-p2
            protocol: TCP
        readinessProbe:
          initialDelaySeconds: 5
          periodSeconds: 30
          timeoutSeconds: 30
          failureThreshold: 2
          httpGet:
            path: /
            port: 8089
      restartPolicy: Always
      volumes:
        - name: lib
          configMap:
            name: example-lib
        - name: locustfile
          configMap:
            name: example-locustfile
        - name: config
          configMap:
            name: locust-config
---
# Source: locust/templates/worker-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: locust-worker
  labels:
    component: worker
    app.kubernetes.io/name: locust
    app.kubernetes.io/instance: locust
    load_test: example
    app.kubernetes.io/version: "2.15.1"
spec:
  selector:
    matchLabels:
      component: worker
      app.kubernetes.io/name: locust
      app.kubernetes.io/instance: locust
      load_test: example
  replicas: 5
  strategy:
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/config-locust-lib: 11c642231170fa1b5e10aa04c620bd3c99f9608585636773b9db2b15e184ce23
        checksum/config-locust-locustfile: 4eb6e87d2d38fd9804e45d87115499590a0c87768df3032e060d55c5e94a6e45
        checksum/config-config: 6e010ffbb07a7d3337f1fc2f53a8e2b40b3bf4ad494ad819e7c294f13cf4e298
        checksum/config-secret: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
      labels:
        component: worker
        app.kubernetes.io/name: locust
        app.kubernetes.io/instance: locust
        load_test: example
        app.kubernetes.io/version: "2.15.1"
    spec:
      securityContext:
        {}
      serviceAccountName: locust-worker
      containers:
      - name: locust
        securityContext:
            {}
        image: "locustio/locust:2.15.1"
        command:
        - sh
        - /config/docker-entrypoint.sh
        args:
          - --worker
        imagePullPolicy: IfNotPresent
        resources:
          {}
        volumeMounts:
          - name: locustfile
            mountPath: "/mnt/locust"
          - name: lib
            mountPath: "/mnt/locust/lib"
          - name: config
            mountPath: /config
        env:
          - name: LOCUST_HOST
            value: "http://controller.nuvolaris:3233"
          - name: LOCUST_MASTER_NODE_HOST
            value: "locust"
          - name: LOCUST_MASTER_NODE_PORT
            value: "5557"
          - name: LOCUST_LOGLEVEL
            value: "INFO"
          - name: LOCUST_LOCUSTFILE
            value: "/mnt/locust/main.py"
      restartPolicy: Always
      volumes:
        - name: lib
          configMap:
            name: example-lib
        - name: locustfile
          configMap:
            name: example-locustfile
        - name: config
          configMap:
            name: locust-config
