-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add feature for CNI Custom Networking #786
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ type ( | |
// +optional | ||
Network `json:",inline"` // global CIDR and VPC ID | ||
// +optional | ||
PodCIDRs []*ipnet.IPNet `json:"podCIDRs,omitempty"` | ||
// +optional | ||
SecurityGroup string `json:"securityGroup,omitempty"` // cluster SG | ||
// subnets are either public or private for use with separate nodegroups | ||
// these are keyed by AZ for convenience | ||
|
@@ -21,6 +23,8 @@ type ( | |
// for additional CIDR associations, e.g. to use with separate CIDR for | ||
// private subnets or any ad-hoc subnets | ||
// +optional | ||
PodSubnets map[string]*CustomSubnets `json:"podSubnets,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we could just add this as a new topology under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @errordeveloper As in |
||
// +optional | ||
ExtraCIDRs []*ipnet.IPNet `json:"extraCIDRs,omitempty"` | ||
// for pre-defined shared node SG | ||
SharedNodeSecurityGroup string `json:"sharedNodeSecurityGroup,omitempty"` | ||
|
@@ -39,6 +43,12 @@ type ( | |
// +optional | ||
CIDR *ipnet.IPNet `json:"cidr,omitempty"` | ||
} | ||
|
||
// PodSubnets holds the pod VPC CIDR and subnets | ||
CustomSubnets struct { | ||
CIDR *ipnet.IPNet `json:"cidr,omitempty"` | ||
Subnets *ClusterSubnets `json:"subnets,omitempty"` | ||
} | ||
) | ||
|
||
const ( | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package builder | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
gfn "github.com/awslabs/goformation/cloudformation" | ||
|
@@ -10,9 +11,9 @@ import ( | |
"github.com/weaveworks/eksctl/pkg/vpc" | ||
) | ||
|
||
func (c *ClusterResourceSet) addSubnets(refRT *gfn.Value, topology api.SubnetTopology, subnets map[string]api.Network) { | ||
func (c *ClusterResourceSet) addSubnets(refRT *gfn.Value, topology api.SubnetTopology, subnets map[string]api.Network, kind string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function changed a bit (see #776), please rebase :) |
||
for az, subnet := range subnets { | ||
alias := string(topology) + strings.ToUpper(strings.Join(strings.Split(az, "-"), "")) | ||
alias := string(kind) + string(topology) + strings.ToUpper(strings.Join(strings.Split(az, "-"), "")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will have to maintain names of existing keys as they are, so please only add prefix for new subnets... That is because logical names inside the stack need to remain the same for our append-only stack update code to function as expected, but also in general that is essential in CloudFormation. |
||
subnet := &gfn.AWSEC2Subnet{ | ||
AvailabilityZone: gfn.NewString(az), | ||
CidrBlock: gfn.NewString(subnet.CIDR.String()), | ||
|
@@ -31,10 +32,21 @@ func (c *ClusterResourceSet) addSubnets(refRT *gfn.Value, topology api.SubnetTop | |
}} | ||
} | ||
refSubnet := c.newResource("Subnet"+alias, subnet) | ||
c.newResource("RouteTableAssociation"+alias, &gfn.AWSEC2SubnetRouteTableAssociation{ | ||
SubnetId: refSubnet, | ||
RouteTableId: refRT, | ||
}) | ||
if alias == "" { | ||
c.newResource("RouteTableAssociation"+alias, &gfn.AWSEC2SubnetRouteTableAssociation{ | ||
SubnetId: refSubnet, | ||
RouteTableId: refRT, | ||
}) | ||
} else { | ||
c.newResource("RouteTableAssociation"+alias, &awsCloudFormationResource{ | ||
Type: "AWS::EC2::SubnetRouteTableAssociation", | ||
Properties: map[string]interface{}{ | ||
"SubnetId": refSubnet, | ||
"RouteTableId": refRT, | ||
}, | ||
DependsOn: []string{alias}, | ||
}) | ||
} | ||
c.subnets[topology] = append(c.subnets[topology], refSubnet) | ||
} | ||
} | ||
|
@@ -49,6 +61,17 @@ func (c *ClusterResourceSet) addResourcesForVPC() { | |
EnableDnsHostnames: gfn.True(), | ||
}) | ||
|
||
for i, podCIDR := range c.spec.VPC.PodCIDRs { | ||
c.newResource(fmt.Sprintf("PodCIDR%d", i), &awsCloudFormationResource{ | ||
Type: "AWS::EC2::VPCCidrBlock", | ||
Properties: map[string]interface{}{ | ||
"CidrBlock": podCIDR.String(), | ||
"VpcId": c.vpc, | ||
}, | ||
DependsOn: []string{"VPC"}, | ||
}) | ||
} | ||
|
||
c.subnets = make(map[api.SubnetTopology][]*gfn.Value) | ||
|
||
refIG := c.newResource("InternetGateway", &gfn.AWSEC2InternetGateway{}) | ||
|
@@ -67,7 +90,7 @@ func (c *ClusterResourceSet) addResourcesForVPC() { | |
GatewayId: refIG, | ||
}) | ||
|
||
c.addSubnets(refPublicRT, api.SubnetTopologyPublic, c.spec.VPC.Subnets.Public) | ||
c.addSubnets(refPublicRT, api.SubnetTopologyPublic, c.spec.VPC.Subnets.Public, "") | ||
|
||
c.newResource("NATIP", &gfn.AWSEC2EIP{ | ||
Domain: gfn.NewString("vpc"), | ||
|
@@ -89,7 +112,13 @@ func (c *ClusterResourceSet) addResourcesForVPC() { | |
NatGatewayId: refNG, | ||
}) | ||
|
||
c.addSubnets(refPrivateRT, api.SubnetTopologyPrivate, c.spec.VPC.Subnets.Private) | ||
c.addSubnets(refPrivateRT, api.SubnetTopologyPrivate, c.spec.VPC.Subnets.Private, "") | ||
|
||
// TODO add specific name for pod subnets | ||
for i := range c.spec.VPC.PodCIDRs { | ||
|
||
c.addSubnets(refPrivateRT, api.SubnetTopologyPrivate, c.spec.VPC.PodSubnets[fmt.Sprintf("eksctlGroup%d", i)].Subnets.Private, fmt.Sprintf("PodCIDR%d", i)) | ||
} | ||
} | ||
|
||
func (c *ClusterResourceSet) importResourcesForVPC() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ package ipnet | |
// TODO: this is not ideal, we should move this out or do something else about it. | ||
|
||
import ( | ||
"encoding/binary" | ||
"encoding/json" | ||
"fmt" | ||
"net" | ||
"reflect" | ||
|
||
|
@@ -114,3 +116,29 @@ func MustParseCIDR(s string) *IPNet { | |
} | ||
return cidr | ||
} | ||
|
||
// SplitIntoN splits the parent IPNet into n subnets | ||
func SplitIntoN(parent *net.IPNet, n int) ([]*net.IPNet, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to migrate to this and copy the unit tests from kops? (I think they had a few there). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I'm not sure if needs to be |
||
networkLength, _ := parent.Mask.Size() | ||
networkLength += 3 | ||
|
||
var subnets []*net.IPNet | ||
for i := 0; i < n; i++ { | ||
ip4 := parent.IP.To4() | ||
if ip4 != nil { | ||
n := binary.BigEndian.Uint32(ip4) | ||
n += uint32(i) << uint(32-networkLength) | ||
subnetIP := make(net.IP, len(ip4)) | ||
binary.BigEndian.PutUint32(subnetIP, n) | ||
|
||
subnets = append(subnets, &net.IPNet{ | ||
IP: subnetIP, | ||
Mask: net.CIDRMask(networkLength, 32), | ||
}) | ||
} else { | ||
return nil, fmt.Errorf("Unexpected IP address type: %s", parent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the convention is that error string always begin with lower-case... |
||
} | ||
} | ||
|
||
return subnets, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment belongs to
ExtraCIDRs
... please replace it with a comment to say that it need to be deprecated.