From 66a9a9f22fea4d4303ea18db6aae7a12fd840873 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 1 Feb 2017 14:44:14 +0900 Subject: [PATCH] Generalize subnet names so that we can have mutiple private or public subnets per AZ --- config/config.go | 13 +-- config/config_test.go | 12 +-- config/templates/stack-template.json | 29 ++++-- e2e/run | 6 ++ model/etcd.go | 7 +- model/identifier.go | 14 +-- model/nat_gateway.go | 93 +++++++++++++------ model/subnet.go | 82 ++++++++-------- nodepool/config/config.go | 28 ++++-- nodepool/config/templates/cluster.yaml | 8 +- nodepool/config/templates/stack-template.json | 50 ---------- test/integration/maincluster_test.go | 54 +++++------ 12 files changed, 201 insertions(+), 195 deletions(-) diff --git a/config/config.go b/config/config.go index 102b434e1..db2fda51c 100644 --- a/config/config.go +++ b/config/config.go @@ -185,8 +185,8 @@ func (c *Cluster) SetDefaults() { publicTopologyImplied := c.RouteTableID != "" && c.MapPublicIPs for i, s := range c.Subnets { - if s.CustomName == "" { - c.Subnets[i].CustomName = fmt.Sprintf("Subnet%d", i) + if s.Name == "" { + c.Subnets[i].Name = fmt.Sprintf("Subnet%d", i) } // DEPRECATED AND REMOVED IN THE FUTURE @@ -969,7 +969,7 @@ func (s DeploymentSettings) AllSubnets() []model.Subnet { func (c DeploymentSettings) FindSubnetMatching(condition model.Subnet) model.Subnet { for _, s := range c.Subnets { - if s.CustomName == condition.CustomName { + if s.Name == condition.Name { return s } } @@ -1015,14 +1015,15 @@ func (c DeploymentSettings) NATGateways() []model.NATGateway { var publicSubnet model.Subnet ngwConfig := privateSubnet.NATGateway if privateSubnet.ManageNATGateway() { - found := false + publicSubnetFound := false for _, s := range c.PublicSubnets() { if s.AvailabilityZone == privateSubnet.AvailabilityZone { publicSubnet = s - found = true + publicSubnetFound = true + break } } - if !found { + if !publicSubnetFound { panic(fmt.Sprintf("No appropriate public subnet found for a non-preconfigured NAT gateway associated to private subnet %s", privateSubnet.LogicalName())) } ngw := model.NewNATGateway(ngwConfig, privateSubnet, publicSubnet) diff --git a/config/config_test.go b/config/config_test.go index 5d6982adb..2aee4569a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -332,12 +332,12 @@ subnets: { InstanceCIDR: "10.4.3.0/24", AvailabilityZone: "ap-northeast-1a", - CustomName: "Subnet0", + Name: "Subnet0", }, { InstanceCIDR: "10.4.4.0/24", AvailabilityZone: "ap-northeast-1c", - CustomName: "Subnet1", + Name: "Subnet1", }, }, }, @@ -353,7 +353,7 @@ instanceCIDR: 10.4.3.0/24 { AvailabilityZone: "ap-northeast-1a", InstanceCIDR: "10.4.3.0/24", - CustomName: "Subnet0", + Name: "Subnet0", }, }, }, @@ -370,7 +370,7 @@ subnets: [] { AvailabilityZone: "ap-northeast-1a", InstanceCIDR: "10.4.3.0/24", - CustomName: "Subnet0", + Name: "Subnet0", }, }, }, @@ -384,7 +384,7 @@ subnets: [] { AvailabilityZone: "ap-northeast-1a", InstanceCIDR: "10.0.0.0/24", - CustomName: "Subnet0", + Name: "Subnet0", }, }, }, @@ -397,7 +397,7 @@ availabilityZone: "ap-northeast-1a" { AvailabilityZone: "ap-northeast-1a", InstanceCIDR: "10.0.0.0/24", - CustomName: "Subnet0", + Name: "Subnet0", }, }, }, diff --git a/config/templates/stack-template.json b/config/templates/stack-template.json index 6f4acdd38..ec39120d4 100644 --- a/config/templates/stack-template.json +++ b/config/templates/stack-template.json @@ -1148,7 +1148,7 @@ {{end}} {{range $index, $subnet := .Subnets}} - {{if $subnet.ManageSubnet }} + {{if $subnet.ManageSubnet}} , "{{$subnet.LogicalName}}": { "Properties": { @@ -1179,12 +1179,12 @@ } {{if $subnet.ManageRouteTable}} , - "{{$subnet.RouteTableName}}": { + "{{$subnet.RouteTableLogicalName}}": { "Properties": { "Tags": [ { "Key": "Name", - "Value": "{{$.ClusterName}}-{{$subnet.RouteTableName}}" + "Value": "{{$.ClusterName}}-{{$subnet.RouteTableLogicalName}}" }, { "Key": "KubernetesCluster", @@ -1196,7 +1196,6 @@ "Type": "AWS::EC2::RouteTable" } {{end}} - {{end}} {{if $.ElasticFileSystemID}} , "{{$subnet.LogicalName}}MountTarget": { @@ -1210,7 +1209,7 @@ {{end}} {{if $subnet.ManageRouteToInternet}} , - "{{$subnet.RouteTableName}}ToInternet": { + "{{$subnet.InternetGatewayRouteLogicalName}}": { "Properties": { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": {{$.InternetGatewayRef}}, @@ -1220,6 +1219,7 @@ } {{end}} {{end}} + {{end}} {{range $i, $ngw := .NATGateways}} {{if $ngw.ManageEIP}} @@ -1241,18 +1241,20 @@ "Type": "AWS::EC2::NatGateway" } {{end}} - {{if $ngw.ManageRoute}} + {{range $_, $s := $ngw.PrivateSubnets}} + {{if $s.ManageRouteToNATGateway}} , - "{{$ngw.NATGatewayRouteName}}": { + "{{$s.NATGatewayRouteLogicalName}}": { "Properties": { "DestinationCidrBlock": "0.0.0.0/0", "NatGatewayId": {{$ngw.Ref}}, - "RouteTableId": {{$ngw.PrivateSubnetRouteTableRef}} + "RouteTableId": {{$s.RouteTableRef}} }, "Type": "AWS::EC2::Route" } {{end}} {{end}} + {{end}} {{if not .InternetGatewayID}} , @@ -1314,10 +1316,17 @@ {{end}} {{range $index, $subnet := .Subnets}} {{if $subnet.ManageRouteTable}} - "{{$subnet.RouteTableName}}" : { + "{{$subnet.RouteTableLogicalName}}" : { "Description" : "The route table assigned to the subnet {{$subnet.LogicalName}}", "Value" : {{$subnet.RouteTableRef}}, - "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-{{$subnet.RouteTableName}}" }} + "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-{{$subnet.RouteTableLogicalName}}" }} + }, + {{end}} + {{if $subnet.ManageSubnet}} + "{{$subnet.LogicalName}}" : { + "Description" : "The subnet id of {{$subnet.LogicalName}}", + "Value" : {{$subnet.Ref}}, + "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-{{$subnet.LogicalName}}" }} }, {{end}} {{end}} diff --git a/e2e/run b/e2e/run index 02238b2fb..322123c82 100755 --- a/e2e/run +++ b/e2e/run @@ -488,6 +488,12 @@ nodepools_destroy() { KUBE_AWS_NODE_POOL_INDEX=2 nodepool_destroy } +nodepools_rerun() { + nodepools_destroy + build + nodepools +} + all_destroy() { nodepools_destroy main_destroy diff --git a/model/etcd.go b/model/etcd.go index cb5d2eec6..16fca71cc 100644 --- a/model/etcd.go +++ b/model/etcd.go @@ -35,16 +35,13 @@ func (i etcdInstanceImpl) SubnetRef() string { } func (i etcdInstanceImpl) DependencyExists() bool { - return i.subnet.Private && i.natGateway != nil && i.natGateway.ManageRoute() + return i.subnet.Private && i.subnet.ManageRouteToNATGateway() } func (i etcdInstanceImpl) DependencyRef() (string, error) { // We have to wait until the route to the NAT gateway if it doesn't exist yet(hence ManageRoute=true) or the etcd node fails due to inability to connect internet if i.DependencyExists() { - name, err := i.natGateway.NATGatewayRouteName() - if err != nil { - return "", err - } + name := i.subnet.NATGatewayRouteLogicalName() return fmt.Sprintf(`"%s"`, name), nil } return "", nil diff --git a/model/identifier.go b/model/identifier.go index 3cba1d3ce..c9d995db9 100644 --- a/model/identifier.go +++ b/model/identifier.go @@ -13,23 +13,25 @@ func (i Identifier) HasIdentifier() bool { return i.ID != "" || i.IDFromStackOutput != "" } -func (i Identifier) Ref(logicalName string) string { +func (i Identifier) Ref(logicalNameProvider func() string) string { if i.IDFromStackOutput != "" { - return fmt.Sprintf(`{ "ImportValue" : %q }`, i.IDFromStackOutput) + return fmt.Sprintf(`{ "Fn::ImportValue" : %q }`, i.IDFromStackOutput) } else if i.ID != "" { return fmt.Sprintf(`"%s"`, i.ID) } else { - return fmt.Sprintf(`{ "Ref" : %q }`, logicalName) + return fmt.Sprintf(`{ "Ref" : %q }`, logicalNameProvider()) } } -func (i Identifier) IdOrRef(refProvider func() (string, error)) (string, error) { +// RefOrError should be used instead of Ref where possible so that kube-aws can print a more useful error message with +// the line number for the stack-template.json when there's an error. +func (i Identifier) RefOrError(logicalNameProvider func() (string, error)) (string, error) { if i.IDFromStackOutput != "" { - return fmt.Sprintf(`{ "ImportValue" : %q }`, i.IDFromStackOutput), nil + return fmt.Sprintf(`{ "Fn::ImportValue" : %q }`, i.IDFromStackOutput), nil } else if i.ID != "" { return fmt.Sprintf(`"%s"`, i.ID), nil } else { - logicalName, err := refProvider() + logicalName, err := logicalNameProvider() if err != nil { return "", fmt.Errorf("failed to get id or ref: %v", err) } diff --git a/model/nat_gateway.go b/model/nat_gateway.go index a2ff9b65c..8c3bfcc75 100644 --- a/model/nat_gateway.go +++ b/model/nat_gateway.go @@ -9,6 +9,14 @@ type NATGatewayConfig struct { EIPAllocationID string `yaml:"eipAllocationId,omitempty"` } +func (c NATGatewayConfig) Validate() error { + if c.HasIdentifier() && c.EIPAllocationID != "" { + return fmt.Errorf("eipAllocationId can't be specified for a existing nat gatway. It is an user's responsibility to configure the nat gateway if one tried to reuse an existing one: %+v", c) + } + return nil +} + +// kube-aws manages at most one NAT gateway per subnet type NATGateway interface { EIPAllocationIDRef() string EIPLogicalName() string @@ -17,33 +25,48 @@ type NATGateway interface { ManageEIP() bool ManageNATGateway() bool ManageRoute() bool - NATGatewayRouteName() (string, error) Ref() string - PrivateSubnetRouteTableRef() (string, error) PublicSubnetRef() string + PrivateSubnets() []Subnet Validate() error } type natGatewayImpl struct { NATGatewayConfig - privateSubnet Subnet - publicSubnet Subnet + privateSubnets []Subnet + publicSubnet Subnet } func NewNATGateway(c NATGatewayConfig, private Subnet, public Subnet) NATGateway { return natGatewayImpl{ NATGatewayConfig: c, - privateSubnet: private, + privateSubnets: []Subnet{private}, publicSubnet: public, } } func (g natGatewayImpl) LogicalName() string { - return fmt.Sprintf("NatGateway%s", g.privateSubnet.AvailabilityZoneLogicalName()) + name := "" + for _, s := range g.privateSubnets { + name = name + s.LogicalName() + } + return fmt.Sprintf("NatGateway%s", name) } func (g natGatewayImpl) ManageNATGateway() bool { - return g.privateSubnet.ManageNATGateway() + allTrue := true + allFalse := true + for _, s := range g.privateSubnets { + allTrue = allTrue && s.ManageNATGateway() + allFalse = allFalse && !s.ManageNATGateway() + } + if allTrue { + return true + } else if allFalse { + return false + } + + panic(fmt.Sprintf("[bug] assertion failed: private subnets associated to this nat gateway(%+v) conflicts in their settings. kube-aws is confused and can't decide whether it should manage the nat gateway or not", g)) } func (g natGatewayImpl) ManageEIP() bool { @@ -51,7 +74,19 @@ func (g natGatewayImpl) ManageEIP() bool { } func (g natGatewayImpl) ManageRoute() bool { - return g.privateSubnet.ManageRouteToNATGateway() + allTrue := true + allFalse := true + for _, s := range g.privateSubnets { + allTrue = allTrue && s.ManageRouteToNATGateway() + allFalse = allFalse && !s.ManageRouteToNATGateway() + } + if allTrue { + return true + } else if allFalse { + return false + } + + panic(fmt.Sprintf("[bug] assertion failed: private subnets associated to this nat gateway(%+v) conflicts in their settings. kube-aws is confused and can't decide whether it should manage the route to nat gateway or not", g)) } func (g natGatewayImpl) EIPLogicalName() string { @@ -66,41 +101,39 @@ func (g natGatewayImpl) EIPAllocationIDRef() string { } func (g natGatewayImpl) IsConnectedToPrivateSubnet(s Subnet) bool { - return g.privateSubnet.LogicalName() == s.LogicalName() + for _, ps := range g.privateSubnets { + if ps.LogicalName() == s.LogicalName() { + return true + } + } + return false } func (g natGatewayImpl) Ref() string { - return g.Identifier.Ref(g.LogicalName()) + return g.Identifier.Ref(g.LogicalName) } func (g natGatewayImpl) PublicSubnetRef() string { return g.publicSubnet.Ref() } -func (g natGatewayImpl) PrivateSubnetRouteTableRef() (string, error) { - ref, err := g.privateSubnet.RouteTableRef() - if err != nil { - return "", err - } - return ref, nil -} - -func (g natGatewayImpl) NATGatewayRouteName() (string, error) { - return fmt.Sprintf("%sRouteToNatGateway", g.privateSubnet.ReferenceName()), nil +func (g natGatewayImpl) PrivateSubnets() []Subnet { + return g.privateSubnets } func (g natGatewayImpl) Validate() error { + if err := g.NATGatewayConfig.Validate(); err != nil { + return fmt.Errorf("failed to validate nat gateway: %v", err) + } if !g.ManageNATGateway() { - if !g.privateSubnet.HasIdentifier() { - return fmt.Errorf("a preconfigured NGW must be associated to an existing private subnet: %+v", g) - } - - if g.publicSubnet.Provided() { - return fmt.Errorf("a preconfigured NGW must not be associated to an existing public subnet: %+v", g) - } - - if !g.privateSubnet.RouteTable.HasIdentifier() { - return fmt.Errorf("a preconfigured NGW must have an existing route table provided via routeTable.id or routeTable.idFromStackOutput: %+v", g) + for i, s := range g.privateSubnets { + if !s.HasIdentifier() { + return fmt.Errorf("a preconfigured NGW must be associated to an existing private subnet #%d: %+v", i, g) + } + + if !s.RouteTable.HasIdentifier() { + return fmt.Errorf("a preconfigured NGW must have an existing route table provided via routeTable.id or routeTable.idFromStackOutput: %+v", g) + } } if g.HasIdentifier() { diff --git a/model/subnet.go b/model/subnet.go index b571b6da4..1871897fd 100644 --- a/model/subnet.go +++ b/model/subnet.go @@ -7,13 +7,13 @@ import ( type Subnet struct { Identifier `yaml:",inline"` - CustomName string `yaml:"name,omitempty"` AvailabilityZone string `yaml:"availabilityZone,omitempty"` + Name string `yaml:"name,omitempty"` InstanceCIDR string `yaml:"instanceCIDR,omitempty"` - RouteTable RouteTable `yaml:"routeTable,omitempty"` - NATGateway NATGatewayConfig `yaml:"natGateway,omitempty"` InternetGateway InternetGateway `yaml:"internetGateway,omitempty"` - Private bool + NATGateway NATGatewayConfig `yaml:"natGateway,omitempty"` + Private bool `yaml:"private,omitempty"` + RouteTable RouteTable `yaml:"routeTable,omitempty"` } func NewPublicSubnet(az string, cidr string) Subnet { @@ -100,46 +100,19 @@ func NewImportedPublicSubnet(az string, name string) Subnet { } } -func (s *Subnet) Provided() bool { - return s.AvailabilityZone != "" -} - func (s *Subnet) Public() bool { return !s.Private } -func (s *Subnet) AvailabilityZoneLogicalName() string { - return strings.Replace(strings.Title(s.AvailabilityZone), "-", "", -1) -} - func (s *Subnet) MapPublicIPs() bool { return !s.Private } -func (s *Subnet) ResourcePrefix() string { - var t string - if s.Private { - t = "Private" - } else { - t = "Public" - } - return t -} - -func (s *Subnet) ReferenceName() string { - if s.ManageSubnet() { - return s.LogicalName() - } else if s.ID != "" { - return s.ID - } - return s.IDFromStackOutput -} - func (s *Subnet) LogicalName() string { - if s.CustomName != "" { - return s.CustomName + if s.Name != "" { + return strings.Replace(strings.Title(s.Name), "-", "", -1) } - return s.ResourcePrefix() + "Subnet" + s.AvailabilityZoneLogicalName() + panic(fmt.Sprintf("Name must be set for a subnet: %+v", *s)) } func (s *Subnet) RouteTableID() string { @@ -153,7 +126,7 @@ func (s *Subnet) RouteTableID() string { // * the route table for the subnet is going to be managed by kube-aws(an existing subnet is NOT specified) and // * an existing NAT gateway ID is not specified to be reused func (s *Subnet) ManageNATGateway() bool { - return s.Private && s.ManageRouteTable() && !s.NATGateway.HasIdentifier() + return s.managePrivateRouteTable() && !s.NATGateway.HasIdentifier() } // ManageRouteToNATGateway returns true if a route to a NAT gateway for this subnet must be created or updated by kube-aws @@ -161,7 +134,11 @@ func (s *Subnet) ManageNATGateway() bool { // * the NGW is going to be managed or // * an existing NAT gateway ID is specified func (s *Subnet) ManageRouteToNATGateway() bool { - return s.ManageNATGateway() || s.NATGateway.HasIdentifier() + return s.managePrivateRouteTable() +} + +func (s *Subnet) managePrivateRouteTable() bool { + return s.Private && s.ManageRouteTable() } // ManageRouteTable returns true if a route table for this subnet must be created or updated by kube-aws @@ -170,7 +147,7 @@ func (s *Subnet) ManageRouteTable() bool { return s.ManageSubnet() && !s.RouteTable.HasIdentifier() } -// ManageRouteToInternet returns true if a route from this subnet to to an IGW must be created or updated by kube-aws +// ManageRouteToInternet returns true if a route from this subnet to an IGW must be created or updated by kube-aws // kube-aws creates a route to an IGW for an subnet if and only if: // * the subnet is public and // * the subnet is going to be managed by kube-aws and @@ -191,22 +168,41 @@ func (s *Subnet) ManageSubnet() bool { // Ref returns ID or ref to newly created resource func (s *Subnet) Ref() string { - return s.Identifier.Ref(s.LogicalName()) + return s.Identifier.Ref(s.LogicalName) } -// RouteTableName represents the name of the route table to which this subnet is associated. -func (s *Subnet) RouteTableName() (string, error) { +// RouteTableLogicalName represents the name of the route table to which this subnet is associated. +func (s *Subnet) RouteTableLogicalName() (string, error) { // There should be no need to call this func if the route table isn't going to be created/updated by kube-aws if !s.ManageRouteTable() { - return "", fmt.Errorf("[bug] assertion failed: RouteTableName() must be called if and only if ManageRouteTable() returns true") + return "", fmt.Errorf("[bug] assertion failed: RouteTableLogicalName() must be called if and only if ManageRouteTable() returns true") } - return s.ResourcePrefix() + "RouteTable" + s.AvailabilityZoneLogicalName(), nil + return s.subnetSpecificResourceLogicalName("RouteTable"), nil +} + +func (s *Subnet) InternetGatewayRouteLogicalName() string { + return s.subnetSpecificResourceLogicalName("RouteToInternet") +} + +func (s *Subnet) NATGatewayRouteLogicalName() string { + return s.subnetSpecificResourceLogicalName("RouteToNatGateway") +} + +func (s *Subnet) subnetSpecificResourceLogicalName(resourceName string) string { + return fmt.Sprintf("%s%s", s.LogicalName(), resourceName) } func (s *Subnet) RouteTableRef() (string, error) { - return s.RouteTable.IdOrRef(s.RouteTableName) + return s.RouteTable.RefOrError(s.RouteTableLogicalName) } +// kube-aws manages at most one route table per subnet +// If ID or IDFromStackOutput is non-zero, kube-aws doesn't manage the route table but its users' responsibility to +// provide properly configured one to be reused by kube-aws. +// More concretely: +// * If an user is going to reuse an existing route table for a private subnet, it must have a route to a NAT gateway +// * A NAT gateway can be either a classical one with a NAT EC2 instance or an AWS-managed one +// * IF an user is going to reuse an existing route table for a public subnet, it must have a route to an Internet gateway type RouteTable struct { Identifier `yaml:",inline"` } diff --git a/nodepool/config/config.go b/nodepool/config/config.go index 99e7687f6..185c528dd 100644 --- a/nodepool/config/config.go +++ b/nodepool/config/config.go @@ -144,16 +144,28 @@ func ClusterFromBytes(data []byte, main *cfg.Config) (*ProvidedConfig, error) { return nil, fmt.Errorf("invalid cluster: %v", err) } - // For backward-compatibility - if len(c.Subnets) == 0 { - c.Subnets = []model.Subnet{ - model.NewPublicSubnet(c.AvailabilityZone, c.InstanceCIDR), - } + // Fetch subnets defined in the main cluster by name + for i, s := range c.Worker.Subnets { + linkedSubnet := main.FindSubnetMatching(s) + c.Worker.Subnets[i] = linkedSubnet + } + + // Default to subnets defined in the main cluster + // CAUTION: cluster-autoscaler Won't work if there're 2 or more subnets spanning over different AZs + if len(c.Worker.Subnets) == 0 { + c.Worker.Subnets = main.Worker.Subnets } - for i, s := range c.Subnets { - if s.CustomName == "" { - c.Subnets[i].CustomName = fmt.Sprintf("Subnet%d", i) + // Import all the managed subnets from the main cluster i.e. don't create subnets inside the node pool cfn stack + for i, s := range c.Worker.Subnets { + if !s.HasIdentifier() { + stackOutputName := fmt.Sprintf("%s-%s", main.ClusterName, s.LogicalName()) + az := s.AvailabilityZone + if s.Private { + c.Worker.Subnets[i] = model.NewImportedPublicSubnet(az, stackOutputName) + } else { + c.Worker.Subnets[i] = model.NewImportedPrivateSubnet(az, stackOutputName) + } } } diff --git a/nodepool/config/templates/cluster.yaml b/nodepool/config/templates/cluster.yaml index 59de4289d..0737ecf0f 100644 --- a/nodepool/config/templates/cluster.yaml +++ b/nodepool/config/templates/cluster.yaml @@ -167,11 +167,11 @@ vpcCIDR: "{{.VPCCIDR}}" # instanceCIDR: "10.0.0.0/24" # Kubernetes subnets with their CIDRs and availability zones. Differentiating availability zone for 2 or more subnets result in high-availability (failures of a single availability zone won't result in immediate downtimes) +# However please beware that cluster-autoscaler doesn't support a node pool backed by an ASG assigned to multi AZs. +# If you're planning to use cluster-autoscaler, just use a single subnet for each node pool and create multiple node pools for high-availability. # subnets: -# - availabilityZone: us-west-1a -# instanceCIDR: "10.0.0.0/24" -# - availabilityZone: us-west-1b -# instanceCIDR: "10.0.1.0/24" +# # Fetch subnets managed in the main cluster by name to be reused in this node pool +# - name: PrivateSubnet1a # Required by kubelet to locate the cluster-internal dns hosted on controller nodes in the base cluster dnsServiceIP: "{{.DNSServiceIP}}" diff --git a/nodepool/config/templates/stack-template.json b/nodepool/config/templates/stack-template.json index 6741f84c5..64a89233d 100644 --- a/nodepool/config/templates/stack-template.json +++ b/nodepool/config/templates/stack-template.json @@ -351,55 +351,5 @@ }, "Type": "AWS::IAM::Role" } - - {{range $index, $subnet := .Subnets}} - , - "{{$subnet.LogicalName}}": { - "Properties": { - "AvailabilityZone": "{{$subnet.AvailabilityZone}}", - "CidrBlock": "{{$subnet.InstanceCIDR}}", - "MapPublicIpOnLaunch": {{$subnet.MapPublicIPs}}, - "Tags": [ - { - "Key": "Name", - "Value": "{{$.ClusterName}}-{{$.NodePoolName}}-{{$subnet.LogicalName}}" - }, - { - "Key": "KubernetesCluster", - "Value": "{{$.ClusterName}}" - } - ], - "VpcId": {{$.VPCRef}} - }, - "Type": "AWS::EC2::Subnet" - }, - "{{$subnet.LogicalName}}RouteTableAssociation": { - "Properties": { - "RouteTableId": - {{if not $subnet.RouteTableID}} - {{if $subnet.Private}} - {"Fn::ImportValue" : {"Fn::Sub" : "{{$.ClusterName}}-PrivateRouteTable{{$subnet.AvailabilityZoneLogicalName}}"}}, - {{else}} - {"Fn::ImportValue" : {"Fn::Sub" : "{{$.ClusterName}}-PublicRouteTable{{$subnet.AvailabilityZoneLogicalName}}"}}, - {{end}} - {{else}} - "{{$subnet.RouteTableID}}", - {{end}} - "SubnetId": {{$subnet.Ref}} - }, - "Type": "AWS::EC2::SubnetRouteTableAssociation" - } - {{if $.ElasticFileSystemID}} - , - "{{$subnet.LogicalName}}MountTarget": { - "Properties" : { - "FileSystemId": "{{$.ElasticFileSystemID}}", - "SubnetId": {{$subnet.Ref}}, - "SecurityGroups": [ { "Ref": "SecurityGroupMountTarget" } ] - }, - "Type" : "AWS::EFS::MountTarget" - } - {{end}} - {{end}} } } diff --git a/test/integration/maincluster_test.go b/test/integration/maincluster_test.go index 39a84aafc..053f46dc8 100644 --- a/test/integration/maincluster_test.go +++ b/test/integration/maincluster_test.go @@ -18,7 +18,7 @@ type ConfigTester func(c *config.Cluster, t *testing.T) func TestMainClusterConfig(t *testing.T) { hasDefaultEtcdSettings := func(c *config.Cluster, t *testing.T) { subnet1 := model.NewPublicSubnet("us-west-1c", "10.0.0.0/24") - subnet1.CustomName = "Subnet0" + subnet1.Name = "Subnet0" expected := config.EtcdSettings{ Etcd: model.Etcd{ Subnets: []model.Subnet{ @@ -232,10 +232,10 @@ subnets: hasDefaultExperimentalFeatures, func(c *config.Cluster, t *testing.T) { private1 := model.NewPrivateSubnetWithPreconfiguredNATGateway("us-west-1a", "10.0.1.0/24", "rtb-1a2b3c4d") - private1.CustomName = "Subnet0" + private1.Name = "Subnet0" private2 := model.NewPrivateSubnetWithPreconfiguredNATGateway("us-west-1b", "10.0.2.0/24", "rtb-1a2b3c4d") - private2.CustomName = "Subnet1" + private2.Name = "Subnet1" subnets := []model.Subnet{ private1, @@ -309,10 +309,10 @@ subnets: hasDefaultExperimentalFeatures, func(c *config.Cluster, t *testing.T) { private1 := model.NewPublicSubnetWithPreconfiguredInternetGateway("us-west-1a", "10.0.1.0/24", "rtb-1a2b3c4d") - private1.CustomName = "Subnet0" + private1.Name = "Subnet0" private2 := model.NewPublicSubnetWithPreconfiguredInternetGateway("us-west-1b", "10.0.2.0/24", "rtb-1a2b3c4d") - private2.CustomName = "Subnet1" + private2.Name = "Subnet1" subnets := []model.Subnet{ private1, @@ -400,16 +400,16 @@ worker: everyPublicSubnetHasRouteToIGW, func(c *config.Cluster, t *testing.T) { private1 := model.NewPrivateSubnet("us-west-1a", "10.0.1.0/24") - private1.CustomName = "private1" + private1.Name = "private1" private2 := model.NewPrivateSubnet("us-west-1b", "10.0.2.0/24") - private2.CustomName = "private2" + private2.Name = "private2" public1 := model.NewPublicSubnet("us-west-1a", "10.0.3.0/24") - public1.CustomName = "public1" + public1.Name = "public1" public2 := model.NewPublicSubnet("us-west-1b", "10.0.4.0/24") - public2.CustomName = "public2" + public2.Name = "public2" subnets := []model.Subnet{ private1, @@ -483,16 +483,16 @@ subnets: everyPublicSubnetHasRouteToIGW, func(c *config.Cluster, t *testing.T) { private1 := model.NewPrivateSubnet("us-west-1a", "10.0.1.0/24") - private1.CustomName = "private1" + private1.Name = "private1" private2 := model.NewPrivateSubnet("us-west-1b", "10.0.2.0/24") - private2.CustomName = "private2" + private2.Name = "private2" public1 := model.NewPublicSubnet("us-west-1a", "10.0.3.0/24") - public1.CustomName = "public1" + public1.Name = "public1" public2 := model.NewPublicSubnet("us-west-1b", "10.0.4.0/24") - public2.CustomName = "public2" + public2.Name = "public2" subnets := []model.Subnet{ private1, @@ -576,16 +576,16 @@ worker: everyPublicSubnetHasRouteToIGW, func(c *config.Cluster, t *testing.T) { private1 := model.NewPrivateSubnet("us-west-1a", "10.0.1.0/24") - private1.CustomName = "private1" + private1.Name = "private1" private2 := model.NewPrivateSubnet("us-west-1b", "10.0.2.0/24") - private2.CustomName = "private2" + private2.Name = "private2" public1 := model.NewPublicSubnet("us-west-1a", "10.0.3.0/24") - public1.CustomName = "public1" + public1.Name = "public1" public2 := model.NewPublicSubnet("us-west-1b", "10.0.4.0/24") - public2.CustomName = "public2" + public2.Name = "public2" subnets := []model.Subnet{ private1, @@ -670,16 +670,16 @@ worker: everyPublicSubnetHasRouteToIGW, func(c *config.Cluster, t *testing.T) { private1 := model.NewPrivateSubnet("us-west-1a", "10.0.1.0/24") - private1.CustomName = "private1" + private1.Name = "private1" private2 := model.NewPrivateSubnet("us-west-1b", "10.0.2.0/24") - private2.CustomName = "private2" + private2.Name = "private2" public1 := model.NewPublicSubnet("us-west-1a", "10.0.3.0/24") - public1.CustomName = "public1" + public1.Name = "public1" public2 := model.NewPublicSubnet("us-west-1b", "10.0.4.0/24") - public2.CustomName = "public2" + public2.Name = "public2" subnets := []model.Subnet{ private1, @@ -759,16 +759,16 @@ worker: hasDefaultExperimentalFeatures, func(c *config.Cluster, t *testing.T) { private1 := model.NewExistingPrivateSubnet("us-west-1a", "subnet-1") - private1.CustomName = "private1" + private1.Name = "private1" private2 := model.NewImportedPrivateSubnet("us-west-1b", "mycluster-private-subnet-1") - private2.CustomName = "private2" + private2.Name = "private2" public1 := model.NewExistingPublicSubnet("us-west-1a", "subnet-2") - public1.CustomName = "public1" + public1.Name = "public1" public2 := model.NewImportedPublicSubnet("us-west-1b", "mycluster-public-subnet-1") - public2.CustomName = "public2" + public2.Name = "public2" subnets := []model.Subnet{ private1, @@ -833,7 +833,7 @@ routeTableId: rtb-1a2b3c4d hasDefaultExperimentalFeatures, func(c *config.Cluster, t *testing.T) { subnet1 := model.NewPublicSubnetWithPreconfiguredInternetGateway("us-west-1c", "10.0.0.0/24", "rtb-1a2b3c4d") - subnet1.CustomName = "Subnet0" + subnet1.Name = "Subnet0" subnets := []model.Subnet{ subnet1, } @@ -967,7 +967,7 @@ etcdDataVolumeIOPS: 104 hasDefaultExperimentalFeatures, func(c *config.Cluster, t *testing.T) { subnet1 := model.NewPublicSubnetWithPreconfiguredInternetGateway("us-west-1c", "10.0.0.0/24", "rtb-1a2b3c4d") - subnet1.CustomName = "Subnet0" + subnet1.Name = "Subnet0" subnets := []model.Subnet{ subnet1, }