talm

Форк
0
/
images.go 
55 строк · 1.6 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package cri
6

7
import (
8
	"context"
9
	"fmt"
10

11
	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
12
)
13

14
// PullImage pulls container image.
15
func (c *Client) PullImage(ctx context.Context, image *runtimeapi.ImageSpec, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
16
	resp, err := c.imagesClient.PullImage(ctx, &runtimeapi.PullImageRequest{
17
		Image:         image,
18
		SandboxConfig: sandboxConfig,
19
	})
20
	if err != nil {
21
		return "", fmt.Errorf("error pulling image %s: %w", image, err)
22
	}
23

24
	return resp.ImageRef, nil
25
}
26

27
// ListImages lists available images.
28
func (c *Client) ListImages(ctx context.Context, filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
29
	resp, err := c.imagesClient.ListImages(ctx, &runtimeapi.ListImagesRequest{
30
		Filter: filter,
31
	})
32
	if err != nil {
33
		return nil, fmt.Errorf("error listing images: %w", err)
34
	}
35

36
	return resp.Images, nil
37
}
38

39
// ImageStatus returns the status of the image.
40
func (c *Client) ImageStatus(ctx context.Context, image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
41
	resp, err := c.imagesClient.ImageStatus(ctx, &runtimeapi.ImageStatusRequest{
42
		Image: image,
43
	})
44
	if err != nil {
45
		return nil, fmt.Errorf("ImageStatus %q from image service failed: %w", image.Image, err)
46
	}
47

48
	if resp.Image != nil {
49
		if resp.Image.Id == "" || resp.Image.Size_ == 0 {
50
			return nil, fmt.Errorf("id or size of image %q is not set", image.Image)
51
		}
52
	}
53

54
	return resp.Image, nil
55
}
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.