apiVersion: v1
data:
  MYSQL_ROOT_PASSWORD: {{ .Values.katib.db.password | b64enc | quote }}
kind: Secret
metadata:
  name: katib-db-secrets
  namespace: kubeflow
type: Opaque
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: katib
    component: db
  name: katib-db
  namespace: kubeflow
spec:
  ports:
  - name: dbapi
    port: 3306
    protocol: TCP
  selector:
    app: katib
    component: db
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: katib
    component: db
  name: katib-db
  namespace: kubeflow
spec:
  replicas: 1
  selector:
    matchLabels:
      app: katib
      component: db
  template:
    metadata:
      labels:
        app: katib
        component: db
      name: katib-db
    spec:
      containers:
      - args:
        - --datadir
        - /var/lib/mysql/datadir
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              key: MYSQL_ROOT_PASSWORD
              name: katib-db-secrets
        - name: MYSQL_ALLOW_EMPTY_PASSWORD
          value: "true"
        - name: MYSQL_DATABASE
          value: katib
        image: mysql:8.0.3
        name: katib-db
        ports:
        - containerPort: 3306
          name: dbapi
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - mysql -D $$MYSQL_DATABASE -p$$MYSQL_ROOT_PASSWORD -e 'SELECT 1'
          initialDelaySeconds: 5
          periodSeconds: 2
          timeoutSeconds: 1
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: katib-db-pvc
      volumes:
      - name: katib-db-pvc
        {{- if .Values.katib.db.persistence.enabled }}
        persistentVolumeClaim:
          claimName: katib-db-pvc
        {{- else }}
        emptyDir: {}
        {{ end }}
{{- if .Values.katib.db.persistence.enabled }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: katib-db-pvc
  namespace: kubeflow
spec:
  accessModes:
  - {{ .Values.katib.db.persistence.accessMode | quote }}
  resources:
    requests:
      storage: {{ .Values.katib.db.persistence.size | quote }}
  storageClassName: {{ .Values.katib.db.persistence.storageClass | quote }}
{{- end -}}
