-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commands: add command to wiping cluster
Added command destroy-cluster for remove all crds Added documentation for destroy-cluster Added unittest and integration tests Signed-off-by: Javier <[email protected]>
- Loading branch information
Showing
15 changed files
with
900 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2023 The Rook Authors. All rights reserved. | ||
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. | ||
*/ | ||
|
||
package command | ||
|
||
import ( | ||
"fmt" | ||
"github.com/rook/kubectl-rook-ceph/pkg/crds" | ||
"github.com/rook/kubectl-rook-ceph/pkg/logging" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const ( | ||
destroyClusterQuestion = "Are you sure you want to destroy the cluster in namespace \"%s\"? " | ||
destroyClusterAnswer = "yes-really-destroy-cluster" | ||
) | ||
|
||
// DestroyClusterCmd represents the command for destroy cluster | ||
var DestroyClusterCmd = &cobra.Command{ | ||
Use: "destroy-cluster", | ||
Short: "delete all Rook CRDs", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
question := fmt.Sprintf(destroyClusterQuestion, CephClusterNamespace) | ||
confirmation, err := confirmPrompt(question, destroyClusterAnswer) | ||
if err != nil { | ||
logging.Fatal(err) | ||
} | ||
|
||
logging.Info(confirmation) | ||
clientsets := GetClientsets(cmd.Context()) | ||
err = crds.DeleteCustomResources(cmd.Context(), clientsets, CephClusterNamespace) | ||
if err != nil { | ||
logging.Fatal(err) | ||
} | ||
logging.Info("done") | ||
}, | ||
} | ||
|
||
func init() { | ||
DestroyClusterCmd.Flags().BoolP("yes-really-destroy-cluster", "", false, "confirm cluster deletion") | ||
} | ||
|
||
func confirmPrompt(question, key string) (string, error) { | ||
var answer string | ||
if skip, ok := os.LookupEnv("ROOK_PLUGIN_SKIP_PROMPTS"); ok && skip == "true" { | ||
return "skipped prompt since ROOK_PLUGIN_SKIP_PROMPTS=true", nil | ||
} | ||
logging.Warning(question) | ||
fmt.Scan(&answer) | ||
|
||
if strings.EqualFold(answer, key) { | ||
return "proceeding", nil | ||
} | ||
|
||
return "", fmt.Errorf("you need to response \"yes-really-destroy-cluster\" to confirm the cluster deletion") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,5 +38,6 @@ func addcommands() { | |
command.DebugCmd, | ||
command.Health, | ||
command.DrCmd, | ||
command.DestroyClusterCmd, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
$ | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.