From 4f16a47cdd92be0fe8ae39065f840b33f2febff9 Mon Sep 17 00:00:00 2001 From: Ales Stimec Date: Wed, 18 Dec 2024 17:16:11 +0100 Subject: [PATCH] fix(offers): remove force destroy of application offers 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. --- internal/juju/offers.go | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/internal/juju/offers.go b/internal/juju/offers.go index eb2fb973..b0935fc6 100644 --- a/internal/juju/offers.go +++ b/internal/juju/offers.go @@ -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