fake_image_service.go 2.5 KB

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