{{ if .Values.mysql.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      name: mysql
      labels:
        app: mysql
    spec:
      containers:
      - name: autossh
        image: docker.io/goalprofit/autossh
        imagePullPolicy: Always
        command:
          - bash
          - -c
          - |
            autossh -L 0.0.0.0:3306:{{.Values.mysql.url}}:3306 -N -v {{.Values.mysql.host}}
        workingDir: /home/ubuntu
        volumeMounts:
        - mountPath: /home
          name: home

      imagePullSecrets:
      - name: regcred

      volumes:
      - name: home
        hostPath:
          path: /home
          type: Directory
      {{ include "app.affinity" . | nindent 6}}
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  type: ClusterIP
  selector:
    app: mysql
  ports:
    - name: mysql
      protocol: TCP
      port: 3306
      targetPort: 3306
{{ end }}