Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit a7d5dab

Browse files
author
David Chung
authored
Use plugin.Name instead of string in all plugin confiugrations (#362)
Signed-off-by: David Chung <[email protected]>
1 parent 5a6c860 commit a7d5dab

File tree

16 files changed

+112
-36
lines changed

16 files changed

+112
-36
lines changed

cmd/cli/flavor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
log "github.com/Sirupsen/logrus"
1111
"github.com/docker/infrakit/pkg/discovery"
12+
"github.com/docker/infrakit/pkg/plugin"
1213
"github.com/docker/infrakit/pkg/plugin/group/types"
1314
flavor_plugin "github.com/docker/infrakit/pkg/rpc/flavor"
1415
"github.com/docker/infrakit/pkg/spi/flavor"
@@ -28,7 +29,7 @@ func flavorPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
2829

2930
cmd.PersistentPreRunE = func(c *cobra.Command, args []string) error {
3031

31-
endpoint, err := plugins().Find(*name)
32+
endpoint, err := plugins().Find(plugin.Name(*name))
3233
if err != nil {
3334
return err
3435
}

cmd/cli/group.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
log "github.com/Sirupsen/logrus"
1212
"github.com/docker/infrakit/pkg/discovery"
13+
"github.com/docker/infrakit/pkg/plugin"
1314
group_plugin "github.com/docker/infrakit/pkg/rpc/group"
1415
"github.com/docker/infrakit/pkg/spi/group"
1516
"github.com/spf13/cobra"
@@ -31,7 +32,7 @@ func groupPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
3132
name := cmd.PersistentFlags().String("name", DefaultGroupPluginName, "Name of plugin")
3233
cmd.PersistentPreRunE = func(c *cobra.Command, args []string) error {
3334

34-
endpoint, err := plugins().Find(*name)
35+
endpoint, err := plugins().Find(plugin.Name(*name))
3536
if err != nil {
3637
return err
3738
}

cmd/cli/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func instancePluginCommand(plugins func() discovery.Plugins) *cobra.Command {
2727
name := cmd.PersistentFlags().String("name", "", "Name of plugin")
2828
cmd.PersistentPreRunE = func(c *cobra.Command, args []string) error {
2929

30-
endpoint, err := plugins().Find(*name)
30+
endpoint, err := plugins().Find(plugin.Name(*name))
3131
if err != nil {
3232
return err
3333
}

cmd/group/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ func main() {
3636
return err
3737
}
3838

39-
instancePluginLookup := func(n string) (instance.Plugin, error) {
39+
instancePluginLookup := func(n plugin.Name) (instance.Plugin, error) {
4040
endpoint, err := plugins.Find(n)
4141
if err != nil {
4242
return nil, err
4343
}
4444
return instance_client.NewClient(plugin.Name(n), endpoint.Address), nil
4545
}
4646

47-
flavorPluginLookup := func(n string) (flavor.Plugin, error) {
47+
flavorPluginLookup := func(n plugin.Name) (flavor.Plugin, error) {
4848
endpoint, err := plugins.Find(n)
4949
if err != nil {
5050
return nil, err

pkg/cli/info.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/docker/infrakit/pkg/discovery"
8+
"github.com/docker/infrakit/pkg/plugin"
89
"github.com/docker/infrakit/pkg/rpc/client"
910
"github.com/spf13/cobra"
1011
)
@@ -17,7 +18,7 @@ func InfoCommand(plugins func() discovery.Plugins) *cobra.Command {
1718
}
1819
name := cmd.PersistentFlags().String("name", "", "Name of plugin")
1920
cmd.RunE = func(cmd *cobra.Command, args []string) error {
20-
endpoint, err := plugins().Find(*name)
21+
endpoint, err := plugins().Find(plugin.Name(*name))
2122
if err != nil {
2223
return err
2324
}

pkg/discovery/dir.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type dirPluginDiscovery struct {
1717
}
1818

1919
// Find returns a plugin by name
20-
func (r *dirPluginDiscovery) Find(name string) (*plugin.Endpoint, error) {
21-
lookup, _ := plugin.Name(name).GetLookupAndType()
20+
func (r *dirPluginDiscovery) Find(name plugin.Name) (*plugin.Endpoint, error) {
21+
lookup, _ := name.GetLookupAndType()
2222
plugins, err := r.List()
2323
if err != nil {
2424
return nil, err

pkg/discovery/dir_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88
"time"
99

10+
"github.com/docker/infrakit/pkg/plugin"
1011
rpc "github.com/docker/infrakit/pkg/rpc/instance"
1112
"github.com/docker/infrakit/pkg/rpc/server"
1213
"github.com/stretchr/testify/require"
@@ -44,33 +45,33 @@ func TestDirDiscovery(t *testing.T) {
4445
discover, err := newDirPluginDiscovery(dir)
4546
require.NoError(t, err)
4647

47-
p, err := discover.Find(name1)
48+
p, err := discover.Find(plugin.Name(name1))
4849
require.NoError(t, err)
4950
require.NotNil(t, p)
5051

51-
p, err = discover.Find(name2)
52+
p, err = discover.Find(plugin.Name(name2))
5253
require.NoError(t, err)
5354
require.NotNil(t, p)
5455

5556
// Now we stop the servers
5657
server1.Stop()
5758
blockWhileFileExists(path1)
5859

59-
p, err = discover.Find(name1)
60+
p, err = discover.Find(plugin.Name(name1))
6061
require.Error(t, err)
6162

62-
p, err = discover.Find(name2)
63+
p, err = discover.Find(plugin.Name(name2))
6364
require.NoError(t, err)
6465
require.NotNil(t, p)
6566

6667
server2.Stop()
6768

6869
blockWhileFileExists(path2)
6970

70-
p, err = discover.Find(name1)
71+
p, err = discover.Find(plugin.Name(name1))
7172
require.Error(t, err)
7273

73-
p, err = discover.Find(name2)
74+
p, err = discover.Find(plugin.Name(name2))
7475
require.Error(t, err)
7576

7677
list, err := discover.List()

pkg/discovery/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// Plugins provides access to plugin discovery.
1313
type Plugins interface {
1414
// Find looks up the plugin by name. The name can be of the form $lookup[/$subtype]. See GetLookupAndType().
15-
Find(name string) (*plugin.Endpoint, error)
15+
Find(name plugin.Name) (*plugin.Endpoint, error)
1616
List() (map[string]*plugin.Endpoint, error)
1717
}
1818

pkg/example/flavor/combo/flavor_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package main
33
import (
44
"encoding/json"
55
"errors"
6+
"testing"
7+
68
mock_flavor "github.com/docker/infrakit/pkg/mock/spi/flavor"
9+
"github.com/docker/infrakit/pkg/plugin"
710
"github.com/docker/infrakit/pkg/plugin/group"
811
"github.com/docker/infrakit/pkg/plugin/group/types"
912
"github.com/docker/infrakit/pkg/spi/flavor"
1013
"github.com/docker/infrakit/pkg/spi/instance"
1114
"github.com/golang/mock/gomock"
1215
"github.com/stretchr/testify/require"
13-
"testing"
1416
)
1517

1618
func jsonPtr(v string) *json.RawMessage {
@@ -32,8 +34,8 @@ var inst = instance.Spec{
3234
}
3335

3436
func pluginLookup(plugins map[string]flavor.Plugin) group.FlavorPluginLookup {
35-
return func(key string) (flavor.Plugin, error) {
36-
plugin, has := plugins[key]
37+
return func(key plugin.Name) (flavor.Plugin, error) {
38+
plugin, has := plugins[key.String()]
3739
if has {
3840
return plugin, nil
3941
}

pkg/example/flavor/combo/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
log "github.com/Sirupsen/logrus"
77
"github.com/docker/infrakit/pkg/cli"
88
"github.com/docker/infrakit/pkg/discovery"
9+
"github.com/docker/infrakit/pkg/plugin"
910
flavor_rpc "github.com/docker/infrakit/pkg/rpc/flavor"
1011
"github.com/docker/infrakit/pkg/spi/flavor"
1112
"github.com/spf13/cobra"
@@ -27,7 +28,7 @@ func main() {
2728
os.Exit(1)
2829
}
2930

30-
flavorPluginLookup := func(n string) (flavor.Plugin, error) {
31+
flavorPluginLookup := func(n plugin.Name) (flavor.Plugin, error) {
3132
endpoint, err := plugins.Find(n)
3233
if err != nil {
3334
return nil, err

0 commit comments

Comments
 (0)