# Copyright 2021 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# For those usages not covered by the Apache License, Version 2.0 please
# contact: legal@canonical.com
#
# To get in touch with the maintainers, please contact:
# osm-charmers@lists.launchpad.net
##

version: 2
service:
  scalePolicy: serial
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
containers:
  - name: %(name)s
    image: %(docker_image)s
    kubernetes:
      readinessProbe:
        tcpSocket:
          port: %(mysql_port)s
        initialDelaySeconds: 10
        periodSeconds: 10
        timeoutSeconds: 5
        successThreshold: 1
        failureThreshold: 3
      livenessProbe:
        exec:
          command: ["bash", "-c", "mysql -uroot -p\"${MYSQL_ROOT_PASSWORD}\" -e 'show databases;'"]
        initialDelaySeconds: 120
        periodSeconds: 10
        timeoutSeconds: 5
        successThreshold: 1
        failureThreshold: 3
    ports:
    - containerPort: %(mysql_port)s
      protocol: TCP
      name: main
    - containerPort: 4444
      name: sst
    - containerPort: 4567
      name: replication
    - containerPort: 4568
      name: ist
    config:
      MYSQL_ROOT_PASSWORD: %(root_password)s
      APPLICATION_NAME: %(application_name)s
      MYSQL_USER: %(user)s
      MYSQL_PASSWORD: %(password)s
      MYSQL_DATABASE: %(database)s
    files:
      - name: configurations
        mountPath: /etc/mysqlconfiguration
        files:
          galera.cnf: |
            [galera]
            user = mysql
            bind-address = 0.0.0.0
        
            default_storage_engine = InnoDB
            binlog_format = ROW
            innodb_autoinc_lock_mode = 2
            innodb_flush_log_at_trx_commit = 0
            query_cache_size = 0
            host_cache_size = 0
            query_cache_type = 0

            # MariaDB Galera settings
            wsrep_on=ON
            wsrep_provider=/usr/lib/galera/libgalera_smm.so
            wsrep_sst_method=rsync

            # Cluster settings (automatically updated)
            wsrep_cluster_address=gcomm://
            wsrep_cluster_name=vimdb_cluser
            wsrep_node_address=127.0.0.1
          mariadb.cnf: |
            [client]
            default-character-set = utf8
            [mysqld]
            character-set-server  = utf8
            collation-server      = utf8_general_ci
            plugin_load_add = feedbackx#
            # InnoDB tuning
            innodb_log_file_size  = 50M
