Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,6 @@ github.com/jumppad-labs/go-cty v0.0.0-20230804061424-9e985cb751f6 h1:1ADItCWr5pr
github.com/jumppad-labs/go-cty v0.0.0-20230804061424-9e985cb751f6/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/jumppad-labs/gohup v0.4.0 h1:0OplHvnKnOLkqWm417sRHLSiJ4xGeb8LiSSAJ51QrYg=
github.com/jumppad-labs/gohup v0.4.0/go.mod h1:JYvZnemxJlWDyx8RbDNcCBLZSvIrYlYLnkQqR1BKFW4=
github.com/jumppad-labs/hclconfig v0.26.0 h1:Qg/tC2WlhKwoTW0acAY/vyUXHwCuyr4NmshKLS81How=
github.com/jumppad-labs/hclconfig v0.26.0/go.mod h1:AOzW0btnKiqUKYVi3ioGzSPNCWsTzsJxKcqzVORccvk=
github.com/jumppad-labs/hclconfig v0.28.0 h1:6V6dMrTufkLHgyFdtJHiEcDM5hp9ItVNDZf98wGpVKs=
github.com/jumppad-labs/hclconfig v0.28.0/go.mod h1:mrKi8iCDAqLwmhbOa5k1K56R4+ctsVuYveQ/sMaWYio=
github.com/jumppad-labs/log v0.0.0-20240827082827-4404884e31a7 h1:tuoFYWXAqT5BheDlQNumY1DxvkW8bjG9JOzoxpFneZs=
Expand Down Expand Up @@ -1536,8 +1534,6 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/crypto v0.34.0 h1:+/C6tk6rf/+t5DhUketUbD1aNGqiSX3j15Z6xuIDlBA=
golang.org/x/crypto v0.34.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down
29 changes: 29 additions & 0 deletions pkg/config/resources/network/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,41 @@ func (p *Provider) Destroy(ctx context.Context, force bool) error {
}

if len(ids) == 1 {
networkID := ids[0]
// check if the network has containers attached
containers, err := p.getConnectedContainers(networkID)
if err != nil {
return fmt.Errorf("unable to list connected containers: %w", err)
}

for _, containerID := range containers {
err := p.client.NetworkDisconnect(context.Background(), networkID, containerID, true)
if err != nil {
return fmt.Errorf("unable to disconnect container from network: %w", err)
}
}

return p.client.NetworkRemove(context.Background(), p.config.Meta.Name)
}

return nil
}

func (p *Provider) getConnectedContainers(id string) ([]string, error) {
containers := []string{}

summary, err := p.client.NetworkInspect(context.Background(), id, network.InspectOptions{})
if err != nil {
return containers, err
}

for containerID := range summary.Containers {
containers = append(containers, containerID)
}

return containers, nil
}

// Lookup the ID for a network
func (p *Provider) Lookup() ([]string, error) {
nets, err := p.getNetworks(p.config.Meta.Name)
Expand Down
Loading