---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wrk
  namespace: px-protocol-loadtest
spec:
  replicas: 1
  selector:
    matchLabels:
      name: wrk
  template:
    metadata:
      labels:
        name: wrk
    spec:
      initContainers:
      - name: server-wait
        image: gcr.io/pixie-oss/pixie-dev-public/curl:1.0
        # yamllint disable
        command: ['sh', '-c', 'set -xe;
          URL="${PROTOCOL}://${SERVICE_NAME}:${SERVICE_PORT}${HEALTH_PATH}";
          until [ $(curl -m 0.5 -s -o /dev/null -w "%{http_code}" -k ${URL}) -eq 200 ]; do
            echo "waiting for ${URL}";
            sleep 2;
          done;']
        env:
        - name: SERVICE_NAME
          value: "http-server"
        - name: SERVICE_PORT
          value: "8080"
        - name: HEALTH_PATH
          value: ""
        - name: PROTOCOL
          value: "http"
      containers:
      - name: app
        image: gcr.io/pixie-oss/pixie-dev/experimental/wrk:latest
        # yamllint disable
        command: ['sh', '-c', 'set -xe;
          while true; do
            wrk -t${NUM_THREADS} -c${NUM_CONNECTIONS} -d${DURATION} http://${SERVICE_NAME}:${SERVICE_PORT};
          done;']
        env:
        - name: SERVICE_NAME
          value: "http-server"
        - name: SERVICE_PORT
          value: "8080"
        - name: NUM_CONNECTIONS
          value: "10"
        - name: NUM_THREADS
          value: "10"
        # duration doesn't really matter because the load generator is called in a loop.
        - name: DURATION
          value: "1m"
