-
Notifications
You must be signed in to change notification settings - Fork 54
OCPBUGS-87249: on AWS, select associated IPv6 CIDR block for egress IP subnet #228
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
base: main
Are you sure you want to change the base?
Changes from all 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 |
|---|---|---|
|
|
@@ -276,23 +276,32 @@ func (a *AWS) getSubnet(networkInterface *ec2.InstanceNetworkInterface) (*net.IP | |
| var v4Subnet, v6Subnet *net.IPNet | ||
| subnet := describeOutput.Subnets[0] | ||
| if subnet.CidrBlock != nil && *subnet.CidrBlock != "" { | ||
| _, subnet, err := net.ParseCIDR(*subnet.CidrBlock) | ||
| _, v4Net, err := net.ParseCIDR(*subnet.CidrBlock) | ||
|
Contributor
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. Why do you have to change the variable name here?
Author
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 subnet variable is used for v4 and v6 below, it's like one variable used for two different ipstack types, it is easy to get confused , that is why I changed the variable name. But I can revert if you prefer minimal change |
||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("error: unable to parse IPv4 subnet, err: %v", err) | ||
| } | ||
| v4Subnet = subnet | ||
| v4Subnet = v4Net | ||
| } | ||
|
|
||
| // I don't know what it means to have several IPv6 CIDR blocks defined for | ||
| // one subnet, specially given that you can only have one IPv4 CIDR block | ||
| // defined...¯\_(ツ)_/¯ | ||
| // Let's just pick the first. | ||
| if len(subnet.Ipv6CidrBlockAssociationSet) > 0 && subnet.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock != nil && *subnet.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock != "" { | ||
| _, subnet, err := net.ParseCIDR(*subnet.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock) | ||
| // A subnet can have multiple IPv6 CIDR block associations (e.g., a previous | ||
| // "disassociated" one and a current "associated" one). On dualstack AWS clusters | ||
| // after subnet CIDR changes, picking the wrong (stale) CIDR causes egress IP | ||
| // assignment to fail because OVN-Kubernetes selects IPs from the wrong range. | ||
| // Always select the first association in "associated" state. | ||
| for _, assoc := range subnet.Ipv6CidrBlockAssociationSet { | ||
| if assoc.Ipv6CidrBlock == nil || *assoc.Ipv6CidrBlock == "" { | ||
| continue | ||
| } | ||
| if assoc.Ipv6CidrBlockState == nil || assoc.Ipv6CidrBlockState.State == nil || | ||
| *assoc.Ipv6CidrBlockState.State != ec2.SubnetCidrBlockStateCodeAssociated { | ||
|
Member
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. is there a possibility of more than one associated subnet ? hope you have checked it.
Author
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. Yes, technically AWS allows multiple IPv6 CIDR blocks in associated state simultaneously (e.g., when additional IPv6 prefixes are added to a subnet). The current code takes the first associated entry, silently ignoring any others. This means EgressIPs can only be assigned from the first CIDR. This is consistent with how we handle the node's subnet today. If multiple associated entries exist, should I add a klog.Warningf when a second associated entry is found to make this situation visible in logs? Is that what you expect? |
||
| continue | ||
| } | ||
| _, v6Net, err := net.ParseCIDR(*assoc.Ipv6CidrBlock) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("error: unable to parse IPv6 subnet, err: %v", err) | ||
| } | ||
| v6Subnet = subnet | ||
| v6Subnet = v6Net | ||
| break | ||
| } | ||
|
|
||
| return v4Subnet, v6Subnet, 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.
so previously does it took 'disassociated' subnet entry at [0] which is different from host subnet, what was that subnet value ? just curious.