{{$Memory := DefaultParam .Memory "1000M"}}
{{$CPU := DefaultParam .CPU "--millicores=100"}}
{{$MemoryRequest := DefaultParam .MemoryRequest "1000Ki"}}
{{$CPURequest := DefaultParam .CPURequest "100m"}}
{{$LoadType := DefaultParam .LoadType "memory"}}
{{$Provider := DefaultParam .Provider "aks"}}

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{.Name}}
  labels:
    group: {{.Group}}
spec:
  replicas: {{.Replicas}}
  selector:
    matchLabels:
      name: {{.Name}}
  template:
    metadata:
      labels:
        name: {{.Name}}
        group: {{.Group}}
    spec:
      hostNetwork: true
      nodeSelector:
        cri-resource-consume: "true"
      containers:
{{if eq $LoadType "memory"}}
      - name: resource-consumer-memory
{{if eq $Provider "aks"}}
        image: akscritelescope.azurecr.io/e2e-test-images/resource-consumer:1.9
{{else}}
        image: registry.k8s.io/e2e-test-images/resource-consumer:1.9
{{end}}
        imagePullPolicy: IfNotPresent
        command:
          - stress
        args:
          - --vm
          - "1"
          - --vm-bytes
          - {{$Memory}}
          - --vm-hang
          - "0"
          - --timeout
          - "3600"
        resources:
          requests:
            memory: {{$MemoryRequest}}
{{end}}
{{if eq $LoadType "cpu"}}
      - name: resource-consumer-cpu
{{if eq $Provider "aks"}}
        image: akscritelescope.azurecr.io/e2e-test-images/resource-consumer:1.9
{{else}}
        image: registry.k8s.io/e2e-test-images/resource-consumer:1.9
{{end}}
        imagePullPolicy: IfNotPresent
        command:
          - ./consume-cpu/consume-cpu
        args:
          - --duration-sec=3600
          - {{$CPU}}
        resources:
          requests:
            cpu: {{$CPURequest}}
{{end}}
      tolerations:
      - key: "cri-resource-consume"
        operator: "Equal"
        value: "true"
        effect: "NoSchedule"
      - key: "cri-resource-consume"
        operator: "Equal"
        value: "true"
        effect: "NoExecute"
