Skip to content

Commit

Permalink
implement imageList (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceralon authored Dec 13, 2021
1 parent e80a382 commit cbe538e
Show file tree
Hide file tree
Showing 14 changed files with 1,583 additions and 1,101 deletions.
53 changes: 53 additions & 0 deletions cluster/calcium/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,56 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha

return ch, nil
}

// ListImage list Image on a pod or some nodes.
func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan *types.ListImageMessage, error) {
logger := log.WithField("Calcium", "ListImage").WithField("opts", opts)
opts.Normalize()

nodes, err := c.filterNodes(ctx, types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
if err != nil {
return nil, logger.Err(ctx, err)
}

if len(nodes) == 0 {
return nil, logger.Err(ctx, errors.WithStack(types.ErrPodNoNodes))
}

ch := make(chan *types.ListImageMessage)

utils.SentryGo(func() {
defer close(ch)
wg := sync.WaitGroup{}
defer wg.Wait()
for i, node := range nodes {
wg.Add(1)
utils.SentryGo(func(node *types.Node) func() {
return func() {
defer wg.Done()
msg := &types.ListImageMessage{
Images: []*types.Image{},
Nodename: node.Name,
Error: nil,
}
if images, err := node.Engine.ImageList(ctx, opts.Filter); err != nil {
msg.Error = logger.Err(ctx, err)
} else {
for _, image := range images {
msg.Images = append(msg.Images, &types.Image{
ID: image.ID,
Tags: image.Tags,
})
}
}
ch <- msg
}
}(node))
if (i+1)%opts.Step == 0 {
log.Info("[ListImage] Wait for image listed")
wg.Wait()
}
}
})

return ch, nil
}
1 change: 1 addition & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Cluster interface {
BuildImage(ctx context.Context, opts *types.BuildOptions) (chan *types.BuildImageMessage, error)
CacheImage(ctx context.Context, opts *types.ImageOptions) (chan *types.CacheImageMessage, error)
RemoveImage(ctx context.Context, opts *types.ImageOptions) (chan *types.RemoveImageMessage, error)
ListImage(ctx context.Context, opts *types.ImageOptions) (chan *types.ListImageMessage, error)
// workload methods
CreateWorkload(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateWorkloadMessage, error)
ReplaceWorkload(ctx context.Context, opts *types.ReplaceOptions) (chan *types.ReplaceWorkloadMessage, error)
Expand Down
25 changes: 24 additions & 1 deletion cluster/mocks/Cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions engine/virt/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ import (
)

// ImageList lists images.
func (v *Virt) ImageList(ctx context.Context, image string) (imgs []*enginetypes.Image, err error) {
log.Warnf(ctx, "ImageList does not implement")
func (v *Virt) ImageList(ctx context.Context, imageName string) (imgs []*enginetypes.Image, err error) {
images, err := v.client.ListImage(ctx, imageName)
if err != nil {
return nil, err
}

imgs = []*enginetypes.Image{}

for _, image := range images {
imgs = append(imgs, &enginetypes.Image{
ID: image.Id,
Tags: []string{image.Name},
})
}

return
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/opencontainers/runc v1.0.0-rc95 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/projecteru2/libyavirt v0.0.0-20211202092239-8539e8218458
github.com/projecteru2/libyavirt v0.0.0-20211213024339-7490368380c0
github.com/prometheus/client_golang v1.11.0
github.com/sanity-io/litter v1.5.1
github.com/sirupsen/logrus v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/projecteru2/libyavirt v0.0.0-20211202092239-8539e8218458 h1:/vzYKTEuiRyb2izwt/ZiafWsrcBHCLDbqbJBkHWUKOQ=
github.com/projecteru2/libyavirt v0.0.0-20211202092239-8539e8218458/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
github.com/projecteru2/libyavirt v0.0.0-20211213024339-7490368380c0 h1:Fzx/e/V/GoLdiiqBEhH/srG9003oOBBOgqWsRdWkv6Y=
github.com/projecteru2/libyavirt v0.0.0-20211213024339-7490368380c0/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
Expand Down
2 changes: 2 additions & 0 deletions rpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ const (
LogStream codes.Code = 10711
// RunAndWait .
RunAndWait codes.Code = 10712
// ListImage .
ListImage codes.Code = 10713
)
Loading

0 comments on commit cbe538e

Please sign in to comment.