# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: loadgenerator-env
data:
  LOCUST_HOST: http://FRONTEND_IP_ADDRESS
  LOCUST_USERS: "250"
  LOCUST_SPAWN_RATE: "1"
  LOCUST_LOGLEVEL: error
  LOCUST_WEB_PORT: "8080"
---
apiVersion: v1
kind: Service
metadata:
  name: loadgenerator
spec:
  type: ClusterIP
  selector:
    app: loadgenerator
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: loadgenerator
spec:
  selector:
    matchLabels:
      app: loadgenerator
  replicas: 1
  template:
    metadata:
      labels:
        app: loadgenerator
    spec:
      serviceAccountName: default
      terminationGracePeriodSeconds: 5
      restartPolicy: Always
      securityContext:
        fsGroup: 1000
        runAsGroup: 1000
        runAsNonRoot: true
        runAsUser: 1000
      containers:
      - name: loadgenerator
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
              - all
          privileged: false
          readOnlyRootFilesystem: true
        image: gcr.io/bank-of-anthos-ci/loadgenerator:v0.5.11@sha256:7fa44f9bfefd29eacfd62fed4308b8b057cf454ec1f423106303294e6b2d90e4
        command: [locust, "--autostart"]
        envFrom:
        - configMapRef:
            name: loadgenerator-env
        ports:
        - containerPort: 8080
        readinessProbe:
          httpGet:
            scheme: HTTP
            path: /
            port: 8080
        resources:
          requests:
            cpu: 250m
            memory: 512Mi
            ephemeral-storage: 1Gi
          limits:
            cpu: 250m
            memory: 512Mi
            ephemeral-storage: 1Gi
