(ctx context.Context, client *containerd.Client)
| 122 | } |
| 123 | |
| 124 | func UsedNetworks(ctx context.Context, client *containerd.Client) (map[string][]string, error) { |
| 125 | nsService := client.NamespaceService() |
| 126 | nsList, err := nsService.List(ctx) |
| 127 | if err != nil { |
| 128 | return nil, err |
| 129 | } |
| 130 | used := make(map[string][]string) |
| 131 | for _, ns := range nsList { |
| 132 | nsCtx := namespaces.WithNamespace(ctx, ns) |
| 133 | containers, err := client.Containers(nsCtx) |
| 134 | if err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | nsUsedN, err := namespaceUsedNetworks(nsCtx, containers) |
| 138 | if err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | |
| 142 | // merge |
| 143 | for k, v := range nsUsedN { |
| 144 | if value, ok := used[k]; ok { |
| 145 | used[k] = append(value, v...) |
| 146 | } else { |
| 147 | used[k] = v |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | return used, nil |
| 152 | } |
| 153 | |
| 154 | func namespaceUsedNetworks(ctx context.Context, containers []containerd.Container) (map[string][]string, error) { |
| 155 | used := make(map[string][]string) |
no test coverage detected
searching dependent graphs…