---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: minio
  annotations:
    keel.sh/policy: force
    keel.sh/trigger: poll
    keel.sh/pollSchedule: "@midnight"
spec:
  revisionHistoryLimit: 0
  serviceName: minio
  selector:
    matchLabels:
      app: minio
  replicas: 1
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
      - name: minio
        image: minio/minio:latest
        command: ["minio"]
        ports:
        - name: minio
          containerPort: 9000
        - name: minio-console
          containerPort: 9001
        args: ["server", "/data", "--console-address", ":9001"]
        env:
        - name: MINIO_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: minio-secrets
              key: MINIO_ROOT_PASSWORD
        - name: MINIO_ROOT_USER
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
        - mountPath: /data
          name: minio-data

      # Make sure Minio instances run on storage{1..3} nodes, as close
      # as possible to Longhorn instances
      tolerations:
      - key: dedicated
        operator: Equal
        value: storage
        effect: NoSchedule
      nodeSelector:
        dedicated: storage

  volumeClaimTemplates:
  - metadata:
      name: minio-data
    spec:
      storageClassName: longhorn
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 50Gi
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  annotations:
    prometheus.io/scrape: 'true'
spec:
  ports:
    - protocol: TCP
      port: 9000
  selector:
    app: minio
---
apiVersion: v1
kind: Service
metadata:
  name: minio-console
spec:
  ports:
    - protocol: TCP
      port: 9001
  selector:
    app: minio