Don't create route table at all if all subnets are shared

We don't link it up anyway, so we shouldn't try to create it
This commit is contained in:
Justin Santa Barbara 2017-01-24 11:09:12 -05:00
parent 4d49abb272
commit 3185d115cb
1 changed files with 24 additions and 12 deletions

View File

@ -76,6 +76,15 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
// TODO: would be good to create these as shared, to verify them // TODO: would be good to create these as shared, to verify them
} }
allSubnetsShared := true
for i := range b.Cluster.Spec.Subnets {
subnetSpec := &b.Cluster.Spec.Subnets[i]
sharedSubnet := subnetSpec.ProviderID != ""
if !sharedSubnet {
allSubnetsShared = false
}
}
// We always have a public route table, though for private networks it is only used for NGWs and ELBs // We always have a public route table, though for private networks it is only used for NGWs and ELBs
var publicRouteTable *awstasks.RouteTable var publicRouteTable *awstasks.RouteTable
{ {
@ -87,18 +96,21 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
} }
c.AddTask(igw) c.AddTask(igw)
publicRouteTable = &awstasks.RouteTable{ if !allSubnetsShared {
Name: s(b.ClusterName()), publicRouteTable = &awstasks.RouteTable{
VPC: b.LinkToVPC(), Name: s(b.ClusterName()),
} VPC: b.LinkToVPC(),
c.AddTask(publicRouteTable) }
c.AddTask(publicRouteTable)
c.AddTask(&awstasks.Route{ // TODO: Validate when allSubnetsShared
Name: s("0.0.0.0/0"), c.AddTask(&awstasks.Route{
CIDR: s("0.0.0.0/0"), Name: s("0.0.0.0/0"),
RouteTable: publicRouteTable, CIDR: s("0.0.0.0/0"),
InternetGateway: igw, RouteTable: publicRouteTable,
}) InternetGateway: igw,
})
}
} }
privateZones := sets.NewString() privateZones := sets.NewString()
@ -143,9 +155,9 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
Subnet: subnet, Subnet: subnet,
}) })
// TODO: validate even if shared?
privateZones.Insert(subnetSpec.Zone) privateZones.Insert(subnetSpec.Zone)
} }
default: default:
return fmt.Errorf("subnet %q has unknown type %q", subnetSpec.Name, subnetSpec.Type) return fmt.Errorf("subnet %q has unknown type %q", subnetSpec.Name, subnetSpec.Type)
} }