apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: proxysql
  namespace: proxysql
  labels:
    app: proxysql
spec:
  replicas: 3
  serviceName: proxysqlcluster
  selector:
    matchLabels:
      app: proxysql
  updateStrategy:
    type: RollingUpdate
  volumeClaimTemplates:
    - metadata:
        name: proxysql-data
        namespace: proxysql
      spec:
        storageClassName: csi-sc-cinderplugin
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi
    - metadata:
        name: proxysql-etc
        namespace: proxysql
      spec:
        storageClassName: csi-sc-cinderplugin
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi
  template:
    metadata:
      labels:
        app: proxysql
    spec:
      restartPolicy: Always
      containers:
        - image: docker.sunet.se/drive/proxysql:latest
          name: proxysql
          volumeMounts:
            - name: proxysql-data
              mountPath: /var/lib/proxysql
              subPath: data
            - name: proxysql-etc
              mountPath: /etc
              subPath: etc
            - name: proxysql-healthcheck
              mountPath: /usr/local/bin/healthcheck.sh
              subPath: healthcheck.sh
          ports:
            - containerPort: 6033
              name: proxysql-mysql
            - containerPort: 6032
              name: proxysql-admin
          env:
            - name: MYSQL_PWD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_admin_password"
          livenessProbe:
            exec:
              command:
              - /bin/bash
              - /usr/local/bin/healthcheck.sh
            initialDelaySeconds: 5
            periodSeconds: 5
      initContainers:
        - image: docker.sunet.se/sunet/docker-jinja:latest
          name: init-config
          volumeMounts:
            - name: proxysql-config-template
              mountPath: /tmp/proxysql.cnf.template
              subPath: proxysql.cnf
            - name: proxysql-etc
              mountPath: /etc
              subPath: etc
          env:
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_admin_password"
            - name: CLUSTER_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_cluster_password"
            - name: MONITOR_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_monitor_password"
            - name: ANTAGNING_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_antagning_password"
            - name: BTH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_bth_password"
            - name: CHALMERS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_chalmers_password"
            - name: DU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_du_password"
            - name: ESH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_esh_password"
            - name: FHS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_fhs_password"
            - name: GU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_gu_password"
            - name: HB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_hb_password"
            - name: HHS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_hhs_password"
            - name: HIG_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_hig_password"
            - name: HIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_his_password"
            - name: HJ_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_hj_password"
            - name: HV_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_hv_password"
            - name: IRF_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_irf_password"
            - name: KB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_kb_password"
            - name: KI_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_ki_password"
            - name: KKH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_kkh_password"
            - name: KMH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_kmh_password"
            - name: KONSTFACK_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_konstfack_password"
            - name: KTH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_kth_password"
            - name: KVA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_kva_password"
            - name: LIU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_liu_password"
            - name: LNU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_lnu_password"
            - name: LTU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_ltu_password"
            - name: LU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_lu_password"
            - name: MAU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_mau_password"
            - name: MIUN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_miun_password"
            - name: NORDUNET_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_nordunet_password"
            - name: NRM_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_nrm_password"
            - name: ORU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_oru_password"
            - name: RKH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_rkh_password"
            - name: SHH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_shh_password"
            - name: SICS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_sics_password"
            - name: SLU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_slu_password"
            - name: SMHI_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_smhi_password"
            - name: SP_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_sp_password"
            - name: SWAMID_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_swamid_password"
            - name: THS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_ths_password"
            - name: UHR_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_uhr_password"
            - name: UMU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_umu_password"
            - name: UNIARTS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_uniarts_password"
            - name: UU_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_uu_password"
            - name: VINNOVA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_vinnova_password"
            - name: VR_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: proxysql-secret
                  key: "proxysql_vr_password"
          command: ["/bin/sh", "-c", "/usr/bin/j2 -f env -o /etc/proxysql.cnf /tmp/proxysql.cnf.template"]
      volumes:
        - name: proxysql-config-template
          configMap:
            name: proxysql-configmap
            items:
              - key: "proxysql.cnf"
                path: "proxysql.cnf"
        - name: proxysql-healthcheck
          configMap:
            name: proxysql-configmap
            items:
              - key: "healthcheck.sh"
                path: "healthcheck.sh"
