Skip to content

Commit cbe538e

Browse files
authored
implement imageList (#513)
1 parent e80a382 commit cbe538e

File tree

14 files changed

+1583
-1101
lines changed

14 files changed

+1583
-1101
lines changed

cluster/calcium/image.go

+53
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,56 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha
129129

130130
return ch, nil
131131
}
132+
133+
// ListImage list Image on a pod or some nodes.
134+
func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan *types.ListImageMessage, error) {
135+
logger := log.WithField("Calcium", "ListImage").WithField("opts", opts)
136+
opts.Normalize()
137+
138+
nodes, err := c.filterNodes(ctx, types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
139+
if err != nil {
140+
return nil, logger.Err(ctx, err)
141+
}
142+
143+
if len(nodes) == 0 {
144+
return nil, logger.Err(ctx, errors.WithStack(types.ErrPodNoNodes))
145+
}
146+
147+
ch := make(chan *types.ListImageMessage)
148+
149+
utils.SentryGo(func() {
150+
defer close(ch)
151+
wg := sync.WaitGroup{}
152+
defer wg.Wait()
153+
for i, node := range nodes {
154+
wg.Add(1)
155+
utils.SentryGo(func(node *types.Node) func() {
156+
return func() {
157+
defer wg.Done()
158+
msg := &types.ListImageMessage{
159+
Images: []*types.Image{},
160+
Nodename: node.Name,
161+
Error: nil,
162+
}
163+
if images, err := node.Engine.ImageList(ctx, opts.Filter); err != nil {
164+
msg.Error = logger.Err(ctx, err)
165+
} else {
166+
for _, image := range images {
167+
msg.Images = append(msg.Images, &types.Image{
168+
ID: image.ID,
169+
Tags: image.Tags,
170+
})
171+
}
172+
}
173+
ch <- msg
174+
}
175+
}(node))
176+
if (i+1)%opts.Step == 0 {
177+
log.Info("[ListImage] Wait for image listed")
178+
wg.Wait()
179+
}
180+
}
181+
})
182+
183+
return ch, nil
184+
}

cluster/cluster.go

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type Cluster interface {
7777
BuildImage(ctx context.Context, opts *types.BuildOptions) (chan *types.BuildImageMessage, error)
7878
CacheImage(ctx context.Context, opts *types.ImageOptions) (chan *types.CacheImageMessage, error)
7979
RemoveImage(ctx context.Context, opts *types.ImageOptions) (chan *types.RemoveImageMessage, error)
80+
ListImage(ctx context.Context, opts *types.ImageOptions) (chan *types.ListImageMessage, error)
8081
// workload methods
8182
CreateWorkload(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateWorkloadMessage, error)
8283
ReplaceWorkload(ctx context.Context, opts *types.ReplaceOptions) (chan *types.ReplaceWorkloadMessage, error)

cluster/mocks/Cluster.go

+24-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/virt/image.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ import (
1414
)
1515

1616
// ImageList lists images.
17-
func (v *Virt) ImageList(ctx context.Context, image string) (imgs []*enginetypes.Image, err error) {
18-
log.Warnf(ctx, "ImageList does not implement")
17+
func (v *Virt) ImageList(ctx context.Context, imageName string) (imgs []*enginetypes.Image, err error) {
18+
images, err := v.client.ListImage(ctx, imageName)
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
imgs = []*enginetypes.Image{}
24+
25+
for _, image := range images {
26+
imgs = append(imgs, &enginetypes.Image{
27+
ID: image.Id,
28+
Tags: []string{image.Name},
29+
})
30+
}
31+
1932
return
2033
}
2134

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/opencontainers/runc v1.0.0-rc95 // indirect
3333
github.com/patrickmn/go-cache v2.1.0+incompatible
3434
github.com/pkg/errors v0.9.1
35-
github.com/projecteru2/libyavirt v0.0.0-20211202092239-8539e8218458
35+
github.com/projecteru2/libyavirt v0.0.0-20211213024339-7490368380c0
3636
github.com/prometheus/client_golang v1.11.0
3737
github.com/sanity-io/litter v1.5.1
3838
github.com/sirupsen/logrus v1.7.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
430430
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
431431
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
432432
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
433-
github.com/projecteru2/libyavirt v0.0.0-20211202092239-8539e8218458 h1:/vzYKTEuiRyb2izwt/ZiafWsrcBHCLDbqbJBkHWUKOQ=
434-
github.com/projecteru2/libyavirt v0.0.0-20211202092239-8539e8218458/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
433+
github.com/projecteru2/libyavirt v0.0.0-20211213024339-7490368380c0 h1:Fzx/e/V/GoLdiiqBEhH/srG9003oOBBOgqWsRdWkv6Y=
434+
github.com/projecteru2/libyavirt v0.0.0-20211213024339-7490368380c0/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
435435
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
436436
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
437437
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

rpc/errors.go

+2
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,6 @@ const (
8787
LogStream codes.Code = 10711
8888
// RunAndWait .
8989
RunAndWait codes.Code = 10712
90+
// ListImage .
91+
ListImage codes.Code = 10713
9092
)

0 commit comments

Comments
 (0)