Skip to content

Commit

Permalink
fix(offers): remove force destroy of application offers
Browse files Browse the repository at this point in the history
Removes force removal of application offers, but rather errors out if there are
existing integrations with the offer that must be removed first. This is a much
cleaner way to destroy offers as the use of the `force` flag may leave the Juju
state with leftover artefacts.
  • Loading branch information
alesstimec committed Jan 14, 2025
1 parent 7e2527d commit 4f16a47
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions internal/juju/offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,18 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error {
defer func() { _ = conn.Close() }()

client := applicationoffers.NewClient(conn)
offer, err := client.ApplicationOffer(input.OfferURL)
if err != nil {
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
}
end := time.Now().Add(10 * time.Minute)
for {
if time.Now().After(end) {
return fmt.Errorf("failed to destroy offer %q, timeout reached", input.OfferURL)
}
err = client.DestroyOffers(false, input.OfferURL)
if err == nil {
break
}
}

err = client.DestroyOffers(forceDestroy, input.OfferURL)
if err != nil {
return err
time.Sleep(10 * time.Second)
}

return nil
Expand Down

0 comments on commit 4f16a47

Please sign in to comment.