Skip to content

Commit

Permalink
fix(remove): Correctly search for networks when deleting machine (#1699)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Alexander Jung <alex@unikraft.io>
  • Loading branch information
nderjung authored Jun 7, 2024
2 parents b8468cd + 8590038 commit e6e6374
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions internal/cli/kraft/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

machineapi "kraftkit.sh/api/machine/v1alpha1"
networkapi "kraftkit.sh/api/network/v1alpha1"
Expand Down Expand Up @@ -157,14 +156,20 @@ func (opts *RemoveOptions) Run(ctx context.Context, args []string) error {
netcontrollers[net.Driver] = netcontroller
}

// Get the latest version of the network.
found, err := netcontroller.Get(ctx, &networkapi.Network{
ObjectMeta: metav1.ObjectMeta{
Name: net.IfName,
},
})
networks, err := netcontroller.List(ctx, &networkapi.NetworkList{})
if err != nil {
log.G(ctx).Warnf("could not get network information for %s: %v", net.IfName, err)
return err
}
var found *networkapi.Network

for _, network := range networks.Items {
if network.Spec.IfName == net.IfName {
found = &network
break
}
}
if found == nil {
log.G(ctx).Warnf("could not get network information for %s", net.IfName)
continue
}

Expand Down

0 comments on commit e6e6374

Please sign in to comment.