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

Commit 8fa8129

Browse files
authored
Collapse watch and update commands into commit (#293)
Introduces the `commit` command, with a `--pretend` flag `unwatch` is renamed to `free` The following commands are removed: `watch`, `update`, `stop-update`, and `describe-update` Closes #292 Signed-off-by: Bill Farner <[email protected]>
1 parent e6c2deb commit 8fa8129

File tree

20 files changed

+472
-841
lines changed

20 files changed

+472
-841
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ for converging towards, and maintaining, that desired state.
4646
Therefore, a [group plugin](spi/group/spi.go) manages Groups of Instances and exposes the operations that are of
4747
interest to a user:
4848

49-
+ watch/ unwatch a group (start / stop managing a group)
49+
+ commit a group configuration, to start managing a group
5050
+ inspect a group
51-
+ trigger an update the configuration of a group - like changing its size or underlying properties of instances.
52-
+ stop an update
5351
+ destroy a group
5452

5553
##### Default Group plugin

cmd/cli/group.go

Lines changed: 37 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,45 @@ func groupPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
4646

4747
cmd.PersistentFlags().StringVar(&name, "name", name, "Name of plugin")
4848

49-
cmd.AddCommand(&cobra.Command{
50-
Use: "watch <group configuration>",
51-
Short: "watch a group",
52-
RunE: func(cmd *cobra.Command, args []string) error {
53-
assertNotNil("no plugin", groupPlugin)
54-
55-
if len(args) != 1 {
56-
cmd.Usage()
57-
os.Exit(1)
58-
}
59-
60-
buff, err := ioutil.ReadFile(args[0])
61-
if err != nil {
62-
log.Error(err)
63-
os.Exit(1)
64-
}
65-
66-
spec := group.Spec{}
67-
if err := json.Unmarshal(buff, &spec); err != nil {
68-
return err
69-
}
49+
commit := cobra.Command{
50+
Use: "commit <group configuration>",
51+
Short: "commit a group configuration",
52+
}
53+
pretend := commit.Flags().Bool("pretend", false, "Don't actually commit, only explain the commit")
54+
commit.RunE = func(cmd *cobra.Command, args []string) error {
55+
assertNotNil("no plugin", groupPlugin)
56+
57+
if len(args) != 1 {
58+
cmd.Usage()
59+
os.Exit(1)
60+
}
61+
62+
buff, err := ioutil.ReadFile(args[0])
63+
if err != nil {
64+
log.Error(err)
65+
os.Exit(1)
66+
}
67+
68+
spec := group.Spec{}
69+
if err := json.Unmarshal(buff, &spec); err != nil {
70+
return err
71+
}
7072

71-
err = groupPlugin.WatchGroup(spec)
72-
if err == nil {
73-
fmt.Println("watching", spec.ID)
73+
details, err := groupPlugin.CommitGroup(spec, *pretend)
74+
if err == nil {
75+
if *pretend {
76+
fmt.Printf("Committing %s would involve: %s\n", spec.ID, details)
77+
} else {
78+
fmt.Printf("Committed %s: %s\n", spec.ID, details)
7479
}
75-
return err
76-
},
77-
})
80+
}
81+
return err
82+
}
83+
cmd.AddCommand(&commit)
7884

7985
cmd.AddCommand(&cobra.Command{
80-
Use: "unwatch <group ID>",
81-
Short: "unwatch a group",
86+
Use: "free <group ID>",
87+
Short: "free a group from active monitoring, nondestructive",
8288
RunE: func(cmd *cobra.Command, args []string) error {
8389
assertNotNil("no plugin", groupPlugin)
8490

@@ -88,10 +94,9 @@ func groupPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
8894
}
8995

9096
groupID := group.ID(args[0])
91-
err := groupPlugin.UnwatchGroup(groupID)
92-
97+
err := groupPlugin.FreeGroup(groupID)
9398
if err == nil {
94-
fmt.Println("unwatched", groupID)
99+
fmt.Println("Freed", groupID)
95100
}
96101
return err
97102
},
@@ -172,88 +177,6 @@ func groupPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
172177
},
173178
})
174179

