talos/internal/pkg/cri/images.go
Andrey Smirnov c10ef0f15a chore: extract CRI client as separate package
This is preparation for implementing CRI runner.

CRI client moved into its own package, I split it into multiple files
and added rudimentary tests for it.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-07-11 01:52:19 +03:00

39 lines
1.1 KiB
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package cri
import (
"context"
"github.com/pkg/errors"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)
// PullImage pulls container image
func (c *Client) PullImage(ctx context.Context, image *runtimeapi.ImageSpec, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
resp, err := c.imagesClient.PullImage(ctx, &runtimeapi.PullImageRequest{
Image: image,
SandboxConfig: sandboxConfig,
})
if err != nil {
return "", errors.Wrapf(err, "error pulling image %+v", image)
}
return resp.ImageRef, nil
}
// ListImages lists available images
func (c *Client) ListImages(ctx context.Context, filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
resp, err := c.imagesClient.ListImages(ctx, &runtimeapi.ListImagesRequest{
Filter: filter,
})
if err != nil {
return nil, errors.Wrapf(err, "error listing imags")
}
return resp.Images, nil
}