Skip to content

Commit

Permalink
fix(remove): Correctly search for networks when deleting machine
Browse files Browse the repository at this point in the history
Due to recent changes, the name of a network and the actual
interface name might differ, so we cannot directly query
for it. Instead, iterate through the networks and find the
one the interface belongs to.

Signed-off-by: Luca Seritan <[email protected]>
  • Loading branch information
LucaSeri committed Jun 3, 2024
1 parent 7bf661f commit 8590038
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 8590038

Please sign in to comment.