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

Commit 1e53577

Browse files
author
David Chung
authored
Rename Metadata.Ls to Metadata.Keys (#736)
* rename Metadata.Ls to Metadata.Keys Signed-off-by: David Chung <[email protected]> * rename RPC method Metadata.List -> Metadata.Keys Signed-off-by: David Chung <[email protected]> * fix tests Signed-off-by: David Chung <[email protected]>
1 parent ba1ce22 commit 1e53577

File tree

25 files changed

+102
-216
lines changed

25 files changed

+102
-216
lines changed

cmd/infrakit/manager/manager.go

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/docker/infrakit/pkg/spi/group"
2323
"github.com/docker/infrakit/pkg/spi/metadata"
2424
"github.com/docker/infrakit/pkg/types"
25-
"github.com/sergi/go-diff/diffmatchpatch"
2625
"github.com/spf13/cobra"
2726
)
2827

@@ -237,111 +236,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
237236
},
238237
}
239238

240-
///////////////////////////////////////////////////////////////////////////////////
241-
// change
242-
change := &cobra.Command{
243-
Use: "change",
244-
Short: "Change returns the plugin configurations known by the manager",
245-
}
246-
vars := change.Flags().StringSlice("var", []string{}, "key=value pairs")
247-
commitChange := change.Flags().BoolP("commit", "c", false, "Commit changes")
248-
249-
// This is the only interactive command. We want to show the user the proposal, with the diff
250-
// and when the user accepts the change, call a commit.
251-
change.RunE = func(cmd *cobra.Command, args []string) error {
252-
253-
if len(args) != 0 {
254-
cmd.Usage()
255-
os.Exit(1)
256-
}
257-
258-
// get the changes
259-
changes, err := changeSet(*vars)
260-
if err != nil {
261-
return err
262-
}
263-
current, proposed, cas, err := updatablePlugin.Changes(changes)
264-
if err != nil {
265-
return err
266-
}
267-
currentBuff, err := current.MarshalYAML()
268-
if err != nil {
269-
return err
270-
}
271-
272-
proposedBuff, err := proposed.MarshalYAML()
273-
if err != nil {
274-
return err
275-
}
276-
277-
if *commitChange {
278-
fmt.Printf("Committing changes, hash=%s\n", cas)
279-
} else {
280-
fmt.Printf("Proposed changes, hash=%s\n", cas)
281-
}
282-
283-
// Render the delta
284-
dmp := diffmatchpatch.New()
285-
diffs := dmp.DiffMain(string(currentBuff), string(proposedBuff), false)
286-
fmt.Println(dmp.DiffPrettyText(diffs))
287-
288-
if *commitChange {
289-
return updatablePlugin.Commit(proposed, cas)
290-
}
291-
292-
return nil
293-
}
294-
change.Flags().AddFlagSet(templateFlags)
295-
296-
///////////////////////////////////////////////////////////////////////////////////
297-
// change-list
298-
changeList := &cobra.Command{
299-
Use: "ls",
300-
Short: "Lists all the changeable paths",
301-
RunE: func(cmd *cobra.Command, args []string) error {
302-
303-
if len(args) != 0 {
304-
cmd.Usage()
305-
os.Exit(1)
306-
}
307-
308-
all, err := types.ListAll(updatablePlugin, types.PathFromString("."))
309-
if err != nil {
310-
return err
311-
}
312-
313-
types.SortPaths(all)
314-
for _, p := range all {
315-
fmt.Println(p.String())
316-
}
317-
return nil
318-
},
319-
}
320-
///////////////////////////////////////////////////////////////////////////////////
321-
// change-cat
322-
changeGet := &cobra.Command{
323-
Use: "cat",
324-
Short: "Cat returns the current value at given path",
325-
RunE: func(cmd *cobra.Command, args []string) error {
326-
327-
if len(args) != 1 {
328-
cmd.Usage()
329-
os.Exit(1)
330-
}
331-
332-
path := types.PathFromString(args[0])
333-
any, err := updatablePlugin.Get(path)
334-
if err != nil {
335-
return err
336-
}
337-
338-
fmt.Println(any.String())
339-
340-
return nil
341-
},
342-
}
343-
change.AddCommand(changeList, changeGet)
344-
345239
cmd.AddCommand(commit, inspect, leader)
346240

347241
return cmd

docs/plugin/metadata/vars/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ variable `INFRAKIT_VARS_TEMPLATE` as a way to set it.
6464

6565
Corresponding to the SPI methods, there are new commands / verbs as `metadata`:
6666

