github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/state/cleanup.md (about) 1 # Cleanup 2 3 Cleanup is called by the cleaner worker. The cleaner worker watches the 4 cleanups collection and acts when something changes in the collection related 5 to the current model. It will also act on a period time frame. 6 7 Cleanup will interate over the current docs in the collection and call a 8 method to handle the doc based on its kind. If the method is successful, 9 the corresponding doc will be removed from the collection. Otherwise the 10 method will be retried later. 11 12 Docs in the cleanups collection are handled in a specific order. E.g. cleaning 13 up a machine requires that it's units are gone, so clean up the units first. 14 15 ## Model 16 17 Model cleanup starts with `juju destroy-model`, or `juju destroy-controller`. 18 Simplistically model destroyOps, causes the model is marked as dying and up to 19 5 docs are inserted into the cleanup collection: 20 * cleanupModelsForDyingController, only for controller models 21 * cleanupApplicationsForDyingModel, only with non empty models 22 * cleanupMachinesForDyingModel, only with non empty IAAS models 23 * cleanupStorageForDyingModel, only with non empty models with storage 24 * cleanupBranchesForDyingModel, for all models 25 26 ## Docs in the Cleanup collection 27 28 ### cleanupModelsForDyingController 29 ### cleanupApplicationsForDyingModel 30 31 First it attempts to remove all remote applications from the model, then 32 attempts to remove all applications from the model. 33 34 Removing an application inserts a cleanupForceApplication into the cleanups 35 collection. 36 37 ### cleanupMachinesForDyingModel 38 39 For all machines in the model, which are not managers, call 40 DestroyWithContainers. If force is used, call ForceDestroy instead. Force is 41 not allowed for manual machines. The first failure causes the method to exit. 42 43 DestroyWithContainers advances the machine's lifecycle to Dying, and inserts a 44 cleanupDyingMachine job into the cleanups collection. 45 46 Once a machine is dying, it's lifecycle takes over. 47 48 ### cleanupStorageForDyingModel 49 ### cleanupBranchesForDyingModel 50 ### cleanupDyingMachine 51 52 For the dying machine, call cleanupDyingMachineResources. After that, if 53 force is in use, and the machine hasn't been forcedestroyed yet, schedule 54 cleanupForceRemoveMachine by inserting the doc into the cleanups collection. 55 56 cleanupDyingMachineResources checks that the machine has no filesystem nor 57 volume attachments. Then calls cleanupDyingEntityStorage, which detaches 58 all detachable storge and destroys storage which cannot be detached. 59 60 ### cleanupForceRemoveMachine 61 62 ### cleanupForceApplication 63