#
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

apiVersion: apps/v1
kind: Deployment
metadata:
  name: loadgen
  namespace: microservices-aws
spec:
  selector:
    matchLabels:
      app: loadgen
  replicas: 1
  template:
    metadata:
      labels:
        app: loadgen
    spec:
      terminationGracePeriodSeconds: 5
      restartPolicy: Always
      initContainers:
      - name: wait-frontend
        image: alpine:latest
        command: ['sh', '-c', 'set -x;  apk add --no-cache curl; 
          until timeout 2 curl -f "http://${FRONTEND_ADDR}"; do 
            echo "waiting for http://${FRONTEND_ADDR}"; 
            sleep 2;
          done;']
        env:
        - name: FRONTEND_ADDR
          value: "frontend"
        resources:
          requests:
            cpu: 100m
            memory: 32Mi
          limits:
            cpu: 100m
            memory: 64Mi
      containers:
      - name: loadtester
        image: ckassen/loadgen:latest
        env:
        - name: FRONTEND_ADDR
          value: "frontend"
        - name: USERS
          value: "2"
        resources:
          requests:
            cpu: 128m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 256Mi
