Skip to content

Commit

Permalink
Moved NetworkWalker to another package
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Timbota-Belin <mihai.mtb10@gmail.com>
  • Loading branch information
Mihai22125 committed Dec 3, 2022
1 parent baedff8 commit 827cd34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cmd/nerdctl/network_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"

"github.com/containerd/nerdctl/pkg/idutil/netwalker"
"github.com/containerd/nerdctl/pkg/netutil"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,9 +68,9 @@ func networkRmAction(cmd *cobra.Command, args []string) error {
return err
}

walker := netutil.NetworkWalker{
walker := netwalker.NetworkWalker{
Client: e,
OnFound: func(ctx context.Context, found netutil.Found) error {
OnFound: func(ctx context.Context, found netwalker.Found) error {
if found.MatchCount > 1 {
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
limitations under the License.
*/

package netutil
package netwalker

import (
"context"
"fmt"
"regexp"

"github.com/containerd/nerdctl/pkg/netutil"
)

type Found struct {
Network *NetworkConfig
Network *netutil.NetworkConfig
Req string // The raw request string. name, short ID, or long ID.
MatchIndex int // Begins with 0, up to MatchCount - 1.
MatchCount int // 1 on exact match. > 1 on ambiguous match. Never be <= 0.
Expand All @@ -32,7 +34,7 @@ type Found struct {
type OnFound func(ctx context.Context, found Found) error

type NetworkWalker struct {
Client *CNIEnv
Client *netutil.CNIEnv
OnFound OnFound
}

Expand All @@ -50,7 +52,7 @@ func (w *NetworkWalker) Walk(ctx context.Context, req string) (int, error) {
return 0, err
}

networks := []*NetworkConfig{}
networks := []*netutil.NetworkConfig{}
for _, n := range w.Client.Networks {
if n.Name == req || longIDExp.Match([]byte(*n.NerdctlID)) || shortIDExp.Match([]byte(*n.NerdctlID)) {
networks = append(networks, n)
Expand Down

0 comments on commit 827cd34

Please sign in to comment.