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

Function Detect

pkg/netutil/nettype/nettype.go:44–76  ·  view source on GitHub ↗
(names []string)

Source from the content-addressed store, hash-verified

42}
43
44func Detect(names []string) (Type, error) {
45 var res Type
46
47 for _, name := range names {
48 var tmp Type
49
50 // In case of using --network=container:<container> to share the network namespace
51 networkName := strings.SplitN(name, ":", 2)[0]
52 switch networkName {
53 case "none":
54 tmp = None
55 case "host":
56 tmp = Host
57 case "container":
58 tmp = Container
59 case "ns":
60 tmp = Namespace
61 default:
62 tmp = CNI
63 }
64 if res != Invalid && res != tmp {
65 return Invalid, fmt.Errorf("mixed network types: %v and %v", netTypeToName[res], netTypeToName[tmp])
66 }
67 res = tmp
68 }
69
70 // defaults to CNI
71 if res == Invalid {
72 res = CNI
73 }
74
75 return res, nil
76}

Callers 7

ReconfigNetContainerFunction · 0.92
namespaceUsedNetworksFunction · 0.92
cleanupNetworkFunction · 0.92
newHandlerOptsFunction · 0.92
TestDetectFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestDetectFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…