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

Filter pods that have out of range IP #1963

Merged
merged 2 commits into from Apr 27, 2023

Conversation

sawsa307
Copy link
Contributor

Filter pods have IPs outside of the corresponding nodes' IP ranges.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 21, 2023
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 21, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @sawsa307. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 21, 2023
@sawsa307
Copy link
Contributor Author

/assign @swetharepakula

@sawsa307 sawsa307 force-pushed the filter-pod-using-podcidr branch 2 times, most recently from fe88f4d to 963f048 Compare February 21, 2023 21:38
if !isNode {
return false
}
_, podCIDR, err := netset.ParseCIDRSloppy(node.Spec.PodCIDR)
Copy link
Member

Choose a reason for hiding this comment

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

you can omit the custom parsers here and use the std library ones, net.ParseCIDR()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Antonio, i found in the comment section for ParseCIDRSloppy, it says We're choosing to keep it for compat with potential stored values., where the values refer to CIDR with leading '0' characters on numbers. Is there a specific reason that we can be sure that there is no need to consider CIDR like this?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, that is a good question, we had to do it in kubernetes to keep compatibility, imagine someone created a service with the ip 10.001.1.1, if he upgrades that Service will be invalid, and we don't want to break it.

For components that use the kubernetes API they have more freedom to make their choice and say, since version X if we found that IP we are going to reject it, so please update your manifests.

I prefer for the ecosystem to "force" this evolution and not keep the old parsers, it should be a problem only for Kubernetes/kubernetes not for the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. That makes sense. Thank you!

return false
}
_, podCIDR, err := netset.ParseCIDRSloppy(node.Spec.PodCIDR)
podIP := net.ParseIP(pod.Status.PodIP)
Copy link
Member

Choose a reason for hiding this comment

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

the CNI not necessarily have to use node.Spec.PodCIDR , that means that this relation may not be always true, also, if the CNI is supposed to use the CIDR this double check should not be necessary, because this can only happen if the CNI is wrong.

In addition, there is a plan to support multiple PodCIDRs, so node.Spec.PodCIDRs will contain a slice of networks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The checks is related to the problem of preemptible node with the buggy 1.22 node eviction logic. We are verify this because it might cause the NEG not to be sync completely. We are operation it on the assumption that there might be a bug somewhere else.
Currently since we are only supporting single network ipv4, we only do check for ipv4. As we add support for the other feature, this will be updated.
@swetharepakula

Copy link
Member

Choose a reason for hiding this comment

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

then it is better if you iterate over the node.Spec.PodCIDRs list too , and returns true if there is a match, and false if there is no match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'll change it. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

I commented in the other PR you sent with a sketch of a solution

@aojea
Copy link
Member

aojea commented Feb 22, 2023

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 22, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2023
@sawsa307 sawsa307 force-pushed the filter-pod-using-podcidr branch 2 times, most recently from 2dd2c7f to fc1e477 Compare March 10, 2023 22:46
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2023
@sawsa307 sawsa307 force-pushed the filter-pod-using-podcidr branch 3 times, most recently from e0a1233 to b37cf85 Compare March 15, 2023 23:27
@sawsa307 sawsa307 force-pushed the filter-pod-using-podcidr branch 5 times, most recently from b8c4612 to 25a99ce Compare April 18, 2023 03:06
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 18, 2023
Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

The pod IP validation needs to consider a few more edge cases

@@ -527,10 +535,13 @@ func validatePod(pod *apiv1.Pod, nodeLister cache.Indexer) error {
if err != nil || !exists {
return negtypes.ErrEPNodeNotFound
}
_, isNode := obj.(*apiv1.Node)
node, isNode := obj.(*apiv1.Node)
Copy link
Member

Choose a reason for hiding this comment

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

nit: by convention we use ok instead of isNode

// If dual stack is enabled, it would return error if either ipv4 or ipv6 address does not match to the pod IPs
func podContainsEndpointAddress(networkEndpoint negtypes.NetworkEndpoint, pod *apiv1.Pod, enableDualStackNEG bool) error {
endpointIPs := []string{networkEndpoint.IP}
if enableDualStackNEG {
Copy link
Member

Choose a reason for hiding this comment

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

check that there is a dual stack endpoint. It is possible dual stack is enabled but this service is not a dual stack service.

Comment on lines 616 to 618
for _, podIP := range pod.Status.PodIPs {
podIPs = append(podIPs, net.ParseIP(podIP.IP))
}
Copy link
Member

Choose a reason for hiding this comment

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

since the pod ips have already been verified, use the network endpoint we formed instead. This might be a dual stack cluster, but it might not be a dual stack service so both endpoints may not need to be verified.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 21, 2023
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 22, 2023
@sawsa307 sawsa307 force-pushed the filter-pod-using-podcidr branch 3 times, most recently from d202d16 to d87e0fd Compare April 26, 2023 22:00
Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

few small comments, otherwise this is ready to merge

pkg/neg/syncers/utils.go Show resolved Hide resolved
pkg/neg/syncers/utils_test.go Outdated Show resolved Hide resolved
Filter pods have IPs outside of the corresponding nodes' IP ranges.
@sawsa307
Copy link
Contributor Author

/retest

Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sawsa307, swetharepakula

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 743ff5b into kubernetes:master Apr 27, 2023
5 checks passed
@sawsa307 sawsa307 deleted the filter-pod-using-podcidr branch September 2, 2023 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants