github.com/containerd/Containerd@v1.4.13/services/namespaces/service.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 namespaces 18 19 import ( 20 "context" 21 22 api "github.com/containerd/containerd/api/services/namespaces/v1" 23 "github.com/containerd/containerd/plugin" 24 "github.com/containerd/containerd/services" 25 ptypes "github.com/gogo/protobuf/types" 26 "github.com/pkg/errors" 27 "google.golang.org/grpc" 28 ) 29 30 func init() { 31 plugin.Register(&plugin.Registration{ 32 Type: plugin.GRPCPlugin, 33 ID: "namespaces", 34 Requires: []plugin.Type{ 35 plugin.ServicePlugin, 36 }, 37 InitFn: func(ic *plugin.InitContext) (interface{}, error) { 38 plugins, err := ic.GetByType(plugin.ServicePlugin) 39 if err != nil { 40 return nil, err 41 } 42 p, ok := plugins[services.NamespacesService] 43 if !ok { 44 return nil, errors.New("namespaces service not found") 45 } 46 i, err := p.Instance() 47 if err != nil { 48 return nil, err 49 } 50 return &service{local: i.(api.NamespacesClient)}, nil 51 }, 52 }) 53 } 54 55 type service struct { 56 local api.NamespacesClient 57 } 58 59 var _ api.NamespacesServer = &service{} 60 61 func (s *service) Register(server *grpc.Server) error { 62 api.RegisterNamespacesServer(server, s) 63 return nil 64 } 65 66 func (s *service) Get(ctx context.Context, req *api.GetNamespaceRequest) (*api.GetNamespaceResponse, error) { 67 return s.local.Get(ctx, req) 68 } 69 70 func (s *service) List(ctx context.Context, req *api.ListNamespacesRequest) (*api.ListNamespacesResponse, error) { 71 return s.local.List(ctx, req) 72 } 73 74 func (s *service) Create(ctx context.Context, req *api.CreateNamespaceRequest) (*api.CreateNamespaceResponse, error) { 75 return s.local.Create(ctx, req) 76 } 77 78 func (s *service) Update(ctx context.Context, req *api.UpdateNamespaceRequest) (*api.UpdateNamespaceResponse, error) { 79 return s.local.Update(ctx, req) 80 } 81 82 func (s *service) Delete(ctx context.Context, req *api.DeleteNamespaceRequest) (*ptypes.Empty, error) { 83 return s.local.Delete(ctx, req) 84 }