Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#17684 from ca-scribner/prompt-user-on-model-s…
…torage-destroy juju#17684 This adds a check during `juju destroy-model` calls to proactively alert the user when they have storage but have not invoked a `--destroy-storage` or `--release-storage` flag. Previously, the user would not be alerted to this until after they've confirmed deletion, leading to an annoying UX. Because this fix invokes a `ModelStatus` query earlier in the destroy command, many tests needed modifications to pass. This was typically for one of two reasons: * the default test case includes detachable volumes/filesystems. Some `TestDestroy*` tests previously would "pass" because their assertions were satisfied before the storage mattered, but now it is tested proactively and the tests would fail. These were updated to test without storage. * some tests have additional `nil` entries in `s.api.modelInfoErr` because `ModelStatus` is callewd an extra time Tests were updated to handle this. During QA for this fix, a few driveby fixes were done on the `destroyModelMsg` and `destroyModelMsgDetails` templates. The template only worked for machine models. For example, machine models would get this message: ``` juju destory-model lxd:test WARNING This command will destroy the "test" model and all its resources. It cannot be stopped. - 2 machines will be destroyed - machine list: "0 (juju-03f299-0)" "1 (juju-03f299-1)" - 2 applications will be removed - application list: "lxd" "postgresql" - 1 filesystem and 1 volume will be destroyed To continue, enter the name of the model to be destroyed: ``` whereas container models see: ``` juju destroy-model container-model:test WARNING This command will destroy the "test" model and all its resources. It cannot be stopped. To continue, enter the name of the model to be destroyed: ``` This was likely due to a typo in the `destroyModelMsgDetails` template and has been fixed here. We also see the same "WARNING This command will destroy X model and all its resources" even when `--release-storage` is specified. The wording has been updated to avoid confusion. The message now renders, both for container and machine models, as: ``` juju destroy-model container-model:test WARNING This command will destroy the "test" model and all its resources. It cannot be stopped. - 1 application will be removed - application list: "minio" - 0 filesystem and 1 volume will be destroyed To continue, enter the name of the model to be destroyed: ``` ## Checklist <!-- If an item is not applicable, use `~strikethrough~`. --> - [ ] ~Code style: imports ordered, good names, simple structure, etc~ - [ ] ~Comments saying why design decisions were made~ - [x] Go unit tests, with comments saying what you're testing - [ ] ~[Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~ - [ ] ~[doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~ ## QA steps ### Machine model setup: ``` juju bootstrap lxd lxd juju add-model -c lxd test # volume storage juju deploy ch:lxd --model lxd:test --storage local=10G,1 # filesystem storage juju deploy postgresql --model lxd:test --storage pgdata=lxd,2G ``` without `--destroy-storage` or `--release-storage`: ``` juju destroy-model lxd:test ERROR cannot destroy model "test" The model has persistent storage remaining: 1 filesystem(s) To destroy the storage, run the destroy-model command again with the "--destroy-storage" option. To release the storage from Juju's management without destroying it, use the "--release-storage" option instead. The storage can then be imported into another Juju model. ``` with `--destroy-storage` or `--release-storage`: ``` juju destroy-model lxd:test --destroy-storage WARNING This command will destroy the "test" model and affect the following resources. It cannot be stopped. - 2 machines will be destroyed - machine list: "0 (juju-43ffa3-0)" "1 (juju-43ffa3-1)" - 2 applications will be removed - application list: "lxd" "postgresql" - 1 filesystem and 1 volume will be destroyed To continue, enter the name of the model to be destroyed: test Destroying model ``` ### Kubernetes model setup: ``` juju add-model test -c microk8s # volume storage juju deploy minio --model microk8s:test ``` without flag: ``` juju destroy-model microk8s:test ERROR cannot destroy model "test" The model has persistent storage remaining: 1 volume(s) 1 filesystem(s) To destroy the storage, run the destroy-model command again with the "--destroy-storage" option. To release the storage from Juju's management without destroying it, use the "--release-storage" option instead. The storage can then be imported into another Juju model. ``` with flag: ``` juju destroy-model microk8s:test --destroy-storage WARNING This command will destroy the "test" model and affect the following resources. It cannot be stopped. - 1 application will be removed - application list: "minio" - 1 filesystem and 1 volume will be destroyed To continue, enter the name of the model to be destroyed: test Destroying model ``` ## Documentation changes ## Links **Launchpad bug:** https://bugs.launchpad.net/juju/+bug/2012593/
- Loading branch information