# Source: https://raw.githubusercontent.com/Pharb/kubernetes-iperf3/master/iperf3.yaml
---
apiVersion: v1
kind: Namespace
metadata:
  name: iperf3
    {% if rbac["pss"]["pod-security"] == "enabled" and rbac["pss"]["defaults"]["enforce"] == "restricted" %}
  labels:
    pod-security.kubernetes.io/enforce: baseline
    pod-security.kubernetes.io/enforce-version: latest
    pod-security.kubernetes.io/audit: baseline
    pod-security.kubernetes.io/audit-version: latest
    pod-security.kubernetes.io/warn: baseline
    pod-security.kubernetes.io/warn-version: latest
    {% endif %}

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: iperf3-server-deployment
  namespace: iperf3
  labels:
    app: iperf3-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: iperf3-server
  template:
    metadata:
      labels:
        app: iperf3-server
    spec:
      {% if plugins['iperf3']['nodeSelector'] is defined -%}
      nodeSelector:
        {{ plugins['iperf3']['nodeSelector'] | toyaml | indent(width=8, first=False) -}}
      {%- endif %}
      {% if plugins['iperf3']['tolerations'] is defined -%}
      tolerations:
        {{ plugins['iperf3']['tolerations'] | toyaml | indent(width=8, first=False) -}}
      {%- endif %}
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            preference:
              matchExpressions:
              - key: kubernetes.io/role
                operator: In
                values:
                - control-plane
      containers:
      - name: iperf3-server
        image: {% set registry = plugins['iperf3']['installation'].get('registry', '') %}{% if registry | length %}{{ registry }}/{% endif %}networkstatic/iperf3
        args: ['-s']
        ports:
        - containerPort: 5201
          name: server
      terminationGracePeriodSeconds: 0

---

apiVersion: v1
kind: Service
metadata:
  name: iperf3-server
  namespace: iperf3
spec:
  selector:
    app: iperf3-server
  ports:
  - protocol: TCP
    port: 5201
    targetPort: server

---

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: iperf3-clients
  namespace: iperf3
  labels:
    app: iperf3-client
spec:
  selector:
    matchLabels:
      app: iperf3-client
  template:
    metadata:
      labels:
        app: iperf3-client
    spec:
      {% if plugins['iperf3']['nodeSelector'] is defined -%}
      nodeSelector:
        {{ plugins['iperf3']['nodeSelector'] | toyaml | indent(width=8, first=False) -}}
      {%- endif %}
      {% if plugins['iperf3']['tolerations'] is defined -%}
      tolerations:
        {{ plugins['iperf3']['tolerations'] | toyaml | indent(width=8, first=False) -}}
      {%- endif %}
      containers:
      - name: iperf3-client
        image: {% set registry = plugins['iperf3']['installation'].get('registry', '') %}{% if registry | length %}{{ registry }}/{% endif %}networkstatic/iperf3
        command: ['/bin/sh', '-c', 'sleep infinity']
        # To benchmark manually: kubectl exec iperf3-clients-jlfxq -- /bin/sh -c 'iperf3 -c iperf3-server'
      terminationGracePeriodSeconds: 0
