Skip to content

Commit

Permalink
commands: add documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Javier <[email protected]>
  • Loading branch information
Javlopez committed Oct 1, 2023
1 parent dacd40a commit 3796dd2
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 8 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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;})
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
108 changes: 108 additions & 0 deletions docs/destroy_cluster.md
Original file line number Diff line number Diff line change
@@ -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)
$
```


2 changes: 0 additions & 2 deletions pkg/crds/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3796dd2

Please sign in to comment.