Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/services/introspection"
"github.com/containerd/containerd/snapshots"
snproxy "github.com/containerd/containerd/snapshots/proxy"
"github.com/containerd/typeurl"
Expand Down Expand Up @@ -621,10 +622,13 @@ func (c *Client) DiffService() DiffService {
}

// IntrospectionService returns the underlying Introspection Client
func (c *Client) IntrospectionService() introspectionapi.IntrospectionClient {
func (c *Client) IntrospectionService() introspection.Service {
if c.introspectionService != nil {
return c.introspectionService
}
c.connMu.Lock()
defer c.connMu.Unlock()
return introspectionapi.NewIntrospectionClient(c.conn)
return introspection.NewIntrospectionServiceFromClient(introspectionapi.NewIntrospectionClient(c.conn))
}

// LeasesService returns the underlying Leases Client
Expand Down
5 changes: 1 addition & 4 deletions cmd/ctr/commands/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"
"text/tabwriter"

introspection "github.com/containerd/containerd/api/services/introspection/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/platforms"
Expand Down Expand Up @@ -67,9 +66,7 @@ var listCommand = cli.Command{
}
defer cancel()
ps := client.IntrospectionService()
response, err := ps.Plugins(ctx, &introspection.PluginsRequest{
Filters: context.Args(),
})
response, err := ps.Plugins(ctx, context.Args())
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"runtime"
"strings"

introspectionapi "github.com/containerd/containerd/api/services/introspection/v1"
"github.com/containerd/containerd/archive"
"github.com/containerd/containerd/archive/compression"
"github.com/containerd/containerd/content"
Expand Down Expand Up @@ -99,11 +98,8 @@ func (c *Client) getInstallPath(ctx context.Context, config InstallConfig) (stri
if config.Path != "" {
return config.Path, nil
}
resp, err := c.IntrospectionService().Plugins(ctx, &introspectionapi.PluginsRequest{
Filters: []string{
"id==opt",
},
})
filters := []string{"id==opt"}
resp, err := c.IntrospectionService().Plugins(ctx, filters)
if err != nil {
return "", err
}
Expand Down
28 changes: 19 additions & 9 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ import (
containersapi "github.com/containerd/containerd/api/services/containers/v1"
"github.com/containerd/containerd/api/services/diff/v1"
imagesapi "github.com/containerd/containerd/api/services/images/v1"
introspectionapi "github.com/containerd/containerd/api/services/introspection/v1"
namespacesapi "github.com/containerd/containerd/api/services/namespaces/v1"
"github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/services/introspection"
"github.com/containerd/containerd/snapshots"
)

type services struct {
contentStore content.Store
imageStore images.Store
containerStore containers.Store
namespaceStore namespaces.Store
snapshotters map[string]snapshots.Snapshotter
taskService tasks.TasksClient
diffService DiffService
eventService EventService
leasesService leases.Manager
contentStore content.Store
imageStore images.Store
containerStore containers.Store
namespaceStore namespaces.Store
snapshotters map[string]snapshots.Snapshotter
taskService tasks.TasksClient
diffService DiffService
eventService EventService
leasesService leases.Manager
introspectionService introspection.Service
}

// ServicesOpt allows callers to set options on the services
Expand Down Expand Up @@ -110,3 +113,10 @@ func WithLeasesService(leasesService leases.Manager) ServicesOpt {
s.leasesService = leasesService
}
}

// WithIntrospectionService sets the introspection service.
func WithIntrospectionService(in introspectionapi.IntrospectionClient) ServicesOpt {
return func(s *services) {
s.introspectionService = introspection.NewIntrospectionServiceFromClient(in)
}
}
62 changes: 62 additions & 0 deletions services/introspection/introspection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package introspection

import (
context "context"

api "github.com/containerd/containerd/api/services/introspection/v1"
"github.com/containerd/containerd/errdefs"
ptypes "github.com/gogo/protobuf/types"
)

type Service interface {
Plugins(context.Context, []string) (*api.PluginsResponse, error)
Server(context.Context, *ptypes.Empty) (*api.ServerResponse, error)
}

type introspectionRemote struct {
client api.IntrospectionClient
}

var _ = (Service)(&introspectionRemote{})

func NewIntrospectionServiceFromClient(c api.IntrospectionClient) Service {
return &introspectionRemote{client: c}
}

func (i *introspectionRemote) Plugins(ctx context.Context, filters []string) (*api.PluginsResponse, error) {
resp, err := i.client.Plugins(ctx, &api.PluginsRequest{
Filters: filters,
})

if err != nil {
return nil, errdefs.FromGRPC(err)
}

return resp, nil
}

func (i *introspectionRemote) Server(ctx context.Context, in *ptypes.Empty) (*api.ServerResponse, error) {
resp, err := i.client.Server(ctx, in)

if err != nil {
return nil, errdefs.FromGRPC(err)
}

return resp, nil
}
Loading