175-
cmd.AddCommand(&cobra.Command{
176-
Use: "describe-update <group configuration file>",
177-
Short: "describe the steps to perform an update",
178-
RunE: func(cmd *cobra.Command, args []string) error {
179-
assertNotNil("no plugin", groupPlugin)
180-
181-
if len(args) != 1 {
182-
cmd.Usage()
183-
os.Exit(1)
184-
}
185-
186-
buff, err := ioutil.ReadFile(args[0])
187-
if err != nil {
188-
log.Error(err)
189-
os.Exit(1)
190-
}
191-
192-
spec := group.Spec{}
193-
if err := json.Unmarshal(buff, &spec); err != nil {
194-
return err
195-
}
196-
197-
desc, err := groupPlugin.DescribeUpdate(spec)
198-
if err == nil {
199-
fmt.Println(desc)
200-
}
201-
return err
202-
},
203-
})
204-
205-
cmd.AddCommand(&cobra.Command{
206-
Use: "update [group configuration]",
207-
Short: "update a group",
208-
RunE: func(cmd *cobra.Command, args []string) error {
209-
assertNotNil("no plugin", groupPlugin)
210-
211-
if len(args) != 1 {
212-
cmd.Usage()
213-
os.Exit(1)
214-
}
215-
216-
buff, err := ioutil.ReadFile(args[0])
217-
if err != nil {
218-
log.Error(err)
219-
os.Exit(1)
220-
}
221-
222-
spec := group.Spec{}
223-
if err := json.Unmarshal(buff, &spec); err != nil {
224-
return err
225-
}
226-
227-
// TODO - make this not block, but how to get status?
228-
err = groupPlugin.UpdateGroup(spec)
229-
if err == nil {
230-
fmt.Println("update", spec.ID, "completed")
231-
}
232-
return err
233-
},
234-
})
235-
236-
cmd.AddCommand(&cobra.Command{
237-
Use: "stop-update <group ID>",
238-
Short: "stop updating a group",
239-
RunE: func(cmd *cobra.Command, args []string) error {
240-
assertNotNil("no plugin", groupPlugin)
241-
242-
if len(args) != 1 {
243-
cmd.Usage()
244-
os.Exit(1)
245-
}
246-
247-
groupID := group.ID(args[0])
248-
err := groupPlugin.StopUpdate(groupID)
249-
250-
if err == nil {
251-
fmt.Println("update", groupID, "stopped")
252-
}
253-
return err
254-
},
255-
})
256-
257180
cmd.AddCommand(&cobra.Command{
258181
Use: "destroy <group ID>",
259182
Short: "destroy a group",

docs/tutorial.md

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -114,50 +114,55 @@ $ build/infrakit instance --name instance-file describe
114114
ID LOGICAL TAGS
115115
```
116116

117-
Let's tell the group plugin to `watch` our group by providing the group plugin with the configuration:
117+
Let's tell the group plugin to `commit` our group by providing the group plugin with the configuration:
118118

119119
```shell
120-
$ build/infrakit group watch cattle.json
121-
watching cattle
120+
$ build/infrakit group commit cattle.json
121+
Committed cattle: Managing 5 instances
122122
```
123123

124124
The group plugin is responsible for ensuring that the infrastructure state matches with your specifications. Since we
125125
started out with nothing, it will create 5 instances and maintain that state by monitoring the instances:
126126
```shell
127127
$ build/infrakit group describe cattle
128-
ID LOGICAL TAGS
129-
instance-1475104926 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
130-
instance-1475104936 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
131-
instance-1475104946 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
132-
instance-1475104956 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
133-
instance-1475104966 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
128+
ID LOGICAL TAGS
129+
instance-5993795900014843850 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
130+
instance-6529053068646043018 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
131+
instance-7203714904652099824 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
132+
instance-8430289623921829870 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
133+
instance-9014687032220994836 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
134134
```
135135

136136
The Instance Plugin can also report instances, it will report all instances across all groups (not just `cattle`).
137137

138138
```shell
139139
$ build/infrakit instance --name instance-file describe
140-
ID LOGICAL TAGS
141-
instance-1475104926 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
142-
instance-1475104936 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
143-
instance-1475104946 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
144-
instance-1475104956 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
145-
instance-1475104966 - infrakit.config_sha=Y23cKqyRpkQ_M60vIq7CufFmQWk=,infrakit.group=cattle,project=infrakit,tier=web
140+
ID LOGICAL TAGS
141+
instance-5993795900014843850 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
142+
instance-6529053068646043018 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
143+
instance-7203714904652099824 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
144+
instance-8430289623921829870 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
145+
instance-9014687032220994836 - infrakit.config_sha=006438mMXW8gXeYtUxgf9Zbg94Y=,infrakit.group=cattle,project=infrakit,tier=web
146146
```
147147

148-
At any point you can safely `unwatch` a group. This will instruct _InfraKit_ to cease active monitoring:
148+
At any point you can safely `free` a group. This is a non-destructive action, which instructs _InfraKit_ to cease
149+
active monitoring. No instances are affected, but _InfraKit_ will no longer manage them.
149150
```shell
150-
$ build/infrakit group unwatch cattle
151+
$ build/infrakit group free cattle
152+
Freed cattle
151153
```
152154

153-
You can `watch` the group to start monitoring it again:
155+
You can `commit` the group to start monitoring it again:
154156
```shell
155-
$ build/infrakit group watch cattle.json
157+
$ build/infrakit group commit cattle.json
158+
Committed cattle: Managing 5 instances
156159
```
157160

158-
Check which groups are being watched:
161+
Check which groups are being managed:
159162
```shell
160163
$ build/infrakit group ls
164+
ID
165+
cattle
161166
```
162167

163168
Now let's update the configuration by changing the size of the group and a property of the instance. Save this file as
@@ -209,8 +214,8 @@ $ diff cattle.json cattle2.json
209214

210215
Before we do an update, we can see what the proposed changes are:
211216
```shell
212-
$ build/infrakit group describe-update cattle2.json
213-
Performs a rolling update on 5 instances, then adds 5 instances to increase the group size to 10
217+
$ build/infrakit group commit cattle2.json --pretend
218+
Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10
214219
```
215220

216221
So here 5 instances will be updated via rolling update, while 5 new instances at the new configuration will
@@ -219,51 +224,48 @@ be created.
219224
Let's apply the new config:
220225

221226
```shell
222-
$ build/infrakit group update cattle2.json
223-
224-
# ..... wait a bit...
225-
update cattle completed
227+
$ build/infrakit group commit cattle2.json
228+
Committed cattle: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10
226229
```
227-
Now we can check:
228230

231+
If we poll the group, we can see state will converging until all instances have been updated:
229232
```shell
230233
$ build/infrakit group describe cattle
231-
ID LOGICAL TAGS
232-
instance-1475105646 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
233-
instance-1475105656 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
234-
instance-1475105666 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
235-
instance-1475105676 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
236-
instance-1475105686 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
237-
instance-1475105696 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
238-
instance-1475105706 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
239-
instance-1475105716 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
240-
instance-1475105726 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
241-
instance-1475105736 - infrakit.config_sha=BXedrwY0GdZlHhgHmPAzxTN4oHM=,infrakit.group=cattle,project=infrakit,tier=web
234+
ID LOGICAL TAGS
235+
instance-1422140834255860063 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
236+
instance-1478871890164117825 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
237+
instance-1507972539885141336 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
238+
instance-1665488406863611296 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
239+
instance-2340140454359833670 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
240+
instance-2796731287627125229 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
241+
instance-285480170677988698 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
242+
instance-4084455402433225349 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
243+
instance-5591036640758692177 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
244+
instance-6810420924276316298 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
242245
```
243246

244-
Note the instances now have a new SHA `BXedrwY0GdZlHhgHmPAzxTN4oHM=` (vs `Y23cKqyRpkQ_M60vIq7CufFmQWk=` previously)
247+
Note the instances now have a new SHA `eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=` (vs `006438mMXW8gXeYtUxgf9Zbg94Y_M60vIq7CufFmQWk=` previously)
245248

246249
To see that the Group plugin can enforce the size of the group, let's simulate an instance disappearing.
247250

248251
```shell
249-
$ rm tutorial/instance-1475105646 tutorial/instance-1475105686 tutorial/instance-1475105726
250-
251-
# ... now check
252-
253-
$ ls -al tutorial
254-
total 104
255-
drwxr-xr-x 15 davidchung staff 510 Sep 28 16:40 .
256-
drwxr-xr-x 36 davidchung staff 1224 Sep 28 16:39 ..
257-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:34 instance-1475105656
258-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:34 instance-1475105666
259-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:34 instance-1475105676
260-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:34 instance-1475105696
261-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:35 instance-1475105706
262-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:35 instance-1475105716
263-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:35 instance-1475105736
264-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:40 instance-1475106016 <-- new instance
265-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:40 instance-1475106026 <-- new instance
266-
-rw-r--r-- 1 davidchung staff 654 Sep 28 16:40 instance-1475106036 <-- new instance
252+
$ rm tutorial/instance-1422140834255860063 tutorial/instance-1478871890164117825 tutorial/instance-1507972539885141336
253+
```
254+
255+
After a few moments, the missing instances will be replaced (we've highlighted new instances with `-->`):
256+
```shell
257+
$ build/infrakit group describe cattle
258+
ID LOGICAL TAGS
259+
--> instance-1265288729718091217 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
260+
instance-1665488406863611296 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
261+
--> instance-1952247477026188949 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
262+
instance-2340140454359833670 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
263+
instance-2796731287627125229 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
264+
instance-285480170677988698 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
265+
instance-4084455402433225349 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
266+
--> instance-4161733946225446641 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
267+
instance-5591036640758692177 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
268+
instance-6810420924276316298 - infrakit.config_sha=eB2JuP0c5Sf41X5e2vc2gJ4ZTVg=,infrakit.group=cattle,project=infrakit,tier=web
267269
```
268270

269271
We see that 3 new instance have been created to replace the three removed, to match our
@@ -277,7 +279,7 @@ $ build/infrakit group destroy cattle
277279

278280
This concludes our quick tutorial. In this tutorial we:
279281
+ Started the plugins and learned to access them
280-
+ Created a configuration for a group we wanted to watch
282+
+ Created a configuration for a group we wanted to manage
281283
+ Verified the instances created matched the specifications
282284
+ Updated the configurations of the group and scaled up the group
283285
+ Reviewed the proposed changes

example/flavor/combo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ $ build/infrakit-flavor-combo
5757
INFO[0000] Listening at: ~/.infrakit/plugins/flavor-combo
5858
```
5959

60-
Using the [example](example.json) configuration, start watching a group:
60+
Using the [example](example.json) configuration, commit a group:
6161
```shell
62-
$ build/infrakit group watch example/flavor/combo/example.json
63-
watching combo
62+
$ build/infrakit group commit example/flavor/combo/example.json
63+
Committed combo
6464
```
6565

6666
You will notice that the configuration is somewhat nonsensical, as the result could have been achieved without

0 commit comments

Comments
 (0)