apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: hawkular-openshift-agent
  labels:
    name: hawkular-openshift-agent
    metrics-infra: agent
  namespace: {{openshift_metrics_hawkular_agent_namespace}}
spec:
  selector:
    matchLabels:
      name: hawkular-openshift-agent
  template:
    metadata:
      labels:
        name: hawkular-openshift-agent
        metrics-infra: agent
    spec:
      serviceAccount: hawkular-openshift-agent
{% if node_selector is iterable and node_selector | length > 0 %}
      nodeSelector:
{% for key, value in node_selector.items() %}
        {{key}}: "{{value}}"
{% endfor %}
{% endif %}
      containers:
      - image: {{ openshift_metrics_hawkular_agent_image }}
        imagePullPolicy: IfNotPresent
        name: hawkular-openshift-agent
{% if ((openshift_metrics_hawkular_agent_limits_cpu is defined and openshift_metrics_hawkular_agent_limits_cpu is not none)
   or (openshift_metrics_hawkular_agent_limits_memory is defined and openshift_metrics_hawkular_agent_limits_memory is not none)
   or (openshift_metrics_hawkular_agent_requests_cpu is defined and openshift_metrics_hawkular_agent_requests_cpu is not none)
   or (openshift_metrics_hawkular_agent_requests_memory is defined and openshift_metrics_hawkular_agent_requests_memory is not none))
%}
        resources:
{% if (openshift_metrics_hawkular_agent_limits_cpu is not none
   or openshift_metrics_hawkular_agent_limits_memory is not none)
%}
          limits:
{% if openshift_metrics_hawkular_agent_limits_cpu is not none %}
            cpu: "{{openshift_metrics_hawkular_agent_limits_cpu}}"
{% endif %}
{% if openshift_metrics_hawkular_agent_limits_memory is not none %}
            memory: "{{openshift_metrics_hawkular_agent_limits_memory}}"
{% endif %}
{% endif %}
{% if (openshift_metrics_hawkular_agent_requests_cpu is not none
   or openshift_metrics_hawkular_agent_requests_memory is not none)
%}
          requests:
{% if openshift_metrics_hawkular_agent_requests_cpu is not none %}
            cpu: "{{openshift_metrics_hawkular_agent_requests_cpu}}"
{% endif %}
{% if openshift_metrics_hawkular_agent_requests_memory is not none %}
            memory: "{{openshift_metrics_hawkular_agent_requests_memory}}"
{% endif %}
{% endif %}
{% endif %}

        livenessProbe:
          httpGet:
            scheme: HTTP
            path: /health
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 30
        command:
          - "hawkular-openshift-agent"
          - "-config"
          - "/hawkular-openshift-agent-configuration/config.yaml"
          - "-v"
          - "3"
        env:
        - name: K8S_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: K8S_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        volumeMounts:
        - name: hawkular-openshift-agent-configuration
          mountPath: "/hawkular-openshift-agent-configuration"
      volumes:
      - name: hawkular-openshift-agent-configuration
        configMap:
          name: hawkular-openshift-agent-configuration
      - name: hawkular-openshift-agent
        configMap:
          name: hawkular-openshift-agent-configuration
