apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: memcached-mutilate
spec:
  replicas: 0
  serviceName: memcached-mutilate
  podManagementPolicy: Parallel
  selector:
    matchLabels:
      app: memcached-mutilate
  template:
    metadata:
      labels:
        app: memcached-mutilate
    spec:
      terminationGracePeriodSeconds: 0
      nodeSelector:
        goal: service
      containers:
        - name: memcached
          image: memcached
          imagePullPolicy: Always
          envFrom:
            - configMapRef:
                name: memcached
          command:
            - sh
            - -c
            - >
              memcached
              -t $threads
              -m $memory
              -u root
              $extra
        - name: mutilate
          image: mutilate
          imagePullPolicy: Always
          envFrom:
            - configMapRef:
                name: mutilate
          env:
            - name: podname
              valueFrom: {fieldRef: {fieldPath: metadata.name}}
          command:
            - bash
            - -c
            - >
              echo sleeping...;
              sleep 30;
              shopt -s extglob;
              identifier=${podname#mutilate-};
              target='127.0.0.1';
              echo targeting: $target;

              echo loading;
              ./mutilate
              -T 1
              -s ${target}:11211
              --loadonly -r
              $load_records
              -V $value
              -v

              echo started;
              ./mutilate
              -C $conns
              -T $threads
              -t $time
              -s ${target}:11211
              --noload
              --scan $qps:$qps:0
              -r $records
              -V $value
              $extra

  # required for workaround bug with kustomize https://github.com/kubernetes-sigs/kustomize/issues/504
  # when using commonLabels
  # fixed in 2.1.0 https://github.com/kubernetes-sigs/kustomize/commit/c470982ce5b96da82a757f088a842bb05d3bcdb4
  volumeClaimTemplates: []
