Skip to content

Commit

Permalink
fix - remove force destroy of application offers.
Browse files Browse the repository at this point in the history
Removes force removal of application offers.
  • Loading branch information
alesstimec committed Dec 18, 2024
1 parent 46aadad commit 2a13a5a
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions internal/juju/offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,30 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error {
return err
}

forceDestroy := false
//This code loops until it detects 0 connections in the offer or 3 minutes elapses
if len(offer.Connections) > 0 {
end := time.Now().Add(5 * time.Minute)
for ok := true; ok; ok = len(offer.Connections) > 0 {
//if we have been failing to destroy offer for 5 minutes then force destroy
//TODO: investigate cleaner solution (acceptance tests fail even if timeout set to 20m)
if time.Now().After(end) {
forceDestroy = true
break
}
time.Sleep(10 * time.Second)
offer, err = client.ApplicationOffer(input.OfferURL)
if err != nil {
return err
checkConnections := func() error {
//This code loops until it detects 0 connections in the offer or 3 minutes elapses
if len(offer.Connections) > 0 {
end := time.Now().Add(5 * time.Minute)
for ok := true; ok; ok = len(offer.Connections) > 0 {
//if we have been failing to destroy offer for 5 minutes then fail on destroy
if time.Now().After(end) {
return fmt.Errorf("offer %q has remaining connections", input.OfferURL)
}
time.Sleep(10 * time.Second)
offer, err = client.ApplicationOffer(input.OfferURL)
if err != nil {
return err
}
}
}
return nil
}

if err = checkConnections(); err != nil {
return err
}

err = client.DestroyOffers(forceDestroy, input.OfferURL)
err = client.DestroyOffers(false, input.OfferURL)
if err != nil {
return err
}
Expand Down

0 comments on commit 2a13a5a

Please sign in to comment.