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 10, 2025
1 parent 46aadad commit 3b09502
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/juju/offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,17 @@ 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
//This code loops until it detects 0 connections in the offer or 5 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 we have been failing to destroy offer for 5 minutes then fail on destroy
if time.Now().After(end) {
forceDestroy = true
break
connections := make([]string, len(offer.Connections))
for i, connection := range offer.Connections {
connections[i] = fmt.Sprintf("%s:%s", connection.SourceModelUUID, connection.Endpoint)
}
return fmt.Errorf("offer %q has remaining integrations: %s", input.OfferURL, strings.Join(connections, ", "))
}
time.Sleep(10 * time.Second)
offer, err = client.ApplicationOffer(input.OfferURL)
Expand All @@ -214,7 +215,7 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error {
}
}

err = client.DestroyOffers(forceDestroy, input.OfferURL)
err = client.DestroyOffers(false, input.OfferURL)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/resource_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ resource "juju_integration" "a" {
application {
offer_url = juju_offer.b.url
}
depends_on = [juju_offer.b]
}
`, srcModelName, aOS, dstModelName, bOS, viaCIDRs)
}
Expand Down Expand Up @@ -315,6 +317,8 @@ resource "juju_integration" "b1" {
application {
offer_url = juju_offer.a.url
}
depends_on = [juju_offer.a]
}
resource "juju_application" "b2" {
Expand All @@ -339,6 +343,8 @@ resource "juju_integration" "b2" {
application {
offer_url = juju_offer.a.url
}
depends_on = [juju_offer.a]
}
variable "enable-b1-consumer" {
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/resource_offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ resource "juju_integration" "int" {
application {
offer_url = juju_offer.offerone.url
}
depends_on = [juju_offer.offerone]
}
`, srcModelName, destModelName)
}
Expand Down

0 comments on commit 3b09502

Please sign in to comment.