1/*
2   Copyright The containerd 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
17package server
18
19import (
20	"golang.org/x/net/context"
21	runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
22)
23
24// ListImages lists existing images.
25// TODO(random-liu): Add image list filters after CRI defines this more clear, and kubelet
26// actually needs it.
27func (c *criService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (*runtime.ListImagesResponse, error) {
28	imagesInStore := c.imageStore.List()
29
30	var images []*runtime.Image
31	for _, image := range imagesInStore {
32		// TODO(random-liu): [P0] Make sure corresponding snapshot exists. What if snapshot
33		// doesn't exist?
34		images = append(images, toCRIImage(image))
35	}
36
37	return &runtime.ListImagesResponse{Images: images}, nil
38}
39