Specify subnetid and routetableid via cloud provider config

This commit is contained in:
Henrik Schmidt 2017-04-07 16:04:52 +02:00
parent ad3e0903f3
commit 1c1f02fde3
2 changed files with 27 additions and 12 deletions

View File

@ -392,6 +392,10 @@ type CloudConfig struct {
// on a different aws account, on a different cloud provider or on-premise. // on a different aws account, on a different cloud provider or on-premise.
// If the flag is set also the KubernetesClusterTag must be provided // If the flag is set also the KubernetesClusterTag must be provided
VPC string VPC string
// SubnetID enables using a specific subnet to use for ELB's
SubnetID string
// RouteTableID enables using a specific RouteTable
RouteTableID string
// KubernetesClusterTag is the legacy cluster id we'll use to identify our cluster resources // KubernetesClusterTag is the legacy cluster id we'll use to identify our cluster resources
KubernetesClusterTag string KubernetesClusterTag string
@ -817,13 +821,14 @@ func newAWSCloud(config io.Reader, awsServices Services) (*Cloud, error) {
deviceAllocators: make(map[types.NodeName]DeviceAllocator), deviceAllocators: make(map[types.NodeName]DeviceAllocator),
} }
if cfg.Global.VPC != "" && (cfg.Global.KubernetesClusterTag != "" || cfg.Global.KubernetesClusterID != "") { if cfg.Global.VPC != "" && cfg.Global.SubnetID != "" && (cfg.Global.KubernetesClusterTag != "" || cfg.Global.KubernetesClusterID != "") {
// When the master is running on a different AWS account, cloud provider or on-premise // When the master is running on a different AWS account, cloud provider or on-premise
// build up a dummy instance and use the VPC from the nodes account // build up a dummy instance and use the VPC from the nodes account
glog.Info("Master is configured to run on a AWS account, different cloud provider or on-premise") glog.Info("Master is configured to run on a different AWS account, different cloud provider or on-premise")
awsCloud.selfAWSInstance = &awsInstance{ awsCloud.selfAWSInstance = &awsInstance{
nodeName: "master-dummy", nodeName: "master-dummy",
vpcID: cfg.Global.VPC, vpcID: cfg.Global.VPC,
subnetID: cfg.Global.SubnetID,
} }
awsCloud.vpcID = cfg.Global.VPC awsCloud.vpcID = cfg.Global.VPC
} else { } else {

View File

@ -29,19 +29,29 @@ func (c *Cloud) findRouteTable(clusterName string) (*ec2.RouteTable, error) {
// This should be unnecessary (we already filter on TagNameKubernetesCluster, // This should be unnecessary (we already filter on TagNameKubernetesCluster,
// and something is broken if cluster name doesn't match, but anyway... // and something is broken if cluster name doesn't match, but anyway...
// TODO: All clouds should be cluster-aware by default // TODO: All clouds should be cluster-aware by default
request := &ec2.DescribeRouteTablesInput{Filters: c.tagging.addFilters(nil)} var tables []*ec2.RouteTable
if c.cfg.Global.RouteTableID != "" {
request := &ec2.DescribeRouteTablesInput{Filters: []*ec2.Filter{newEc2Filter("route-table-id", c.cfg.Global.RouteTableID)}}
response, err := c.ec2.DescribeRouteTables(request)
if err != nil {
return nil, err
}
tables = response
} else {
request := &ec2.DescribeRouteTablesInput{Filters: c.tagging.addFilters(nil)}
response, err := c.ec2.DescribeRouteTables(request) response, err := c.ec2.DescribeRouteTables(request)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var tables []*ec2.RouteTable
for _, table := range response { for _, table := range response {
if c.tagging.hasClusterTag(table.Tags) { if c.tagging.hasClusterTag(table.Tags) {
tables = append(tables, table) tables = append(tables, table)
} }
} }
}
if len(tables) == 0 { if len(tables) == 0 {
return nil, fmt.Errorf("unable to find route table for AWS cluster: %s", clusterName) return nil, fmt.Errorf("unable to find route table for AWS cluster: %s", clusterName)