2022-07-05 10:33:39 -04:00
|
|
|
package containerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-10 09:22:32 -04:00
|
|
|
"errors"
|
2022-07-05 10:33:39 -04:00
|
|
|
|
|
|
|
"github.com/containerd/containerd"
|
2022-08-22 12:36:03 -04:00
|
|
|
"github.com/containerd/containerd/plugin"
|
2022-07-05 10:33:39 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/container"
|
|
|
|
"github.com/docker/docker/daemon/images"
|
2022-08-10 09:22:32 -04:00
|
|
|
"github.com/docker/docker/errdefs"
|
2022-07-05 10:33:39 -04:00
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageService implements daemon.ImageService
|
|
|
|
type ImageService struct {
|
2022-08-03 05:20:54 -04:00
|
|
|
client *containerd.Client
|
|
|
|
snapshotter string
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewService creates a new ImageService.
|
2022-08-03 05:20:54 -04:00
|
|
|
func NewService(c *containerd.Client, snapshotter string) *ImageService {
|
2022-07-05 10:33:39 -04:00
|
|
|
return &ImageService{
|
2022-08-03 05:20:54 -04:00
|
|
|
client: c,
|
|
|
|
snapshotter: snapshotter,
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// DistributionServices return services controlling daemon image storage.
|
|
|
|
func (i *ImageService) DistributionServices() images.DistributionServices {
|
|
|
|
return images.DistributionServices{}
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// CountImages returns the number of images stored by ImageService
|
|
|
|
// called from info.go
|
|
|
|
func (i *ImageService) CountImages() int {
|
|
|
|
imgs, err := i.client.ListImages(context.TODO())
|
2022-07-05 10:33:39 -04:00
|
|
|
if err != nil {
|
2022-07-18 06:51:49 -04:00
|
|
|
return 0
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
return len(imgs)
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// Children returns the children image.IDs for a parent image.
|
|
|
|
// called from list.go to filter containers
|
|
|
|
// TODO: refactor to expose an ancestry for image.ID?
|
|
|
|
func (i *ImageService) Children(id image.ID) []image.ID {
|
2022-07-05 10:33:39 -04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// CreateLayer creates a filesystem layer for a container.
|
|
|
|
// called from create.go
|
|
|
|
// TODO: accept an opt struct instead of container?
|
|
|
|
func (i *ImageService) CreateLayer(container *container.Container, initFunc layer.MountInit) (layer.RWLayer, error) {
|
2022-08-10 09:22:32 -04:00
|
|
|
return nil, errdefs.NotImplemented(errdefs.NotImplemented(errors.New("not implemented")))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetLayerByID returns a layer by ID
|
|
|
|
// called from daemon.go Daemon.restore(), and Daemon.containerExport().
|
2022-07-18 06:51:49 -04:00
|
|
|
func (i *ImageService) GetLayerByID(cid string) (layer.RWLayer, error) {
|
2022-08-10 09:22:32 -04:00
|
|
|
return nil, errdefs.NotImplemented(errors.New("not implemented"))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// LayerStoreStatus returns the status for each layer store
|
|
|
|
// called from info.go
|
|
|
|
func (i *ImageService) LayerStoreStatus() [][2]string {
|
2022-08-22 12:36:03 -04:00
|
|
|
// TODO(thaJeztah) do we want to add more details about the driver here?
|
|
|
|
return [][2]string{
|
|
|
|
{"driver-type", string(plugin.SnapshotPlugin)},
|
|
|
|
}
|
2022-07-18 06:51:49 -04:00
|
|
|
}
|
|
|
|
|
2022-07-05 10:33:39 -04:00
|
|
|
// GetLayerMountID returns the mount ID for a layer
|
|
|
|
// called from daemon.go Daemon.Shutdown(), and Daemon.Cleanup() (cleanup is actually continerCleanup)
|
|
|
|
// TODO: needs to be refactored to Unmount (see callers), or removed and replaced with GetLayerByID
|
2022-07-18 06:51:49 -04:00
|
|
|
func (i *ImageService) GetLayerMountID(cid string) (string, error) {
|
2022-08-10 09:22:32 -04:00
|
|
|
return "", errdefs.NotImplemented(errors.New("not implemented"))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup resources before the process is shutdown.
|
|
|
|
// called from daemon.go Daemon.Shutdown()
|
2022-07-18 04:57:11 -04:00
|
|
|
func (i *ImageService) Cleanup() error {
|
2022-07-05 10:33:39 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-09 11:03:50 -04:00
|
|
|
// StorageDriver returns the name of the default storage-driver (snapshotter)
|
|
|
|
// used by the ImageService.
|
|
|
|
func (i *ImageService) StorageDriver() string {
|
2022-08-03 05:20:54 -04:00
|
|
|
return i.snapshotter
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// ReleaseLayer releases a layer allowing it to be removed
|
|
|
|
// called from delete.go Daemon.cleanupContainer(), and Daemon.containerExport()
|
|
|
|
func (i *ImageService) ReleaseLayer(rwlayer layer.RWLayer) error {
|
2022-08-10 09:22:32 -04:00
|
|
|
return errdefs.NotImplemented(errors.New("not implemented"))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// LayerDiskUsage returns the number of bytes used by layer stores
|
|
|
|
// called from disk_usage.go
|
2022-07-18 04:57:11 -04:00
|
|
|
func (i *ImageService) LayerDiskUsage(ctx context.Context) (int64, error) {
|
2022-08-10 09:22:32 -04:00
|
|
|
return 0, errdefs.NotImplemented(errors.New("not implemented"))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// ImageDiskUsage returns information about image data disk usage.
|
|
|
|
func (i *ImageService) ImageDiskUsage(ctx context.Context) ([]*types.ImageSummary, error) {
|
2022-08-10 09:22:32 -04:00
|
|
|
return nil, errdefs.NotImplemented(errors.New("not implemented"))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// UpdateConfig values
|
|
|
|
//
|
|
|
|
// called from reload.go
|
|
|
|
func (i *ImageService) UpdateConfig(maxDownloads, maxUploads int) {
|
2022-07-05 10:33:39 -04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2022-07-18 06:51:49 -04:00
|
|
|
// GetLayerFolders returns the layer folders from an image RootFS.
|
|
|
|
func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer) ([]string, error) {
|
2022-08-10 09:22:32 -04:00
|
|
|
return nil, errdefs.NotImplemented(errors.New("not implemented"))
|
2022-07-05 10:33:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetContainerLayerSize returns the real size & virtual size of the container.
|
2022-07-18 04:57:11 -04:00
|
|
|
func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64) {
|
2022-07-05 10:33:39 -04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|