apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: client-v1
  template:
    metadata:
      labels:
        app: client-v1
    spec:
      containers:
        - name: client
          image: curlimages/curl:7.72.0
          imagePullPolicy: IfNotPresent
          command: [ "/scripts/client-v1.sh" ]
          ports:
            - containerPort: 8080
              name: http
          env:
            - name: HOST
              valueFrom:
                configMapKeyRef:
                  name: client-v1
                  key: host
            - name: REQUEST_PATH
              valueFrom:
                configMapKeyRef:
                  name: client-v1
                  key: request_path
            - name: METHOD
              valueFrom:
                configMapKeyRef:
                  name: client-v1
                  key: method
            - name: HEADERS
              valueFrom:
                configMapKeyRef:
                  name: client-v1
                  key: headers
          volumeMounts:
            - name: client-v1
              mountPath: /scripts
      volumes:
        - name: client-v1
          configMap:
            name: client-v1
            defaultMode: 0755
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: client-v1
data:
  host: http://dest-svc:8080
  request_path: /configuration-v1
  method: POST
  headers: x-demo:true
  client-v1.sh: |
    #!/bin/sh

    host="${HOST:-http://localhost:8080}"
    request_path="${REQUEST_PATH:-/echo}"
    method="${METHOD:-GET}"
    headers=${HEADERS}

    echo "Configuration:"
    echo "  HOST:         ${host}"
    echo "  REQUEST_PATH: ${request_path}"
    echo "  METHOD:       ${method}"
    echo "  HEADERS:      ${headers}"

    header_array=`echo $headers | sed -e 's/,/ /g'`

    start_delay=10
    echo -n "Starting in "
    echo -n "$start_delay "
    echo -n "seconds"

    i=0
    while [[ $i -lt $start_delay ]]
    do
      echo -n "."
      i=`expr $i + 1`
      sleep 1
    done
    echo

    cmd="curl -s "
    for h in $header_array
    do
      cmd=$cmd" -H \"$h\""
    done
    cmd=$cmd" -X ${method} ${host}${request_path}"

    while true
    do
      eval $cmd
      echo -e "\n"
      sleep 1
    done
