MCPcopy Create free account
hub / github.com/containerd/nerdctl / Prune

Function Prune

pkg/cmd/network/prune.go:31–73  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, options types.NetworkPruneOptions)

Source from the content-addressed store, hash-verified

29)
30
31func Prune(ctx context.Context, client *containerd.Client, options types.NetworkPruneOptions) error {
32 e, err := netutil.NewCNIEnv(options.GOptions.CNIPath, options.GOptions.CNINetConfPath, netutil.WithNamespace(options.GOptions.Namespace))
33 if err != nil {
34 return err
35 }
36
37 usedNetworks, err := netutil.UsedNetworks(ctx, client)
38 if err != nil {
39 return err
40 }
41
42 networkConfigs, err := e.NetworkList()
43 if err != nil {
44 return err
45 }
46
47 var removedNetworks []string // nolint: prealloc
48 for _, net := range networkConfigs {
49 if strutil.InStringSlice(options.NetworkDriversToKeep, net.Name) {
50 continue
51 }
52 if net.NerdctlID == nil || net.File == "" {
53 continue
54 }
55 if _, ok := usedNetworks[net.Name]; ok {
56 continue
57 }
58 if err := e.RemoveNetwork(net); err != nil {
59 log.G(ctx).WithError(err).Errorf("failed to remove network %s", net.Name)
60 continue
61 }
62 removedNetworks = append(removedNetworks, net.Name)
63 }
64
65 if len(removedNetworks) > 0 {
66 fmt.Fprintln(options.Stdout, "Deleted Networks:")
67 for _, name := range removedNetworks {
68 fmt.Fprintln(options.Stdout, name)
69 }
70 fmt.Fprintln(options.Stdout, "")
71 }
72 return nil
73}

Callers 2

PruneFunction · 0.92
pruneActionFunction · 0.92

Calls 6

NetworkListMethod · 0.95
RemoveNetworkMethod · 0.95
NewCNIEnvFunction · 0.92
WithNamespaceFunction · 0.92
UsedNetworksFunction · 0.92
InStringSliceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…