67-
+ `ls` lists the metadata paths
67+
+ `keys` lists the metadata paths
6868
+ `cat` reads metadata values
6969
+ `change` updates metadata values, provided the plugin implements the updatable SPI (not readonly)
7070

@@ -130,15 +130,15 @@ Usage:
130130
Available Commands:
131131
cat Get metadata entry by path
132132
change Update metadata where args are key=value pairs and keys are within namespace of the plugin.
133-
vars List metadata
133+
keys List metadata
134134
```
135135

136136
### Listing, Reading
137137

138138
Listing metadata values:
139139

140140
```shell
141-
$ infrakit vars vars -al
141+
$ infrakit vars keys -al
142142
total 6:
143143
cluster/name
144144
cluster/size
@@ -151,7 +151,7 @@ zones/west/cidr
151151
or
152152

153153
```shell
154-
$ infrakit vars vars -al zones
154+
$ infrakit vars keys -al zones
155155
total 2:
156156
east/cidr
157157
west/cidr
@@ -363,7 +363,7 @@ Committing 2 changes, hash=ad861ded7a0742f9662c2b78354c89f6
363363
Now querying:
364364

365365
```shell
366-
$ infrakit vars vars -al
366+
$ infrakit vars keys -al
367367
total 2:
368368
cluster/name
369369
cluster/workers/size

pkg/cli/v0/metadata/cmd.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@ import (
1313
var log = logutil.New("module", "cli/v1/metadata")
1414

1515
func init() {
16-
// cli.Register(metadata.InterfaceSpec,
17-
// []cli.CmdBuilder{
18-
// Metadata,
19-
// })
20-
// cli.Register(metadata.UpdatableInterfaceSpec,
21-
// []cli.CmdBuilder{
22-
// Updatable,
23-
// })
2416
cli.Register(metadata.InterfaceSpec,
2517
[]cli.CmdBuilder{
26-
Ls,
18+
Keys,
2719
Cat,
2820
})
2921
cli.Register(metadata.UpdatableInterfaceSpec,
3022
[]cli.CmdBuilder{
31-
Ls,
23+
Keys,
3224
Cat,
3325
Change,
3426
})
@@ -63,7 +55,7 @@ func Metadata(name string, services *cli.Services) *cobra.Command {
6355
}
6456

6557
cmd.AddCommand(
66-
Ls(name, services),
58+
Keys(name, services),
6759
Cat(name, services),
6860
)
6961

@@ -79,7 +71,7 @@ func Updatable(name string, services *cli.Services) *cobra.Command {
7971
}
8072

8173
cmd.AddCommand(
82-
Ls(name, services),
74+
Keys(name, services),
8375
Cat(name, services),
8476
Change(name, services),
8577
)

pkg/cli/v0/metadata/ls.go renamed to pkg/cli/v0/metadata/keys.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
// Ls returns the Ls command
13-
func Ls(name string, services *cli.Services) *cobra.Command {
12+
// Keys returns the Keys command
13+
func Keys(name string, services *cli.Services) *cobra.Command {
1414

15-
ls := &cobra.Command{
16-
Use: "ls",
15+
keys := &cobra.Command{
16+
Use: "keys",
1717
Short: "List metadata",
1818
}
1919

20-
long := ls.Flags().BoolP("long", "l", false, "Print full path")
21-
all := ls.Flags().BoolP("all", "a", false, "Find all under the paths given")
22-
quick := ls.Flags().BoolP("quick", "q", false, "True to turn off headers, etc.")
20+
long := keys.Flags().BoolP("long", "l", false, "Print full path")
21+
all := keys.Flags().BoolP("all", "a", false, "Find all under the paths given")
22+
quick := keys.Flags().BoolP("quick", "q", false, "True to turn off headers, etc.")
2323

24-
ls.RunE = func(cmd *cobra.Command, args []string) error {
24+
keys.RunE = func(cmd *cobra.Command, args []string) error {
2525

2626
metadataPlugin, err := loadPlugin(services.Plugins(), name)
2727
if err != nil {
@@ -59,7 +59,7 @@ func Ls(name string, services *cli.Services) *cobra.Command {
5959
nodes = append(nodes, c)
6060
}
6161
} else {
62-
children, err := metadataPlugin.List(path)
62+
children, err := metadataPlugin.Keys(path)
6363
if err != nil {
6464
log.Warn("Cannot metadata ls on plugin", "name", name, "err", err)
6565
}
@@ -89,15 +89,15 @@ func Ls(name string, services *cli.Services) *cobra.Command {
8989
}
9090
return nil
9191
}
92-
return ls
92+
return keys
9393
}
9494

9595
func listAll(m metadata.Plugin, path types.Path) ([]types.Path, error) {
9696
if m == nil {
9797
return nil, fmt.Errorf("no plugin")
9898
}
9999
result := []types.Path{}
100-
nodes, err := m.List(path)
100+
nodes, err := m.Keys(path)
101101
if err != nil {
102102
return nil, err
103103
}

pkg/plugin/flavor/kubernetes/flavor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ func (s *baseFlavor) Healthy(flavorProperties *types.Any, inst instance.Descript
209209
return flavor.Healthy, nil
210210
}
211211

212-
// List implements the metadata.Plugin SPI's List method
213-
func (s *baseFlavor) List(path types.Path) ([]string, error) {
212+
// Keys implements the metadata.Plugin SPI's Keys method
213+
func (s *baseFlavor) Keys(path types.Path) ([]string, error) {
214214
return nil, nil
215215
}
216216

217-
// Get implements the metadata.Plugin SPI's List method
217+
// Get implements the metadata.Plugin SPI's Get method
218218
func (s *baseFlavor) Get(path types.Path) (*types.Any, error) {
219219
if s.metadataPlugin != nil {
220220
return s.metadataPlugin.Get(path)

pkg/plugin/flavor/swarm/flavor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func (s *baseFlavor) runMetadataSnapshot(stopSnapshot <-chan struct{}) chan func
113113
return updateSnapshot
114114
}
115115

116-
// List implements the metadata.Plugin SPI's List method
117-
func (s *baseFlavor) List(path types.Path) ([]string, error) {
116+
// Keys implements the metadata.Plugin SPI's Keys method
117+
func (s *baseFlavor) Keys(path types.Path) ([]string, error) {
118118
if s.metadataPlugin != nil {
119-
return s.metadataPlugin.List(path)
119+
return s.metadataPlugin.Keys(path)
120120
}
121121
return nil, nil
122122
}
123123

124-
// Get implements the metadata.Plugin SPI's List method
124+
// Get implements the metadata.Plugin SPI's Get method
125125
func (s *baseFlavor) Get(path types.Path) (*types.Any, error) {
126126
if s.metadataPlugin != nil {
127127
return s.metadataPlugin.Get(path)

pkg/plugin/metadata/lazy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ func (c *lazyConnect) do(f func(p metadata.Plugin) error) (err error) {
8888
return f(c.client)
8989
}
9090

91-
func (c *lazyConnect) List(path types.Path) (child []string, err error) {
91+
func (c *lazyConnect) Keys(path types.Path) (child []string, err error) {
9292
err = c.do(func(p metadata.Plugin) error {
93-
child, err = p.List(path)
93+
child, err = p.Keys(path)
9494
return err
9595
})
9696
return

pkg/plugin/metadata/lazy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestLazyNoBlock(t *testing.T) {
5454

5555
type fake chan int
5656

57-
func (f fake) List(path types.Path) (child []string, err error) {
57+
func (f fake) Keys(path types.Path) (child []string, err error) {
5858
f <- 1
5959
return
6060
}

pkg/plugin/metadata/plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ type plugin struct {
5252
reads chan func(data map[string]interface{})
5353
}
5454

55-
// List returns a list of *child nodes* given a path, which is specified as a slice
55+
// Keys returns a list of *child nodes* given a path, which is specified as a slice
5656
// where for i > j path[i] is the parent of path[j]
57-
func (p *plugin) List(path types.Path) ([]string, error) {
57+
func (p *plugin) Keys(path types.Path) ([]string, error) {
5858
if p.reads == nil && p.data != nil {
5959
return types.List(path, p.data), nil
6060
}

pkg/plugin/metadata/plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestPluginUnserializedReadWrites(t *testing.T) {
2323

2424
p := NewPluginFromData(m)
2525

26-
require.Equal(t, []string{"us-west-1", "us-west-2"}, first(p.List(types.PathFromString("/"))))
26+
require.Equal(t, []string{"us-west-1", "us-west-2"}, first(p.Keys(types.PathFromString("/"))))
2727
require.Nil(t, first(p.Get(types.PathFromString("us-west-1/metrics/instances/foo"))))
2828
require.Equal(t, "2000", first(p.Get(types.PathFromString("us-west-1/metrics/instances/count"))).(*types.Any).String())
2929

0 commit comments

Comments
 (0)