apiVersion: apps/v1
kind: Deployment
metadata:
  name: katib-mysql
  namespace: kubeflow
  # TODO (andreyvelich): Modify labels to follow k8s guidelines.
  labels:
    app: katib-mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: katib-mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: katib-mysql
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      containers:
        - name: katib-mysql
          image: mysql:8
          args:
            - --datadir
            - /var/lib/mysql/datadir
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: katib-mysql-secrets
                  key: MYSQL_ROOT_PASSWORD
            - name: MYSQL_ALLOW_EMPTY_PASSWORD
              value: "true"
            - name: MYSQL_DATABASE
              value: "katib"
          ports:
            - name: dbapi
              containerPort: 3306
          readinessProbe:
            exec:
              command:
                - "/bin/bash"
                - "-c"
                - "mysql -D ${MYSQL_DATABASE} -u root -p${MYSQL_ROOT_PASSWORD} -e 'SELECT 1'"
            periodSeconds: 2
            failureThreshold: 10
          livenessProbe:
            exec:
              command:
                - "/bin/bash"
                - "-c"
                - "mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}"
            periodSeconds: 2
            failureThreshold: 10
          startupProbe:
            exec:
              command:
                - "/bin/bash"
                - "-c"
                - "mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}"
            periodSeconds: 15
            failureThreshold: 60
          volumeMounts:
            - name: katib-mysql
              mountPath: /var/lib/mysql
      volumes:
        - name: katib-mysql
          persistentVolumeClaim:
            claimName: katib-mysql
