Skip to content

Commit

Permalink
Merge pull request juju#12178 from ycliuhw/fix/destroy-caas-controlle…
Browse files Browse the repository at this point in the history
…r-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
  • Loading branch information
jujubot authored Oct 22, 2020
2 parents 8eda9c2 + f33c58f commit 704369c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion state/allwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (u *backingUnit) updated(ctx *allWatcherContext) error {
info.CharmURL = u.CharmURL.String()
}

// Construct a unit for the purpose of retieving other fields as necessary.
// Construct a unit for the purpose of retrieving other fields as necessary.
modelType, err := ctx.modelType()
if err != nil {
return errors.Annotatef(err, "get model type for %q", ctx.modelUUID)
Expand Down
10 changes: 8 additions & 2 deletions state/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ func (st *State) cleanupUnitsForDyingApplication(applicationname string, cleanup
units, closer := st.db().GetCollection(unitsC)
defer closer()

unit := Unit{st: st}
sel := bson.D{{"application", applicationname}}
// If we're forcing then include dying and dead units, since we
// still want the opportunity to schedule fallback cleanups if the
Expand All @@ -716,7 +715,14 @@ func (st *State) cleanupUnitsForDyingApplication(applicationname string, cleanup
}
iter := units.Find(sel).Iter()
defer closeIter(iter, &err, "reading unit document")
for iter.Next(&unit.doc) {

m, err := st.Model()
if err != nil {
return errors.Trace(err)
}
var unitDoc unitDoc
for iter.Next(&unitDoc) {
unit := newUnit(st, m.Type(), &unitDoc)
op := unit.DestroyOperation()
op.DestroyStorage = destroyStorage
op.Force = force
Expand Down

0 comments on commit 704369c

Please sign in to comment.