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

Commit ccbd398

Browse files
author
David Chung
authored
Scope and refactor for consistent lookup of plugins (#739)
Signed-off-by: David Chung <[email protected]>
1 parent 41a17c1 commit ccbd398

File tree

145 files changed

+1451
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1451
-1195
lines changed

cmd/infrakit/base/module.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package base
33
import (
44
"sync"
55

6-
"github.com/docker/infrakit/pkg/discovery"
6+
"github.com/docker/infrakit/pkg/run/scope"
77
"github.com/spf13/cobra"
88
)
99

10-
type module func(func() discovery.Plugins) *cobra.Command
10+
type module func(scope.Scope) *cobra.Command
1111

1212
var (
1313
lock sync.Mutex
@@ -25,12 +25,12 @@ func Register(f module) {
2525
}
2626

2727
// VisitModules iterate through all the modules known
28-
func VisitModules(p func() discovery.Plugins, f func(*cobra.Command)) {
28+
func VisitModules(scope scope.Scope, f func(*cobra.Command)) {
2929
lock.Lock()
3030
defer lock.Unlock()
3131

3232
for _, m := range modules {
33-
command := m(p)
33+
command := m(scope)
3434
f(command)
3535
}
3636
}

cmd/infrakit/base/template.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

cmd/infrakit/flavor/flavor.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"strings"
88

99
"github.com/docker/infrakit/cmd/infrakit/base"
10+
1011
"github.com/docker/infrakit/pkg/cli"
11-
"github.com/docker/infrakit/pkg/discovery"
1212
logutil "github.com/docker/infrakit/pkg/log"
1313
"github.com/docker/infrakit/pkg/plugin"
14-
group_types "github.com/docker/infrakit/pkg/plugin/group/types"
1514
flavor_plugin "github.com/docker/infrakit/pkg/rpc/flavor"
15+
"github.com/docker/infrakit/pkg/run/scope"
1616
"github.com/docker/infrakit/pkg/spi/flavor"
1717
"github.com/docker/infrakit/pkg/spi/group"
1818
"github.com/docker/infrakit/pkg/spi/instance"
@@ -27,7 +27,9 @@ func init() {
2727
}
2828

2929
// Command is the entry point of this module
30-
func Command(plugins func() discovery.Plugins) *cobra.Command {
30+
func Command(scp scope.Scope) *cobra.Command {
31+
32+
services := cli.NewServices(scp)
3133

3234
var flavorPlugin flavor.Plugin
3335

@@ -43,7 +45,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
4345
return err
4446
}
4547

46-
endpoint, err := plugins().Find(plugin.Name(*name))
48+
endpoint, err := scp.Plugins().Find(plugin.Name(*name))
4749
if err != nil {
4850
return err
4951
}
@@ -75,13 +77,13 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
7577
0,
7678
"Group Size to use as the Allocation method")
7779
}
78-
allocationMethodFromFlags := func() group_types.AllocationMethod {
80+
allocationMethodFromFlags := func() group.AllocationMethod {
7981
ids := []instance.LogicalID{}
8082
for _, id := range logicalIDs {
8183
ids = append(ids, instance.LogicalID(id))
8284
}
8385

84-
return group_types.AllocationMethod{
86+
return group.AllocationMethod{
8587
Size: groupSize,
8688
LogicalIDs: ids,
8789
}
@@ -100,12 +102,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
100102
"Sequence number within the group")
101103
}
102104

103-
indexFromFlags := func() group_types.Index {
104-
return group_types.Index{Group: group.ID(groupID), Sequence: groupSequence}
105+
indexFromFlags := func() group.Index {
106+
return group.Index{Group: group.ID(groupID), Sequence: groupSequence}
105107
}
106108

107-
templateFlags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
108-
109109
///////////////////////////////////////////////////////////////////////////////////
110110
// validate
111111
validate := &cobra.Command{
@@ -118,20 +118,20 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
118118
os.Exit(1)
119119
}
120120

121-
view, err := processTemplate(*flavorPropertiesURL)
121+
view, err := services.ProcessTemplate(*flavorPropertiesURL)
122122
if err != nil {
123123
return err
124124
}
125125

126-
buff, err := toJSON([]byte(view))
126+
buff, err := services.ToJSON([]byte(view))
127127
if err != nil {
128128
return err
129129
}
130130

131131
return flavorPlugin.Validate(types.AnyBytes(buff), allocationMethodFromFlags())
132132
},
133133
}
134-
validate.Flags().AddFlagSet(templateFlags)
134+
validate.Flags().AddFlagSet(services.ProcessTemplateFlags)
135135
addAllocationMethodFlags(validate)
136136

137137
///////////////////////////////////////////////////////////////////////////////////
@@ -146,15 +146,15 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
146146
os.Exit(1)
147147
}
148148

149-
flavorProperties, err := processTemplate(*flavorPropertiesURL)
149+
flavorProperties, err := services.ProcessTemplate(*flavorPropertiesURL)
150150
if err != nil {
151151
return err
152152
}
153153

154-
view, err := base.ReadFromStdinIfElse(
154+
view, err := services.ReadFromStdinIfElse(
155155
func() bool { return args[0] == "-" },
156-
func() (string, error) { return processTemplate(args[0]) },
157-
toJSON,
156+
func() (string, error) { return services.ProcessTemplate(args[0]) },
157+
services.ToJSON,
158158
)
159159
if err != nil {
160160
return err
@@ -181,7 +181,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
181181
return err
182182
},
183183
}
184-
prepare.Flags().AddFlagSet(templateFlags)
184+
prepare.Flags().AddFlagSet(services.ProcessTemplateFlags)
185185
addAllocationMethodFlags(prepare)
186186
indexFlags(prepare)
187187

@@ -194,15 +194,15 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
194194
tags := healthy.Flags().StringSlice("tags", []string{}, "Tags to filter")
195195
id := healthy.Flags().String("id", "", "ID of resource")
196196
logicalID := healthy.Flags().String("logical-id", "", "Logical ID of resource")
197-
healthy.Flags().AddFlagSet(templateFlags)
197+
healthy.Flags().AddFlagSet(services.ProcessTemplateFlags)
198198
healthy.RunE = func(cmd *cobra.Command, args []string) error {
199199

200200
if len(args) != 0 {
201201
cmd.Usage()
202202
os.Exit(1)
203203
}
204204

205-
flavorProperties, err := processTemplate(*flavorPropertiesURL)
205+
flavorProperties, err := services.ProcessTemplate(*flavorPropertiesURL)
206206
if err != nil {
207207
return err
208208
}

cmd/infrakit/group/group.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"strings"
99

1010
"github.com/docker/infrakit/cmd/infrakit/base"
11+
1112
"github.com/docker/infrakit/pkg/cli"
12-
"github.com/docker/infrakit/pkg/discovery"
1313
logutil "github.com/docker/infrakit/pkg/log"
1414
"github.com/docker/infrakit/pkg/plugin"
1515
group_plugin "github.com/docker/infrakit/pkg/rpc/group"
16+
"github.com/docker/infrakit/pkg/run/scope"
1617
"github.com/docker/infrakit/pkg/spi/group"
1718
"github.com/docker/infrakit/pkg/types"
1819
"github.com/spf13/cobra"
@@ -30,7 +31,9 @@ func init() {
3031
}
3132

3233
// Command is the entrypoint to this module
33-
func Command(plugins func() discovery.Plugins) *cobra.Command {
34+
func Command(scp scope.Scope) *cobra.Command {
35+
36+
services := cli.NewServices(scp)
3437

3538
var groupPlugin group.Plugin
3639

@@ -48,7 +51,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
4851
return err
4952
}
5053

51-
endpoint, err := plugins().Find(plugin.Name(*name))
54+
endpoint, err := scp.Plugins().Find(plugin.Name(*name))
5255
if err != nil {
5356
return err
5457
}
@@ -63,8 +66,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
6366
return nil
6467
}
6568

66-
templateFlags, toJSON, fromJSON, processTemplate := base.TemplateProcessor(plugins)
67-
6869
///////////////////////////////////////////////////////////////////////////////////
6970
// commit
7071
commit := &cobra.Command{
@@ -77,10 +78,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
7778
os.Exit(1)
7879
}
7980

80-
view, err := base.ReadFromStdinIfElse(
81+
view, err := services.ReadFromStdinIfElse(
8182
func() bool { return args[0] == "-" },
82-
func() (string, error) { return processTemplate(args[0]) },
83-
toJSON,
83+
func() (string, error) { return services.ProcessTemplate(args[0]) },
84+
services.ToJSON,
8485
)
8586
if err != nil {
8687
return err
@@ -102,7 +103,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
102103
return err
103104
},
104105
}
105-
commit.Flags().AddFlagSet(templateFlags)
106+
commit.Flags().AddFlagSet(services.ProcessTemplateFlags)
106107

107108
///////////////////////////////////////////////////////////////////////////////////
108109
// free
@@ -187,7 +188,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
187188
return err
188189
}
189190

190-
data, err = fromJSON(data)
191+
data, err = services.FromJSON(data)
191192
if err != nil {
192193
return err
193194
}
@@ -203,7 +204,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
203204
return err
204205
},
205206
}
206-
inspect.Flags().AddFlagSet(templateFlags)
207+
inspect.Flags().AddFlagSet(services.ProcessTemplateFlags)
207208

208209
///////////////////////////////////////////////////////////////////////////////////
209210
// destroy

cmd/infrakit/instance/instance.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"text/template"
1111

1212
"github.com/docker/infrakit/cmd/infrakit/base"
13+
1314
"github.com/docker/infrakit/pkg/cli"
14-
"github.com/docker/infrakit/pkg/discovery"
1515
logutil "github.com/docker/infrakit/pkg/log"
1616
"github.com/docker/infrakit/pkg/plugin"
1717
instance_plugin "github.com/docker/infrakit/pkg/rpc/instance"
18+
"github.com/docker/infrakit/pkg/run/scope"
1819
"github.com/docker/infrakit/pkg/spi/instance"
1920
"github.com/docker/infrakit/pkg/types"
2021
"github.com/spf13/cobra"
@@ -27,7 +28,9 @@ func init() {
2728
}
2829

2930
// Command is the entry point to this module
30-
func Command(plugins func() discovery.Plugins) *cobra.Command {
31+
func Command(scp scope.Scope) *cobra.Command {
32+
33+
services := cli.NewServices(scp)
3134

3235
var instancePlugin instance.Plugin
3336

@@ -42,7 +45,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
4245
return err
4346
}
4447

45-
endpoint, err := plugins().Find(plugin.Name(*name))
48+
endpoint, err := scp.Plugins().Find(plugin.Name(*name))
4649
if err != nil {
4750
return err
4851
}
@@ -57,8 +60,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
5760
return nil
5861
}
5962

