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

Commit a8cb7e2

Browse files
ndegoryDavid Chung
authored andcommitted
Aws metadata should start when no template is provided (#746)
Signed-off-by: Nicolas Degory <[email protected]>
1 parent 382d614 commit a8cb7e2

File tree

11 files changed

+130
-90
lines changed

11 files changed

+130
-90
lines changed

docs/cmd/infrakit/util/init/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ of `init` works as follows:
2929
2. The CLI fetches this and evaluates it as a template.
3030
+ The engine uses the `INFRAKIT_VARS_TEMPLATE` env to determine a variables JSON to
3131
initialize some variables. These can be overridden by appropriately named `--var`
32-
and `--metdata` flags in the command line.
32+
and `--metadata` flags in the command line.
3333
+ The engine uses the `--var` to set parameters in memory for the scope of *this*
3434
evaluation. These are ephemeral and can override the defaults set in above.
3535
+ The engine uses the `--metadata` to set parameters that will persist, as some
@@ -44,7 +44,7 @@ of `init` works as follows:
4444
renders a template. Depending on the plugin implementation, values that are not known
4545
at this time may be deferred (as multipass = true -- see `swarm/flavor.go#31).
4646
7. The CLI renders the text blob from the `Init` field of the instance spec returned
47-
by the `Prepare` method. This will apply the same set of `--var` as varaibles.
47+
by the `Prepare` method. This will apply the same set of `--var` as variables.
4848
8. The CLI prints out the rendered init script
4949
9. If `--persist` is set, the CLI will commit the current state of the vars plugin
5050
(which was started in the beginning of this process).

pkg/cli/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func templateProcessor(scope scope.Scope) (*pflag.FlagSet,
107107

108108
fs := pflag.NewFlagSet("template", pflag.ExitOnError)
109109

110-
globals := fs.StringSlice("var", []string{}, "key=value pairs of globally scoped variagbles")
110+
globals := fs.StringSlice("var", []string{}, "key=value pairs of globally scoped variables")
111111
yamlDoc := fs.BoolP("yaml", "y", false, "True if input is in yaml format; json is the default")
112112
dump := fs.BoolP("dump", "x", false, "True to dump to output instead of executing")
113113
singlePass := fs.BoolP("final", "f", false, "True to render template as the final pass")

pkg/manager/stored.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type key struct {
1515
}
1616

1717
type record struct {
18-
// Handler is the actuall plugin used to process the input
18+
// Handler is the actual plugin used to process the input
1919
Handler plugin.Name
2020

2121
// Spec is a copy of the spec

pkg/plugin/flavor/kubernetes/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ wget -qO- https://get.docker.com/ | sh
8787
### A Word on Security
8888

8989
Since Kubeadm use Token to authorize nodes, initializing
90-
the Kubernetes requires:
90+
Kubernetes requires:
9191

92-
Docken socke API server exposes the remote API, but it is protected by TLS. Infrakit intends to make access to kubernetes manager from the side, but we can not send commands such as `get nodes` yet.
92+
Docker engine exposes its remote API, but it is protected by TLS. Infrakit intends to make access to kubernetes manager from the side, but we can not send commands such as `get nodes` yet.
9393
For installation, we use [kubeadm](https://kubernetes.io/docs/admin/kubeadm/) and build a secure cluster.
9494

9595

@@ -102,25 +102,26 @@ Building the binaries - do this from the top level project directory:
102102
make binaries
103103
```
104104

105-
Start required plugins. We use the `infrakit plugin start` utility and a `plugins.json` to start up all the plugins,
106-
along with the InfraKit manager:
105+
Start required plugins.
106+
We can use the plugin utility to start up all the plugins along with the InfraKit manager:
107107

108108
```shell
109-
infrakit-group-default
110-
infrakit-instance-vagrant
111-
infrakit-flavor-kubernetes
109+
export INFRAKIT_LEADER_FILE=$HOME/.infrakit/leader
110+
echo "manager1" > $INFRAKIT_LEADER_FILE
111+
export PATH=$PWD/build:$PATH
112+
infrakit plugin start manager group vagrant kubernetes &
112113
```
113114

114115
Now start up the cluster comprised of a manager and a worker group. In this case, see `groups-master.json` where we will create a manager group of one node and in `group-worker.json` create a worker group of 3 nodes. The topology in this is a single ensemble of infrakit running on your local machine that manages 4 vagrant vms running Kubernetes.
115116
At Kubernetes flavor, you should run manager group first.
116117
Worker group will try to connect to manager before start.
117-
And as this flavor based on kubeadm, currently it support only one manager node.
118+
And as this flavor is based on kubeadm, it currently supports only one manager node.
118119

119120
```shell
120121
infrakit group commit groups-manager.json
121122
```
122-
Wait for manager comes up.
123-
As it need to install docker and kubeadm, it take a little time...
123+
Wait for manager to come up.
124+
As it needs to install docker and kubeadm, it takes a little time...
124125

125126
```shell
126127
infrakit group commit groups-worker.json

pkg/plugin/flavor/swarm/README.md

Lines changed: 62 additions & 40 deletions
Large diffs are not rendered by default.

pkg/plugin/flavor/swarm/plugins.json

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
[
22
{
3-
"Plugin" : "manager",
4-
"Launch" : {
5-
"os": {
6-
"Cmd" : "infrakit-manager --name group --proxy-for-group group-stateless os --leader-file {{env "INFRAKIT_HOME"}}/leader --store-dir {{env "INFRAKIT_HOME"}}/configs > {{env "INFRAKIT_HOME"}}/logs/manager.log 2>&1"
7-
}
3+
"Key": "manager",
4+
"Launch": {
5+
"inproc": {
6+
"Kind": "manager",
7+
"Options": {
8+
"Name": "",
9+
"Group": "group-stateless"
10+
},
11+
"Settings": {
12+
"LeaderFile": "{{env "INFRAKIT_HOME"}}/leader",
13+
"StoreDir": "{{env "INFRAKIT_HOME"}}/configs"
14+
},
15+
"Backend": "file"
816
}
17+
}
918
}
1019
,
1120
{
12-
"Plugin" : "group-stateless",
13-
"Launch" : {
14-
"os": {
15-
"Cmd" : "infrakit-group-default --poll-interval 10s --name group-stateless --log 5 > {{env "INFRAKIT_HOME"}}/logs/group-stateless.log 2>&1"
16-
}
21+
"Key": "group-stateless",
22+
"Launch": {
23+
"inproc": {
24+
"Kind": "group",
25+
"Options": {
26+
"PollInterval": "10s",
27+
"MaxParallelNum": 0,
28+
"PollIntervalGroupSpec": "10s",
29+
"PollIntervalGroupDetail": "10s"
30+
}
1731
}
32+
}
1833
}
1934
,
2035
{
21-
"Plugin" : "instance-vagrant",
22-
"Launch" : {
23-
"os" : {
24-
"Cmd" : "infrakit-instance-vagrant --log 5 > {{env "INFRAKIT_HOME"}}/logs/instance-vagrant.log 2>&1"
25-
}
36+
"Key": "instance-vagrant",
37+
"Launch": {
38+
"inproc": {
39+
"Kind": "vagrant",
40+
"Options": {
41+
}
2642
}
43+
}
2744
}
2845
,
2946
{
30-
"Plugin" : "flavor-swarm",
31-
"Launch" : {
32-
"os" : {
33-
"Cmd" : "infrakit-flavor-swarm --log 5 > {{env "INFRAKIT_HOME"}}/logs/flavor-swarm.log 2>&1"
34-
}
47+
"Key": "flavor-swarm",
48+
"Launch": {
49+
"inproc": {
50+
"Kind": "swarm"
3551
}
52+
}
3653
}
3754
]

pkg/plugin/flavor/swarm/start-plugins.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ echo group > $leaderfile
2828

2929
export INFRAKIT_HOME=$INFRAKIT_HOME
3030

31-
infrakit plugin start --config-url file:///$PWD/examples/flavor/swarm/plugins.json --exec os \
31+
infrakit plugin start --config-url file:///$PWD/plugin/flavor/swarm/plugins.json \
3232
manager \
33-
group-stateless \
33+
group \
3434
flavor-swarm \
35-
instance-vagrant
35+
instance-vagrant &
3636

3737
sleep 5
3838

pkg/provider/aws/plugin/metadata/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewPlugin(options Options, stop <-chan struct{}) (*Context, error) {
5959
providers = append(providers, &staticCreds)
6060
}
6161

62-
if options.Region == "" {
62+
if options.Region == "" || options.Region == "auto" {
6363
log.Warn("region not specified, attempting to discover from EC2 instance metadata")
6464
region, err := instance.GetRegion()
6565
if err != nil {

pkg/provider/aws/plugin/metadata/template.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (c *Context) start() {
4848
c.poll = 1 * time.Minute
4949
}
5050

51-
log.Info("Staring", "context", c, "poll", c.poll)
51+
log.Info("Starting", "context", c, "poll", c.poll)
5252
update := make(chan func(map[string]interface{}))
5353
tick := time.Tick(c.poll)
5454

@@ -58,6 +58,14 @@ func (c *Context) start() {
5858
go func() {
5959

6060
for {
61+
select {
62+
case <-tick:
63+
case <-c.stop:
64+
log.Info("Stopping aws metadata")
65+
close(update)
66+
return
67+
}
68+
6169
log.Debug("Running template to export metadata", "url", c.templateURL, "V", debugV)
6270

6371
t, err := template.NewTemplate(c.templateURL, c.templateOptions)
@@ -66,8 +74,8 @@ func (c *Context) start() {
6674
update <- func(view map[string]interface{}) {
6775
view["err"] = err.Error()
6876
}
77+
continue
6978
}
70-
7179
// Note the actual exporting of the values is done via the 'export' function
7280
// that are invoked as part of processing the template.
7381
_, err = t.Render(c)
@@ -81,14 +89,6 @@ func (c *Context) start() {
8189
delete(view, "err")
8290
}
8391
}
84-
85-
select {
86-
case <-tick:
87-
case <-c.stop:
88-
log.Info("Stopping aws metadata")
89-
close(update)
90-
return
91-
}
9292
}
9393

9494
}()

pkg/run/v0/terraform/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ infrakit plugin start terraform:terraform=inproc
5858
```
5959

6060
where the launch system will look for `Key` of `terraform`, and use the `inproc` launcher which uses the
61-
embeded `terraform` Kind. That then will look for the `Options` field and provide that to the code
61+
embedded `terraform` Kind. That then will look for the `Options` field and provide that to the code
6262
that is in `terraform.go`.
6363

6464
Once you have the new fields defined and updated your `plugins.json` file to reflect these new changes,

pkg/template/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (t *Template) Render(context interface{}) (string, error) {
419419
return buff.String(), err
420420
}
421421

422-
// converts a function of f(Context, ags...) to a regular template function
422+
// converts a function of f(Context, args...) to a regular template function
423423
func makeTemplateFunc(ctx Context, f interface{}) (interface{}, error) {
424424

425425
contextType := reflect.TypeOf((*Context)(nil)).Elem()

0 commit comments

Comments
 (0)