apecloud / kubeblocks

KubeBlocks is an open-source control plane software that runs and manages databases, message queues and other stateful applications on K8s.
https://kubeblocks.io
GNU Affero General Public License v3.0
2.16k stars 176 forks source link

[BUG]kbcli kubeblocks install block by helm install mongo leftover configmaps #2684

Closed ahjing99 closed 1 year ago

ahjing99 commented 1 year ago

➜ ~ kbcli version Kubernetes: v1.25.6-gke.1000 kbcli: 0.5.0-beta.0

  1. Install mongo with helm "helm upgrade -install mongodb-cd kubeblocks/mongodb --version 0.5.0-alpha.11 --namespace default"
  2. Uninstall kb
    ➜  ~kbcli kubeblocks uninstall
    Warning: uninstall will remove all KubeBlocks resources.
    Please type "uninstall-kubeblocks" to confirm: uninstall-kubeblocks
    Uninstall KubeBlocks in namespace "kb-system"
    Uninstall KubeBlocks addons                        OK
    Uninstall helm release kubeblocks 0.5.0-alpha.12   OK
    Remove helm repo kubeblocks                        OK
    Remove built-in custom resources                   OK
    Remove backuppolicytemplates                       OK
    Remove backups                                     OK
    Remove backuptools                                 OK
    Remove clusterdefinitions                          OK
    Remove clusterversions                             OK
    Remove componentclassdefinitions                   OK
    Remove configconstraints                           OK
    Remove customresourcedefinitions                   OK
    Uninstall KubeBlocks done.
  3. Install kb failed for mongo leftover configmaps
    
    `kbcli kubeblocks install --create-namespace --set snapshot-controller.enabled=true  --namespace default `

error: there are resources left by previous KubeBlocks version, try to run "kbcli kubeblocks uninstall" to clean up configmaps: mongodb-metrics-config,mongodb-scripts,mongodb5.0-config-template

ahjing99 commented 1 year ago

After a second time uninstall, kb can be installed now

➜  kbcli git:(test_kb) ✗ kbcli kubeblocks uninstall
Warning: uninstall will remove all KubeBlocks resources.
Please type "uninstall-kubeblocks" to confirm: uninstall-kubeblocks
Warning: failed to locate KubeBlocks meta, will clean up all KubeBlocks resources.
to find out the namespace where KubeBlocks is installed, please use:
    'kbcli kubeblocks status'
to uninstall KubeBlocks completely, please use:
    `kbcli kubeblocks uninstall -n <namespace>`
Uninstall KubeBlocks addons                        OK
Uninstall helm release kubeblocks                  OK
Remove helm repo kubeblocks                        OK
Remove built-in custom resources                   OK
Remove configmaps                                  OK
Uninstall KubeBlocks done.
fengluodb commented 1 year ago

I reproduce this bug, and found it caused by this code https://github.com/apecloud/kubeblocks/blob/d2d701e37c0f82d6710223fc27cada46eb10a996/internal/cli/cmd/kubeblocks/uninstall.go#L171-L177

If kubeblocks existed, the o.namespace is "kb-system", kbcli kubeblocks uninstall only remove the resource in kb-system namespace. (I add a log to show the namespace that will be remove custom resources)

image

After a second time uninstall, kb can be installed now. Because if kubeblocks don't existed, the o.namespace is "", kbcli kubeblocks uninstall remove the resource in all namespace.

image
ldming commented 1 year ago

kbcli install or uninstall KubeBlocks SHOULD NOT touch the helm release manually installed by the user. We should use the specified label to filer these resources.