Skip to content
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

Fixed IPv4 podCIDR check in case spec.PodCIDR is IPv6 #1672

Merged
merged 2 commits into from
Nov 16, 2022

Conversation

rbrtbnfgl
Copy link
Contributor

Description

When using kubeadm if the podSubnet is dualstack and specified as IPv6,IPv4 spec.PodCIDR of the node will be the IPv6 and Flannel will fail to check the IPv4 CIDR. (#1629).
This PR will remove the check of spec.PodCIDR to always check spec.PodCIDRs for both IPv4 and IPv6.

Todos

  • Tests
  • Documentation
  • Release note

Release Note

None required

Copy link
Collaborator

@manuelbuil manuelbuil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just checked on 1.24 and podCIDRs == 0 is something that should never happen. It might be because of the old version of Hyperkube we are using, I'd recommend to first update that version and then see if this issue still exists


for _, podCidr := range n.Spec.PodCIDRs {
_, parseCidr, err := net.ParseCIDR(podCidr)
if len(n.Spec.PodCIDRs) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a switch:

switch len(n.Spec.PodCIDRs) {
case 0:
     // do stuff with n.Spec.PodCIDR
case len(n.Spec.PodCIDRs) < 3:
     // do stuff with n.Spec.PodCIDRs
default:
    // fail!

That way we are protected of weird cases

_, cidr, err := net.ParseCIDR(n.Spec.PodCIDR)
if err != nil {
return l, err
cidr := new(net.IPNet)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is cleaner to define it as it was in line 296

if err != nil {
return l, err
cidr := new(net.IPNet)
if len(n.Spec.PodCIDRs) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the switch

return l, err
cidr := new(net.IPNet)
if len(n.Spec.PodCIDRs) == 0 {
_, cidr, err = net.ParseCIDR(n.Spec.PodCIDR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to check if this is ipv6 or ipv4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because if IPv4 is enabled and no IPv4 CIDR is specified on the pod subnet Flannel should throw an error before the subnet manager starts.

return l, err
}
} else {
log.Infof("Creating the node lease for IPv4. This is the n.Spec.PodCIDRs: %v", n.Spec.PodCIDRs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log will only be correct if len =1, right?

@rbrtbnfgl rbrtbnfgl merged commit 9184f54 into flannel-io:master Nov 16, 2022
@rbrtbnfgl rbrtbnfgl deleted the fixpodCIDR branch November 16, 2022 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants