github.com/demonoid81/containerd@v1.3.4/services.go (about) 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 17 package containerd 18 19 import ( 20 containersapi "github.com/containerd/containerd/api/services/containers/v1" 21 "github.com/containerd/containerd/api/services/diff/v1" 22 imagesapi "github.com/containerd/containerd/api/services/images/v1" 23 namespacesapi "github.com/containerd/containerd/api/services/namespaces/v1" 24 "github.com/containerd/containerd/api/services/tasks/v1" 25 "github.com/containerd/containerd/containers" 26 "github.com/containerd/containerd/content" 27 "github.com/containerd/containerd/images" 28 "github.com/containerd/containerd/leases" 29 "github.com/containerd/containerd/namespaces" 30 "github.com/containerd/containerd/snapshots" 31 ) 32 33 type services struct { 34 contentStore content.Store 35 imageStore images.Store 36 containerStore containers.Store 37 namespaceStore namespaces.Store 38 snapshotters map[string]snapshots.Snapshotter 39 taskService tasks.TasksClient 40 diffService DiffService 41 eventService EventService 42 leasesService leases.Manager 43 } 44 45 // ServicesOpt allows callers to set options on the services 46 type ServicesOpt func(c *services) 47 48 // WithContentStore sets the content store. 49 func WithContentStore(contentStore content.Store) ServicesOpt { 50 return func(s *services) { 51 s.contentStore = contentStore 52 } 53 } 54 55 // WithImageService sets the image service. 56 func WithImageService(imageService imagesapi.ImagesClient) ServicesOpt { 57 return func(s *services) { 58 s.imageStore = NewImageStoreFromClient(imageService) 59 } 60 } 61 62 // WithSnapshotters sets the snapshotters. 63 func WithSnapshotters(snapshotters map[string]snapshots.Snapshotter) ServicesOpt { 64 return func(s *services) { 65 s.snapshotters = make(map[string]snapshots.Snapshotter) 66 for n, sn := range snapshotters { 67 s.snapshotters[n] = sn 68 } 69 } 70 } 71 72 // WithContainerService sets the container service. 73 func WithContainerService(containerService containersapi.ContainersClient) ServicesOpt { 74 return func(s *services) { 75 s.containerStore = NewRemoteContainerStore(containerService) 76 } 77 } 78 79 // WithTaskService sets the task service. 80 func WithTaskService(taskService tasks.TasksClient) ServicesOpt { 81 return func(s *services) { 82 s.taskService = taskService 83 } 84 } 85 86 // WithDiffService sets the diff service. 87 func WithDiffService(diffService diff.DiffClient) ServicesOpt { 88 return func(s *services) { 89 s.diffService = NewDiffServiceFromClient(diffService) 90 } 91 } 92 93 // WithEventService sets the event service. 94 func WithEventService(eventService EventService) ServicesOpt { 95 return func(s *services) { 96 s.eventService = eventService 97 } 98 } 99 100 // WithNamespaceService sets the namespace service. 101 func WithNamespaceService(namespaceService namespacesapi.NamespacesClient) ServicesOpt { 102 return func(s *services) { 103 s.namespaceStore = NewNamespaceStoreFromClient(namespaceService) 104 } 105 } 106 107 // WithLeasesService sets the lease service. 108 func WithLeasesService(leasesService leases.Manager) ServicesOpt { 109 return func(s *services) { 110 s.leasesService = leasesService 111 } 112 }