mariadb-operator / mariadb-operator

🦭 Run and operate MariaDB in a cloud native way
MIT License
498 stars 100 forks source link

[Bug] DB gets deleted on redeploy #1011

Open bennyvar77 opened 2 weeks ago

bennyvar77 commented 2 weeks ago

Documentation

Describe the bug I have deployed a maria db as follows

apiVersion: v1
kind: Secret
metadata:
  name: mariadb-password
  annotations:
    argocd.argoproj.io/sync-wave: "-1"
type: Opaque
data:
  root-password: bWFyaWFwYXNzd29yZA==  # echo -n 'mariapassword'|base64
---
apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
  name: mariadb
spec:
  rootPasswordSecretKeyRef:
    name: mariadb-password
    key: root-password
    generate: true

  username: mariadb
  passwordSecretKeyRef:
    name: mariadb-password
    key: root-password
    generate: true
  database: mariadb

  port: 3306

  storage:
    size: 1Gi

  myCnf: |
    [mariadb]
    bind-address=*
    default_storage_engine=InnoDB
    binlog_format=row
    innodb_autoinc_lock_mode=2
    innodb_buffer_pool_size=1024M
    max_allowed_packet=256M

  resources:
    requests:
      cpu: 100m
      memory: 128Mi
    limits:
      memory: 1Gi

After deploying, i have added a new table to the mariadb db image

If i remove the deployment and redeploy it, the new table will be gone image

Expected behaviour The removal and redeployment should not delete the db

Steps to reproduce the bug

  1. use the manifest above to deploy a maria db
  2. Create a table in the mariadb db
  3. remove the deployment
  4. redeploy and check whether the newly created table still exist

Environment details:

Additional context I use ArgoCD for deployment.

maciej-p commented 2 weeks ago

Looks like you not properly tested it and didn't read documentation: cleanupPolicy

My suggestion is to use separate manifests for database, users and grants with cleanupPolicy: Skip.

Not sure why your ArgoCD deleting deployments, maybe you should set prune: false

Also not sure why you deploying secret if in your MariaDB deployment you have generate: true

bennyvar77 commented 2 weeks ago

Hi @maciej-p Yes, i wasn't thorough enough in reading through the release notes. It was too tempting to get to the latest version. Meanwhile, i tested the cleanupPolicy: Skip The result is fine if the database is initially not included in the mariadb cr. If the database was included in the MariaDB cr and you remove the deployment, it will be deleted. The deletion happens even if i add the database manifest with the same database name and cleanupPolicy: Skip. I was expecting this definition to overrule the definition in the mariadb manifest as it is for the same db. So, what is your suggestion to migrate to a separated database manifest without losing the database?