(names []string)
| 42 | } |
| 43 | |
| 44 | func 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 | } |
no outgoing calls
searching dependent graphs…