in pkg/aws/ec2/instance.go [281:314]
func (i *ec2Instance) updateCurrentSubnetAndCidrBlock(ec2APIHelper api.EC2APIHelper) error {
// Custom networking is being used on node, point the current subnet ID, CIDR block and
// instance security group to the one's present in the Custom networking spec
if i.newCustomNetworkingSubnetID != "" {
if i.newCustomNetworkingSecurityGroups != nil && len(i.newCustomNetworkingSecurityGroups) > 0 {
i.currentInstanceSecurityGroups = i.newCustomNetworkingSecurityGroups
} else {
// when security groups are not specified in ENIConfig, use the primary network interface SG as per custom networking documentation
i.currentInstanceSecurityGroups = i.primaryENISecurityGroups
}
// Only get the subnet CIDR block again if the subnet ID has changed
if i.newCustomNetworkingSubnetID != i.currentSubnetID {
customSubnet, err := ec2APIHelper.GetSubnet(&i.newCustomNetworkingSubnetID)
if err != nil {
return err
}
if customSubnet == nil || customSubnet.CidrBlock == nil {
return fmt.Errorf("failed to find subnet %s", i.newCustomNetworkingSubnetID)
}
i.currentSubnetID = i.newCustomNetworkingSubnetID
i.currentSubnetCIDRBlock = *customSubnet.CidrBlock
// NOTE: IPv6 does not support custom networking
}
} else {
// Custom networking in not being used, point to the primary network interface security group and
// subnet details
i.currentSubnetID = i.instanceSubnetID
i.currentSubnetCIDRBlock = i.instanceSubnetCidrBlock
i.currentSubnetV6CIDRBlock = i.instanceSubnetV6CidrBlock
i.currentInstanceSecurityGroups = i.primaryENISecurityGroups
}
return nil
}