(ctx context.Context, client *containerd.Client, options types.NamespaceListOptions)
| 37 | ) |
| 38 | |
| 39 | func List(ctx context.Context, client *containerd.Client, options types.NamespaceListOptions) error { |
| 40 | nsStore := client.NamespaceService() |
| 41 | nsList, err := nsStore.List(ctx) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | dataStore, err := clientutil.DataStore(options.GOptions.DataRoot, options.GOptions.Address) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | w := options.Stdout |
| 52 | var tmpl *template.Template |
| 53 | namespaceList := []namespace{} |
| 54 | for _, ns := range nsList { |
| 55 | ctx = namespaces.WithNamespace(ctx, ns) |
| 56 | var numContainers, numImages, numVolumes int |
| 57 | |
| 58 | containers, err := client.Containers(ctx) |
| 59 | if err != nil { |
| 60 | log.L.Warn(err) |
| 61 | } |
| 62 | numContainers = len(containers) |
| 63 | |
| 64 | images, err := client.ImageService().List(ctx) |
| 65 | if err != nil { |
| 66 | log.L.Warn(err) |
| 67 | } |
| 68 | numImages = len(images) |
| 69 | |
| 70 | volStore, err := volumestore.New(dataStore, ns) |
| 71 | if err != nil { |
| 72 | log.L.Warn(err) |
| 73 | } else { |
| 74 | numVolumes, err = volStore.Count() |
| 75 | if err != nil { |
| 76 | log.L.Warn(err) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | labels, err := client.NamespaceService().Labels(ctx, ns) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | namespaceList = append(namespaceList, namespace{ |
| 85 | Name: ns, |
| 86 | Containers: numContainers, |
| 87 | Images: numImages, |
| 88 | Volumes: numVolumes, |
| 89 | Labels: labels, |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | switch options.Format { |
| 94 | case "", "table", "wide": |
| 95 | if !options.Quiet { |
| 96 | w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0) |
no test coverage detected
searching dependent graphs…