diff --git a/.github/workflows/go-test.yaml b/.github/workflows/go-test.yaml index d52dc0e2..c774fb3c 100644 --- a/.github/workflows/go-test.yaml +++ b/.github/workflows/go-test.yaml @@ -237,12 +237,7 @@ jobs: set -ex kubectl rook-ceph --operator-namespace test-operator -n test-cluster destroy-cluster - - name: List CRDS 2 - run: | - set -ex - kubectl -n test-cluster get all - - - name: List CRDS + - name: Validate destroyed CRDS run: | set -ex kubectl get deployments -n rook-ceph --no-headers| wc -l | (read n && [ $n -le 1 ] || { echo "the crds could not be deleted"; exit 1;}) diff --git a/README.md b/README.md index 8bd0e89a..e774bf88 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Visit docs below for complete details about each command and their flags uses. 1. [Debug OSDs and Mons](docs/debug.md) 1. [Restore mon quorum](docs/mons.md#restore-quorum) 1. [Disaster Recovery](docs/dr-health.md) +1. [Destroy Cluster](docs/destroy_cluster.md) ## Examples @@ -178,6 +179,49 @@ kubectl rook-ceph ceph versions } } ``` +### Destroy Cluster +```bash +$ kubectl rook-ceph -n rook-ceph destroy-cluster +Warning: Are you sure you want to destroy the cluster in namespace "rook-ceph"? +yes-really-destroy-cluster +Info: proceeding +Info: Getting resources kind cephblockpoolradosnamespaces +Warning: resource cephblockpoolradosnamespaces was not found on the cluster +Info: Getting resources kind cephblockpools +Warning: resource cephblockpools was not found on the cluster +Info: Getting resources kind cephbucketnotifications +Warning: resource cephbucketnotifications was not found on the cluster +Info: Getting resources kind cephbuckettopics +Warning: resource cephbuckettopics was not found on the cluster +Info: Getting resources kind cephclients +Warning: resource cephclients was not found on the cluster +Info: Getting resources kind cephclusters +Warning: resource cephclusters was not found on the cluster +Info: Getting resources kind cephcosidrivers +Warning: resource cephcosidrivers was not found on the cluster +Info: Getting resources kind cephfilesystemmirrors +Warning: resource cephfilesystemmirrors was not found on the cluster +Info: Getting resources kind cephfilesystems +Warning: resource cephfilesystems was not found on the cluster +Info: Getting resources kind cephfilesystemsubvolumegroup +Warning: the server could not find the requested resource: cephfilesystemsubvolumegroup +Info: Getting resources kind cephnfses +Warning: resource cephnfses was not found on the cluster +Info: Getting resources kind cephobjectrealms +Warning: resource cephobjectrealms was not found on the cluster +Info: Getting resources kind cephobjectstores +Warning: resource cephobjectstores was not found on the cluster +Info: Getting resources kind cephobjectstoreusers +Warning: resource cephobjectstoreusers was not found on the cluster +Info: Getting resources kind cephobjectzonegroups +Warning: resource cephobjectzonegroups was not found on the cluster +Info: Getting resources kind cephobjectzones +Warning: resource cephobjectzones was not found on the cluster +Info: Getting resources kind cephrbdmirrors +Warning: resource cephrbdmirrors was not found on the cluster +Info: done +$ +``` ## Contributing diff --git a/docs/destroy_cluster.md b/docs/destroy_cluster.md new file mode 100644 index 00000000..d2bb3254 --- /dev/null +++ b/docs/destroy_cluster.md @@ -0,0 +1,108 @@ +# Destroy Cluster + +This command is used for destroy CRDS (custom resource definitions) created by rook-ceph + +## !!! Warning !!! + **This command is not reversible**, and it will destroy your rook-ceph cluster completely and your data, + please only use this command if your sure that your data must be destroyed. + +## How to use: + +Just you need to run the command, and you will be asked for the confirmation +```bash +$ kubectl rook-ceph -n rook-ceph destroy-cluster +Are you sure you want to destroy the cluster in namespace "rook-ceph"? | +``` + +You must write exactly this answer **yes-really-destroy-cluster** +to confirm that you really want to execute the command and destroy +your cluster, any other response will be rejected and +the process will be stopped even responding yes + +```bash +$ kubectl rook-ceph -n rook-ceph destroy-cluster +Are you sure you want to destroy the cluster in namespace "rook-ceph"? yes +Error: you need to response "yes-really-destroy-cluster" to confirm the cluster deletion +exit status 1 + +``` + +Once you respond with the right answer the process will start, and it will be deleteing the CRDS created by rook-ceph + +```bash +$ kubectl rook-ceph -n rook-ceph destroy-cluster +Warning: Are you sure you want to destroy the cluster in namespace "rook-ceph"? +yes-really-destroy-cluster +Info: proceeding +Info: Getting resources kind cephblockpoolradosnamespaces +Warning: resource cephblockpoolradosnamespaces was not found on the cluster +Info: Getting resources kind cephblockpools +Warning: resource cephblockpools was not found on the cluster +Info: Getting resources kind cephbucketnotifications +Warning: resource cephbucketnotifications was not found on the cluster +Info: Getting resources kind cephbuckettopics +Warning: resource cephbuckettopics was not found on the cluster +Info: Getting resources kind cephclients +Warning: resource cephclients was not found on the cluster +Info: Getting resources kind cephclusters +Warning: resource cephclusters was not found on the cluster +Info: Getting resources kind cephcosidrivers +Warning: resource cephcosidrivers was not found on the cluster +Info: Getting resources kind cephfilesystemmirrors +Warning: resource cephfilesystemmirrors was not found on the cluster +Info: Getting resources kind cephfilesystems +Warning: resource cephfilesystems was not found on the cluster +Info: Getting resources kind cephfilesystemsubvolumegroup +Warning: the server could not find the requested resource: cephfilesystemsubvolumegroup +Info: Getting resources kind cephnfses +Warning: resource cephnfses was not found on the cluster +Info: Getting resources kind cephobjectrealms +Warning: resource cephobjectrealms was not found on the cluster +Info: Getting resources kind cephobjectstores +Warning: resource cephobjectstores was not found on the cluster +Info: Getting resources kind cephobjectstoreusers +Warning: resource cephobjectstoreusers was not found on the cluster +Info: Getting resources kind cephobjectzonegroups +Warning: resource cephobjectzonegroups was not found on the cluster +Info: Getting resources kind cephobjectzones +Warning: resource cephobjectzones was not found on the cluster +Info: Getting resources kind cephrbdmirrors +Warning: resource cephrbdmirrors was not found on the cluster +Info: done +$ +``` + + +# Developer changes +We are adding unittests in order to ensure that the destroy-cluster command is working as we expected, +so if you want to expand the functionality, and you need to change the `pgk/k8sutil/interface.go` remember to recreate the mocks by using `make generate` + +```bash +$ make generate +generating mocks... +completed +$ +``` + +# Run test + +To run the tests you should to execute `make test` +```bash +$ make test +running unit tests +go test ./... +? github.com/rook/kubectl-rook-ceph/cmd [no test files] +ok github.com/rook/kubectl-rook-ceph/cmd/commands (cached) +ok github.com/rook/kubectl-rook-ceph/pkg/crds (cached) +? github.com/rook/kubectl-rook-ceph/pkg/debug [no test files] +? github.com/rook/kubectl-rook-ceph/pkg/dr [no test files] +? github.com/rook/kubectl-rook-ceph/pkg/exec [no test files] +? github.com/rook/kubectl-rook-ceph/pkg/health [no test files] +? github.com/rook/kubectl-rook-ceph/pkg/k8sutil [no test files] +? github.com/rook/kubectl-rook-ceph/pkg/logging [no test files] +? github.com/rook/kubectl-rook-ceph/pkg/rook [no test files] +ok github.com/rook/kubectl-rook-ceph/pkg/mons (cached) +$ +``` + + diff --git a/pkg/crds/crds.go b/pkg/crds/crds.go index 7c943a14..1d5f9838 100644 --- a/pkg/crds/crds.go +++ b/pkg/crds/crds.go @@ -144,8 +144,6 @@ func updatingFinalizers(ctx context.Context, clientsets k8sutil.ClientsetsInterf } jsonPatchData, _ := json.Marshal(patch) - logging.Info(fmt.Sprintf("patching with %s", string(jsonPatchData))) - err := clientsets.PatchResourcesDynamically(ctx, cephRookIoGroup, cephRookResourcesVersion, resource, clusterNamespace, itemResource.GetName(), types.MergePatchType, jsonPatchData) if err != nil { return err