k8s.io/kubernetes@v1.29.3/pkg/kubelet/cri/remote/fake/fake_image_service.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package fake 18 19 import ( 20 "context" 21 22 kubeapi "k8s.io/cri-api/pkg/apis/runtime/v1" 23 ) 24 25 // ListImages lists existing images. 26 func (f *RemoteRuntime) ListImages(ctx context.Context, req *kubeapi.ListImagesRequest) (*kubeapi.ListImagesResponse, error) { 27 images, err := f.ImageService.ListImages(ctx, req.Filter) 28 if err != nil { 29 return nil, err 30 } 31 32 return &kubeapi.ListImagesResponse{ 33 Images: images, 34 }, nil 35 } 36 37 // ImageStatus returns the status of the image. If the image is not 38 // present, returns a response with ImageStatusResponse.Image set to 39 // nil. 40 func (f *RemoteRuntime) ImageStatus(ctx context.Context, req *kubeapi.ImageStatusRequest) (*kubeapi.ImageStatusResponse, error) { 41 resp, err := f.ImageService.ImageStatus(ctx, req.Image, false) 42 if err != nil { 43 return nil, err 44 } 45 46 return resp, nil 47 } 48 49 // PullImage pulls an image with authentication config. 50 func (f *RemoteRuntime) PullImage(ctx context.Context, req *kubeapi.PullImageRequest) (*kubeapi.PullImageResponse, error) { 51 image, err := f.ImageService.PullImage(ctx, req.Image, req.Auth, req.SandboxConfig) 52 if err != nil { 53 return nil, err 54 } 55 56 return &kubeapi.PullImageResponse{ 57 ImageRef: image, 58 }, nil 59 } 60 61 // RemoveImage removes the image. 62 // This call is idempotent, and must not return an error if the image has 63 // already been removed. 64 func (f *RemoteRuntime) RemoveImage(ctx context.Context, req *kubeapi.RemoveImageRequest) (*kubeapi.RemoveImageResponse, error) { 65 err := f.ImageService.RemoveImage(ctx, req.Image) 66 if err != nil { 67 return nil, err 68 } 69 70 return &kubeapi.RemoveImageResponse{}, nil 71 } 72 73 // ImageFsInfo returns information of the filesystem that is used to store images. 74 func (f *RemoteRuntime) ImageFsInfo(ctx context.Context, req *kubeapi.ImageFsInfoRequest) (*kubeapi.ImageFsInfoResponse, error) { 75 resp, err := f.ImageService.ImageFsInfo(ctx) 76 if err != nil { 77 return nil, err 78 } 79 80 return resp, nil 81 }