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