MCPcopy
hub / github.com/containerd/containerd / List

Method List

core/metadata/containers.go:81–121  ·  view source on GitHub ↗
(ctx context.Context, fs ...string)

Source from the content-addressed store, hash-verified

79}
80
81func (s *containerStore) List(ctx context.Context, fs ...string) ([]containers.Container, error) {
82 namespace, err := namespaces.NamespaceRequired(ctx)
83 if err != nil {
84 return nil, err
85 }
86
87 filter, err := filters.ParseAll(fs...)
88 if err != nil {
89 return nil, fmt.Errorf("%s: %w", err.Error(), errdefs.ErrInvalidArgument)
90 }
91
92 var m []containers.Container
93
94 if err := view(ctx, s.db, func(tx *bolt.Tx) error {
95 bkt := getContainersBucket(tx, namespace)
96 if bkt == nil {
97 return nil // empty store
98 }
99
100 return bkt.ForEach(func(k, v []byte) error {
101 cbkt := bkt.Bucket(k)
102 if cbkt == nil {
103 return nil
104 }
105 container := containers.Container{ID: string(k)}
106
107 if err := readContainer(&container, cbkt); err != nil {
108 return fmt.Errorf("failed to read container %q: %w", string(k), err)
109 }
110
111 if filter.Match(adaptContainer(container)) {
112 m = append(m, container)
113 }
114 return nil
115 })
116 }); err != nil {
117 return nil, err
118 }
119
120 return m, nil
121}
122
123func (s *containerStore) Create(ctx context.Context, container containers.Container) (containers.Container, error) {
124 ctx, span := tracing.StartSpan(ctx,

Callers

nothing calls this directly

Calls 8

NamespaceRequiredFunction · 0.92
ParseAllFunction · 0.92
getContainersBucketFunction · 0.85
readContainerFunction · 0.85
adaptContainerFunction · 0.85
viewFunction · 0.70
MatchMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected