diff --git a/pkg/cmd/network/inspect.go b/pkg/cmd/network/inspect.go index a958cc9fa9e..6bacb75e445 100644 --- a/pkg/cmd/network/inspect.go +++ b/pkg/cmd/network/inspect.go @@ -21,7 +21,6 @@ import ( "encoding/json" "errors" "fmt" - "slices" containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/log" @@ -60,7 +59,7 @@ func Inspect(ctx context.Context, client *containerd.Client, options types.Netwo network := netList[0] - var filters = []string{fmt.Sprintf("labels.%q~=%q", labels.Networks, network.Name)} + var filters = []string{fmt.Sprintf(`labels.%q~="\\\"%s\\\""`, labels.Networks, network.Name)} filteredContainers, err := client.Containers(ctx, filters...) if err != nil { return err @@ -76,13 +75,7 @@ func Inspect(ctx context.Context, client *containerd.Client, options types.Netwo continue } - isNetworkMember, err := isContainerInNetwork(ctx, container, network.Name) - if err != nil { - return err - } - if isNetworkMember { - containers = append(containers, nativeContainer) - } + containers = append(containers, nativeContainer) } r := &native.Network{ @@ -119,20 +112,3 @@ func Inspect(ctx context.Context, client *containerd.Client, options types.Netwo return err } - -func isContainerInNetwork(ctx context.Context, container containerd.Container, networkName string) (bool, error) { - info, err := container.Info(ctx) - if err != nil { - return false, err - } - networkLabels, ok := info.Labels[labels.Networks] - if !ok { - return false, nil - } - - var containerNetworks []string - if err := json.Unmarshal([]byte(networkLabels), &containerNetworks); err != nil { - return false, err - } - return slices.Contains(containerNetworks, networkName), nil -}