Skip to content

Commit

Permalink
When we have 2 or more subnets in cluster.yaml, loop through all the …
Browse files Browse the repository at this point in the history
…subnets to automatically find and chooose an appropriate subnet for the specified controllerIP

ref 3rd comment in coreos#439 (comment)
  • Loading branch information
mumoshu authored and cw-kuoka committed May 6, 2016
1 parent 4b71875 commit d5e7161
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions multi-node/aws/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ type StackTemplateOptions struct {

type stackConfig struct {
*Config
UserDataWorker string
UserDataController string
UserDataWorker string
UserDataController string
ControllerSubnetIndex int
}

func execute(filename string, data interface{}, compress bool) (string, error) {
Expand Down Expand Up @@ -227,6 +228,25 @@ func (c Cluster) stackConfig(opts StackTemplateOptions, compressUserData bool) (

stackConfig.Config.TLSConfig = compactAssets

controllerIPAddr := net.ParseIP(stackConfig.ControllerIP)
if controllerIPAddr == nil {
return nil, fmt.Errorf("invalid controllerIP: %s", stackConfig.ControllerIP)
}
controllerSubnetFound := false
lastSubnetIndex := len(stackConfig.Subnets) - 1
for i, subnet := range stackConfig.Subnets {
_, instanceCIDR, err := net.ParseCIDR(subnet.InstanceCIDR)
if err != nil {
return nil, fmt.Errorf("invalid instanceCIDR: %v", err)
}
if instanceCIDR.Contains(controllerIPAddr) {
stackConfig.ControllerSubnetIndex = i
controllerSubnetFound = true
} else if !controllerSubnetFound && i == lastSubnetIndex {
return nil, fmt.Errorf("Fail-fast occurred possibly because of a bug: ControllerSubnetIndex couldn't be determined for subnets (%v) and controllerIP (%v)", stackConfig.Subnets, stackConfig.ControllerIP)
}
}

if stackConfig.UserDataWorker, err = execute(opts.WorkerTmplFile, stackConfig.Config, compressUserData); err != nil {
return nil, fmt.Errorf("failed to render worker cloud config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion multi-node/aws/pkg/config/templates/stack-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
],
"PrivateIpAddress": "{{.ControllerIP}}",
"SubnetId": {
"Ref": "Subnet0"
"Ref": "Subnet{{.ControllerSubnetIndex}}"
}
}
],
Expand Down

0 comments on commit d5e7161

Please sign in to comment.