60-
templateFlags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
61-
6263
///////////////////////////////////////////////////////////////////////////////////
6364
// validate
6465
validate := &cobra.Command{
@@ -71,10 +72,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
7172
os.Exit(1)
7273
}
7374

74-
view, err := base.ReadFromStdinIfElse(
75+
view, err := services.ReadFromStdinIfElse(
7576
func() bool { return args[0] == "-" },
76-
func() (string, error) { return processTemplate(args[0]) },
77-
toJSON,
77+
func() (string, error) { return services.ProcessTemplate(args[0]) },
78+
services.ToJSON,
7879
)
7980
if err != nil {
8081
return err
@@ -87,7 +88,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
8788
return err
8889
},
8990
}
90-
validate.Flags().AddFlagSet(templateFlags)
91+
validate.Flags().AddFlagSet(services.ProcessTemplateFlags)
9192

9293
///////////////////////////////////////////////////////////////////////////////////
9394
// provision
@@ -101,10 +102,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
101102
os.Exit(1)
102103
}
103104

104-
view, err := base.ReadFromStdinIfElse(
105+
view, err := services.ReadFromStdinIfElse(
105106
func() bool { return args[0] == "-" },
106-
func() (string, error) { return processTemplate(args[0]) },
107-
toJSON,
107+
func() (string, error) { return services.ProcessTemplate(args[0]) },
108+
services.ToJSON,
108109
)
109110
if err != nil {
110111
return err
@@ -122,7 +123,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
122123
return err
123124
},
124125
}
125-
provision.Flags().AddFlagSet(templateFlags)
126+
provision.Flags().AddFlagSet(services.ProcessTemplateFlags)
126127

127128
///////////////////////////////////////////////////////////////////////////////////
128129
// destroy

0 commit comments

Comments
 (0)