resource "kubectl_manifest" "DaemonSet_whereabouts" {
  yaml_body  = <<-EOF
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: whereabouts
      namespace: ${var.namespace}
      labels: ${jsonencode(local.common-labels)}
      ownerReferences: ${jsonencode(var.install_owner)}
    spec:
      selector:
        matchLabels:
          name: whereabouts
      updateStrategy:
        type: RollingUpdate
      template:
        metadata:
          labels:
            tier: node
            app: whereabouts
            name: whereabouts
        spec:
          hostNetwork: true
          serviceAccountName: whereabouts
          tolerations:
          - operator: Exists
            effect: NoSchedule
          containers:
          - name: whereabouts
            command:
            - /bin/sh
            args:
            - -c
            - |
              SLEEP=false /install-cni.sh && /ip-control-loop -log-level debug
            image: ${var.images.operator.registry}/${var.images.operator.repository}:${var.images.operator.tag}
            imagePullPolicy: ${var.images.operator.pull_policy}
            env:
            - name: NODENAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
            - name: WHEREABOUTS_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            resources:
              requests:
                cpu: 100m
                memory: 100Mi
              limits:
                cpu: 100m
                memory: 200Mi
            securityContext:
              privileged: true
            volumeMounts:
            - name: cnibin
              mountPath: /host/opt/cni/bin
            - name: cni-net-dir
              mountPath: /host/etc/cni/net.d
            - name: cron-scheduler-configmap
              mountPath: /cron-schedule
          volumes:
          - name: cnibin
            hostPath:
              path: ${var.cni.bin_dir}
          - name: cni-net-dir
            hostPath:
              path: ${var.cni.conf_dir}
          - name: cron-scheduler-configmap
            configMap:
              name: whereabouts-config
              defaultMode: 0744
              items:
              - key: cron-expression
                path: config
EOF
}

