apiVersion: v1
kind: Service
metadata:
  name: minio-service
  labels:
    app: minio
    app.kubernetes.io/name: {{ .Release.Name }}
spec:
  ports:
    - port: 9000
      protocol: TCP
      targetPort: 9000
  selector:
    app: minio
    app.kubernetes.io/name: {{ .Release.Name }}
---
apiVersion: v1
kind: Secret
metadata:
  name: mlpipeline-minio-artifact
stringData:
  accesskey: minio
  secretkey: minio123
---
{{ if .Values.managedstorage.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  labels:
    app: minio
    app.kubernetes.io/name: {{ .Release.Name }}
spec:
  selector:
    matchLabels:
      app: minio
      app.kubernetes.io/name: {{ .Release.Name }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: minio
        app.kubernetes.io/name: {{ .Release.Name }}
    spec:
      containers:
        - args:
            - gateway
            - gcs
            - $(PROJECT_ID)
          env:
            - name: PROJECT_ID
              valueFrom:
                configMapKeyRef:
                  name: "{{ .Values.gcpDefaultConfigName }}"
                  key: "project_id"
            - name: MINIO_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: mlpipeline-minio-artifact
                  key: accesskey
            - name: MINIO_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: mlpipeline-minio-artifact
                  key: secretkey
            # Minio is KFP system workload and we use GCE's default service account
            # or later Workload Identity's corresponding service account.
            # So here no need to setup GOOGLE_APPLICATION_CREDENTIALS.
            # - name: GOOGLE_APPLICATION_CREDENTIALS
            #  value: "/etc/credentials/application_default_credentials.json"
          image: {{ .Values.images.minio }}
          name: minio
          ports:
            - containerPort: 9000
          resources:
            requests:
              cpu: 20m
              memory: 100Mi
{{ end }}
---
{{ if not .Values.managedstorage.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minio-pvc
  labels:
    app.kubernetes.io/name: {{ .Release.Name }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  labels:
    app: minio
    app.kubernetes.io/name: {{ .Release.Name }}
spec:
  selector:
    matchLabels:
      app: minio
      app.kubernetes.io/name: {{ .Release.Name }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: minio
        app.kubernetes.io/name: {{ .Release.Name }}
    spec:
      containers:
        - args:
            - server
            - /data
          env:
            - name: MINIO_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: mlpipeline-minio-artifact
                  key: accesskey
            - name: MINIO_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: mlpipeline-minio-artifact
                  key: secretkey
          image: {{ .Values.images.minio }}
          name: minio
          ports:
            - containerPort: 9000
          volumeMounts:
            - mountPath: /data
              name: data
              subPath: minio
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: minio-pvc
{{ end }}
