apiVersion: apps/v1
kind: DaemonSet
metadata:
  namespace: mayastor
  name: mayastor
  labels:
    openebs/engine: mayastor
spec:
  selector:
    matchLabels:
      app: mayastor
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  minReadySeconds: 10
  template:
    metadata:
      labels:
        app: mayastor
    spec:
      hostNetwork: true
      # To resolve services from mayastor namespace
      dnsPolicy: ClusterFirstWithHostNet
      nodeSelector:
        openebs.io/engine: mayastor
        kubernetes.io/arch: amd64
      # NOTE: Each container must have mem/cpu limits defined in order to
      # belong to Guaranteed QoS class, hence can never get evicted in case of
      # pressure unless they exceed those limits. limits and requests must be
      # the same.
      initContainers:
      - name: message-bus-probe
        image: busybox:latest
        command: ['sh', '-c', 'until nc -vz nats 4222; do echo "Waiting for message bus..."; sleep 1; done;']
      containers:
        - name: mayastor
          image: mayadata/mayastor:latest
          imagePullPolicy: Always
          env:
            - name: MY_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: IMPORT_NEXUSES
              value: "false"
          args:
            - "-N$(MY_NODE_NAME)"
            - "-g$(MY_POD_IP)"
            - "-nnats"
            - "-y/var/local/mayastor/config.yaml"
            - "-C/var/local/mayastor/child-status-config.yaml"
          securityContext:
            privileged: true
          volumeMounts:
            - name: device
              mountPath: /dev
            - name: dshm
              mountPath: /dev/shm
            - name: configlocation
              mountPath: /var/local/mayastor/
            - name: config
              mountPath: /var/local/mayastor/config.yaml
            - name: child-status-config
              mountPath: /var/local/mayastor/child-status-config.yaml
          resources:
            limits:
              cpu: "1"
              memory: "512Mi"
              hugepages-2Mi: "1Gi"
            requests:
              cpu: "1"
              memory: "512Mi"
              hugepages-2Mi: "1Gi"
          ports:
            - containerPort: 10124
              protocol: TCP
              name: mayastor
      volumes:
        - name: device
          hostPath:
            path: /dev
            type: Directory
        - name: dshm
          emptyDir:
            medium: Memory
            sizeLimit: "1Gi"
        - name: hugepage
          emptyDir:
            medium: HugePages
        - name: configlocation
          hostPath:
            path: /var/local/mayastor/
            type: DirectoryOrCreate
        - name: config
          hostPath:
            path: /var/local/mayastor/config.yaml
            type: FileOrCreate
        - name: child-status-config
          hostPath:
            path: /var/local/mayastor/child-status-config.yaml
            type: FileOrCreate
