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
[Dual-stack] Fix generateAPIPodStatus() of kubelet handling Secondary IP #116879
[Dual-stack] Fix generateAPIPodStatus() of kubelet handling Secondary IP #116879
Conversation
568868e
to
f35d0e7
Compare
/assign |
@aojea: GitHub didn't allow me to request PR reviews from the following users: he, has, a, to, try, organize, this, keep. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign |
8b36f12
to
bc7ee64
Compare
/test pull-kubernetes-e2e-kind |
/triage accepted |
pkg/kubelet/kubelet_pods.go
Outdated
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()}) | ||
ok, err := utilnet.IsDualStackIPStrings([]string{s.PodIPs[0].IP, hostIPs[1].String()}) | ||
if err != nil { | ||
kl.recorder.Eventf(pod, v1.EventTypeWarning, "InvalidHostIPs", "host IP is invalid %q", hostIPs[1].String()) |
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.
You can't get an error here. s.PodIPs
is validated and hostIPs
comes from a function that only returns valid IPs.
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.
Undetstood, but I think we'd better still handle the error?
kubernetes/pkg/apis/core/validation/validation.go
Lines 7118 to 7119 in 9e571c0
dualStack, err := netutils.IsDualStackIPStrings(service.Spec.ClusterIPs) | |
if err != nil { // though we check for that earlier. safe > sorry |
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.
yeh, I think there is also a linter now or is going to be added to enforce that
pkg/kubelet/kubelet_pods.go
Outdated
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()}) | ||
} else { | ||
kl.recorder.Eventf(pod, v1.EventTypeWarning, "InvalidHostIPs", | ||
"Inconsistent addresses order received from the cloud-provider, IP family of the second host IP %q is the same as the first one configured in the kubelet %q", |
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.
The wording here is not great in terms of helping the admin understand what to do.
Also, if we are going to notice the "you requested IPv4 but the cloud provider wants dual-stack IPv6-primary" case, then we should really also notice the "you requested IPv4 but the cloud provider wants single-stack IPv6" case too. (It is likely that the original reporter was also running into that case but just didn't notice yet because it doesn't cause any explicit errors. But it may cause problems later with Services.)
So, starting at line 1627:
- if
utilnet.IPFamilyOfString(s.HostIP) != utilnet.IPFamilyOf(hostIPs[0])
then we need to log a warning:- if
s.HostIP
is IPv4 then the problem is that kubelet auto-detected an IPv4 node IP, but the cloud provider wants this to be a single-stack IPv6 or dual-stack IPv6-primary node, and so the fix is for the admin to either (a) pass--node-ip ::
to kubelet to tell it to prefer IPv6 like the cloud provider wants, (b) pass--node-ip <EXPLICIT-IPV4-ADDRESS>
to request a single-stack IPv4 node with a specific IP. (OnceCloudDualStackNodeIPs
is beta we can also suggest (c) pass--node-ip <EXPLICIT-IPV4-ADDRESS>,<EXPLICIT-IPV6-ADDRESS>
.) - if
s.HostIP
is IPv6 then the problem is that the admin passed--node-ip ::
to request an IPv6 node IP, but the cloud provider wants this to be a single-stack IPv4 or dual-stack IPv4-primary node, and so the fix is for the admin to either (a) not pass--node-ip ::
to kubelet and let it default to IPv4-primary like the cloud provider wants, (b)/(c) pass an explicit IPv6 IP as above
- if
- regardless of whether it logged a warning, it should do
s.HostIP = hostIPs[0].String()
, as it does now - if the pod is host-network then:
- it should set
s.PodIPs[0]
tohostIPs[0]
ifs.PodIPs
is unset, as it does now - it should set
s.PodIPs[1]
tohostIPs[1]
iflen(hostIPs) == 2 && len(s.PodIPs) == 1
andutilnet.IPFamilyOfString(s.PodIPs[0].IP) != utilnet.IPFamilyOf(hostIPs[1])
- (the family mismatch can only happen if we have already logged an error above, so we don't need to warn again here)
- it should set
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.
if s.HostIP is IPv4 then the problem is that kubelet auto-detected an IPv4 node IP, but the cloud provider
I think you are talking about hostIPs[0]
?
Thanks for the detailed explanation. Updated.
7f43437
to
c297ee8
Compare
c297ee8
to
c8c6ff8
Compare
/retest |
I think is ok, but defer to Dan, he is driving all this node-ip effort and the person more familiar with it |
@danwinship hello, do you have any other comments? Thank you. |
pkg/kubelet/kubelet_pods.go
Outdated
ok, err := utilnet.IsDualStackIPStrings([]string{s.HostIP, hostIPs[0].String()}) | ||
if err != nil { | ||
kl.recorder.Eventf(pod, v1.EventTypeWarning, "InvalidHostIPs", "host IPs are invalid %q or %q", s.HostIP, hostIPs[0].String()) | ||
} | ||
if ok { |
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.
I think
if utilnet.IPFamilyOfString(s.HostIP) != utilnet.IPFamilyOf(hostIPs[0]) {
is clearer: the error case can't actually happen anyway, and we're comparing exactly two IPs, not scanning a possibly-long list of IPs.
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.
I also prefer clearer code. Updated.
pkg/kubelet/kubelet_pods.go
Outdated
} | ||
if ok { | ||
// Once CloudDualStackNodeIPs is beta, <EXPLICIT-IPV4-ADDRESS>,<EXPLICIT-IPV6-ADDRESS> can be set to --node-ip. | ||
if utilnet.IPFamilyOf(hostIPs[0]) == utilnet.IPv4 { |
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.
if utilnet.IsIPv4(hostIPs[0]) {
actually, wait, this is backwards: hostIPs
is what the cloud provider chose, s.HostIP
is what kubelet detected.
pkg/kubelet/kubelet_pods.go
Outdated
// kubelet auto-detected an IPv4 node IP (hostIPs[0]), but the cloud provider wants this to be | ||
// a single-stack IPv6 or dual-stack IPv6-primary node | ||
kl.recorder.Eventf(pod, v1.EventTypeWarning, "HostIPsIPFamilyMismatch", | ||
"set [::] or an explicit IPv4 address to --node-ip") |
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.
The information that is in the comment needs to be in the Event text instead to make it understandable (after which you no longer need the comment).
"Kubelet auto-detected an IPv4 node IP, but the cloud provider selected an IPv6 node IP; pass an explicit `--node-ip` to kubelet to fix this."
pkg/kubelet/kubelet_pods.go
Outdated
// kubelet auto-detected an IPv6 node IP (hostIPs[0]), but the cloud provider wants this to be | ||
// a single-stack IPv4 or dual-stack IPv4-primary node | ||
kl.recorder.Eventf(pod, v1.EventTypeWarning, "HostIPsIPFamilyMismatch", | ||
"do not set --node-ip or set an explicit IPv4 address to --node-ip") |
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.
likewise. Also, the fix here is to pass an explicit IPv6 address, not IPv4.
actually, we don't really even need separate errors for the v4 and v6 case. Just replace this all (1627-1646) with:
if s.HostIP != "" && utilnet.IPFamilyOfString(s.HostIP) != utilnet.IPFamilyOf(hostIPs[0]) {
kl.recorder.Eventf(pod, v1.EventTypeWarning, "HostIPsIPFamilyMismatch",
"Kubelet detected an IPv%s node IP (%s), but the cloud provider selected an IPv%s node IP (%s); pass an explicit `--node-ip` to kubelet to fix this.",
utilnet.IPFamilyOfString(s.HostIP), s.HostIP, utilnet.IPFamilyOf(hostIPs[0])), hostIPs[0].String())
}
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.
done
pkg/kubelet/kubelet_pods.go
Outdated
@@ -1635,7 +1655,12 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po | |||
} | |||
// Secondary IP is not set #105320 | |||
if len(hostIPs) == 2 && len(s.PodIPs) == 1 { | |||
s.PodIPs = append(s.PodIPs, v1.PodIP{IP: hostIPs[1].String()}) | |||
ok, err := utilnet.IsDualStackIPStrings([]string{s.PodIPs[0].IP, hostIPs[1].String()}) |
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.
again, I think using IPFamilyOf != IPFamilyOf
would be clearer here, and get rid of the unnecessary error check
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.
done
hostIPs order may not be be consistent. If secondary IP is before primary one, current logic adds primary IP twice into PodIPs, which leads to error: "may specify no more than one IP for each IP family". In this case, the second IP shouldn't be added. Co-authored-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
c8c6ff8
to
985cf71
Compare
/lgtm |
LGTM label has been added. Git tree hash: fe173fc6f04c8dc9bb1440ee78c5caa1aca2d19d
|
/assign @Random-Liu |
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.
Thanks!
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lzhecheng, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
1 similar comment
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
What type of PR is this?
/kind bug
What this PR does / why we need it:
[Dual-stack] Fix generateAPIPodStatus() of kubelet handling Secondary IP. hostIPs order may not be be consistent. If secondary IP is before primary one, current logic adds primary IP twice into PodIPs, which leads to error: "may specify no more than one IP for each IP family".
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: