{{$HostNetworkMode := DefaultParam .CL2_USE_HOST_NETWORK_PODS false}}
{{$Image := DefaultParam .Image "registry.k8s.io/pause:3.9"}}
{{$Env := DefaultParam .Env ""}}
{{$DaemonSetSurge := DefaultParam .CL2_DS_SURGE (MaxInt 10 (DivideInt .Nodes 20))}} # 5% of nodes, but not less than 10
{{$RUN_ON_ARM_NODES := DefaultParam .CL2_RUN_ON_ARM_NODES false}}

{{$ENABLE_NETWORK_POLICY_ENFORCEMENT_LATENCY_TEST := DefaultParam .CL2_ENABLE_NETWORK_POLICY_ENFORCEMENT_LATENCY_TEST false}}
{{$NET_POLICY_ENFORCEMENT_LATENCY_NODE_LABEL_VALUE := DefaultParam .CL2_NET_POLICY_ENFORCEMENT_LATENCY_NODE_LABEL_VALUE "net-policy-client"}}

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{.Name}}
  labels:
    group: load
spec:
  updateStrategy:
    rollingUpdate:
      maxUnavailable: {{$DaemonSetSurge}}
  selector:
    matchLabels:
      name: {{.Name}}
  template:
    metadata:
      labels:
        group: load
        name: {{.Name}}
    spec:
      hostNetwork: {{$HostNetworkMode}}
      containers:
      - name: {{.Name}}
        image: {{$Image}}
        env:
          - name: TEST_ENV
            value: {{$Env}}
        resources:
          # Keep the CpuRequest/MemoryRequest request equal percentage of 1-core, 4GB node.
          # For now we're setting it to 0.5%.
          requests:
            cpu: 5m
            memory: "20M"
      priorityClassName: daemonset-priorityclass-0 # Name is autogenerated, hence the -0 prefix.
      terminationGracePeriodSeconds: 1
      tolerations:
      {{if $RUN_ON_ARM_NODES}}
      - key: "kubernetes.io/arch"
        operator: Equal
        value: arm64
        effect: NoSchedule
      {{end}}
      {{if $ENABLE_NETWORK_POLICY_ENFORCEMENT_LATENCY_TEST}}
      - key: test-np
        operator: Equal
        value: {{$NET_POLICY_ENFORCEMENT_LATENCY_NODE_LABEL_VALUE}}
        effect: NoSchedule
      {{end}}
