Skip to content

Commit 704369c

Browse files
authored
Merge pull request juju#12178 from ycliuhw/fix/destroy-caas-controller-hangs
juju#12178 *Fix destroying caas controller/models hang issue by constructing Unit properly in cleanupUnitsForDyingApplication;* ## Checklist - [ ] ~Requires a [pylibjuju](https://github.com/juju/python-libjuju) change~ - [ ] ~Added [integration tests](https://github.com/juju/juju/tree/develop/tests) for the PR~ - [ ] ~Added or updated [doc.go](https://discourse.jujucharms.com/t/readme-in-packages/451) related to packages changed~ - [x] Comments answer the question of why design decisions were made ## QA steps ```console $ juju add-model t1 microk8s $ juju deploy cs:~juju/mariadb-k8s-3 $ juju deploy cs:~juju/mediawiki-k8s-4 --config kubernetes-service-type=LoadBalancer $ juju relate mediawiki-k8s:db mariadb-k8s:server $ juju destroy-controller k1 --destroy-all-models --destroy-storage --debug -y ``` ## Documentation changes No ## Bug reference https://bugs.launchpad.net/juju/+bug/1900937
2 parents 8eda9c2 + f33c58f commit 704369c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

state/allwatcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ func (u *backingUnit) updated(ctx *allWatcherContext) error {
555555
info.CharmURL = u.CharmURL.String()
556556
}
557557

558-
// Construct a unit for the purpose of retieving other fields as necessary.
558+
// Construct a unit for the purpose of retrieving other fields as necessary.
559559
modelType, err := ctx.modelType()
560560
if err != nil {
561561
return errors.Annotatef(err, "get model type for %q", ctx.modelUUID)

state/cleanup.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ func (st *State) cleanupUnitsForDyingApplication(applicationname string, cleanup
706706
units, closer := st.db().GetCollection(unitsC)
707707
defer closer()
708708

709-
unit := Unit{st: st}
710709
sel := bson.D{{"application", applicationname}}
711710
// If we're forcing then include dying and dead units, since we
712711
// still want the opportunity to schedule fallback cleanups if the
@@ -716,7 +715,14 @@ func (st *State) cleanupUnitsForDyingApplication(applicationname string, cleanup
716715
}
717716
iter := units.Find(sel).Iter()
718717
defer closeIter(iter, &err, "reading unit document")
719-
for iter.Next(&unit.doc) {
718+
719+
m, err := st.Model()
720+
if err != nil {
721+
return errors.Trace(err)
722+
}
723+
var unitDoc unitDoc
724+
for iter.Next(&unitDoc) {
725+
unit := newUnit(st, m.Type(), &unitDoc)
720726
op := unit.DestroyOperation()
721727
op.DestroyStorage = destroyStorage
722728
op.Force = force

0 commit comments

Comments
 (0)