apiVersion: apps/v1
kind: StatefulSet
metadata:
  generation: 2
  name: some-name-proxysql
  ownerReferences:
    - controller: true
      kind: PerconaXtraDBCluster
      name: some-name
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/component: proxysql
      app.kubernetes.io/instance: some-name
      app.kubernetes.io/managed-by: percona-xtradb-cluster-operator
      app.kubernetes.io/name: percona-xtradb-cluster
      app.kubernetes.io/part-of: percona-xtradb-cluster
  serviceName: some-name-proxysql-unready
  template:
    metadata:
      annotations: {}
      labels:
        app.kubernetes.io/component: proxysql
        app.kubernetes.io/instance: some-name
        app.kubernetes.io/managed-by: percona-xtradb-cluster-operator
        app.kubernetes.io/name: percona-xtradb-cluster
        app.kubernetes.io/part-of: percona-xtradb-cluster
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchLabels:
                  app.kubernetes.io/component: proxysql
                  app.kubernetes.io/instance: some-name
                  app.kubernetes.io/managed-by: percona-xtradb-cluster-operator
                  app.kubernetes.io/name: percona-xtradb-cluster
                  app.kubernetes.io/part-of: percona-xtradb-cluster
              topologyKey: kubernetes.io/hostname
      containers:
        - env:
            - name: PXC_SERVICE
              value: some-name-pxc
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: root
                  name: my-cluster-secrets
            - name: PROXY_ADMIN_USER
              value: proxyadmin
            - name: PROXY_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: proxyadmin
                  name: my-cluster-secrets
            - name: MONITOR_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: monitor
                  name: my-cluster-secrets
          imagePullPolicy: Always
          name: proxysql
          ports:
            - containerPort: 3306
              name: mysql
              protocol: TCP
            - containerPort: 6032
              name: proxyadm
              protocol: TCP
          resources:
            limits:
              cpu: 700m
              memory: 1G
            requests:
              cpu: 100m
              memory: 100M
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /var/lib/proxysql
              name: proxydata
            - mountPath: /etc/proxysql/ssl
              name: ssl
            - mountPath: /etc/proxysql/ssl-internal
              name: ssl-internal
        - args:
            - /usr/bin/peer-list
            - -on-change=/usr/bin/add_pxc_nodes.sh
            - -service=$(PXC_SERVICE)
          env:
            - name: PXC_SERVICE
              value: some-name-pxc
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: root
                  name: my-cluster-secrets
            - name: PROXY_ADMIN_USER
              value: proxyadmin
            - name: PROXY_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: proxyadmin
                  name: my-cluster-secrets
            - name: MONITOR_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: monitor
                  name: my-cluster-secrets
          imagePullPolicy: Always
          name: pxc-monit
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
        - args:
            - /usr/bin/peer-list
            - -on-change=/usr/bin/add_proxysql_nodes.sh
            - -service=$(PROXYSQL_SERVICE)
          env:
            - name: PROXYSQL_SERVICE
              value: some-name-proxysql-unready
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: root
                  name: my-cluster-secrets
            - name: PROXY_ADMIN_USER
              value: proxyadmin
            - name: PROXY_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: proxyadmin
                  name: my-cluster-secrets
            - name: MONITOR_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: monitor
                  name: my-cluster-secrets
          imagePullPolicy: Always
          name: proxysql-monit
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        supplementalGroups:
          - 1001
      terminationGracePeriodSeconds: 30
      volumes:
        - name: ssl-internal
          secret:
            defaultMode: 420
            optional: true
            secretName: some-name-ssl-internal
        - name: ssl
          secret:
            defaultMode: 420
            optional: false
            secretName: some-name-ssl
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
  volumeClaimTemplates:
    - metadata:
        name: proxydata
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi
      status:
        phase: Pending
