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
Add GetKernelVersion to ipvs.KernelHandler interface #80636
Add GetKernelVersion to ipvs.KernelHandler interface #80636
Conversation
Welcome @ebati! |
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. I understand the commands that are listed here. |
Hi @ebati. 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 Once the patch is verified, the new status will be reflected by the 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. |
5896031
to
e46d051
Compare
There's some work in progress at the moment to move GetKernelVersion into another repo - kubernetes/utils#99 cc @neolit123 @yastij But also, should IPVS tests even run on MacOS? |
On second thought, running kube-proxy unit tests on MacOS is legit and we shouldn't gate on the kernel checks for those. We can probably continue kubernetes/utils#99 after this PR /assign |
I think no release note is fine. |
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 for the PR @ebati, left some comments :)
pkg/util/ipvs/ipvs_test.go
Outdated
} | ||
sort.Strings(got) | ||
sort.Strings(test.want) | ||
for i := range test.want { |
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.
Use reflect.DeepEqual here since the slice is already sorted?
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.
Fixed.
pkg/util/ipvs/ipvs_test.go
Outdated
want []string | ||
}{ | ||
{ | ||
name: "KernelPriorTo4.19", |
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.
test names can have spaces - "kernel version < 4.19"
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.
=) fixed.
pkg/util/ipvs/ipvs_test.go
Outdated
want: []string{ModIPVS, ModIPVSRR, ModIPVSWRR, ModIPVSSH, ModNfConntrackIPV4}, | ||
}, | ||
{ | ||
name: "Kernel4.19", |
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.
kernel version 4.19
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.
fixed.
pkg/util/ipvs/ipvs.go
Outdated
if ver1.LessThan(ver2) { | ||
ipvsModules = append(ipvsModules, ModIPVS, ModIPVSRR, ModIPVSWRR, ModIPVSSH, ModNfConntrackIPV4) | ||
if kernelVersion.LessThan(criticalVers) { | ||
return []string{ModIPVS, ModIPVSRR, ModIPVSWRR, ModIPVSSH, ModNfConntrackIPV4} | ||
} else { |
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.
else
not needed
pkg/proxy/ipvs/proxier.go
Outdated
// parse kernel version | ||
kernelVersion, err := version.ParseGeneric(kernelVersionStr) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing kernel version: %v(%s)", err, kernelVersion) |
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.
"error parsing kernel version %q: %v", kernelVersion, err
?
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 moved this block from the old version, but you are right.
pkg/proxy/ipvs/proxier.go
Outdated
// GetKernelVersion returns currently running kernel version. | ||
func (handle *LinuxKernelHandler) GetKernelVersion() (*version.Version, error) { | ||
kernelVersionFile := "/proc/sys/kernel/osrelease" | ||
out, err := handle.executor.Command("cut", "-f1", "-d", " ", kernelVersionFile).CombinedOutput() |
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.
A bit overdue, but we should use strings.Fields
here instead of execing into cut
. Can we fix it here or add a TODO comment?
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 read file with limiting buffer size as suggested in the other issue you linked. AFAIK we don't need to call Fields
as this file contains only kernel version in this file. But i used it to match older behavior. I checked kernel documentation but couldn't conclude if this file can have multiple columns of text.
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 noticed we removed the strings.TrimSpace
check, I agree it's probably not needed here because of strings.Fields
but I can't say confidently that it wasn't added for no reason.
/ok-to-test |
IPVS as a whole should be Linux scoped only. for unit tests, these should be in a separate file with |
I updated the BUILD file inside |
BUILD files lgtm |
pkg/util/ipvs/ipvs.go
Outdated
// "nf_conntrack_ipv4" has been removed since v4.19 | ||
// see https://github.com/torvalds/linux/commit/a0ae2562c6c4b2721d9fddba63b7286c13517d9f | ||
ver2, _ := version.ParseGeneric("4.19") | ||
criticalVers := version.MustParseGeneric("4.19") |
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.
Why name criticalVers
?
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.
it is changing behavior so a critical point but i can change it to ver
?
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 something more descriptive would be nice. Maybe something like versionNfConntrackIPv4Removed
?
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 comment is up one line and the scope is very limited so if it is ok for you, i think just ver
is enough?
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.
How about this?
if kernelVersion.LessThan(version.MustParseGeneric("4.19")) {
return []string{KernelModuleIPVS, KernelModuleIPVSRR, KernelModuleIPVSWRR, KernelModuleIPVSSH, KernelModuleNfConntrackIPV4}
}
return []string{KernelModuleIPVS, KernelModuleIPVSRR, KernelModuleIPVSWRR, KernelModuleIPVSSH, KernelModuleNfConntrack}
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.
Yes that is even better =)
pkg/util/ipvs/ipvs_test.go
Outdated
for _, test := range Tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got := GetRequiredIPVSModules(test.kernelVersion) | ||
if len(got) != len(test.want) { |
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.
reflect.DeepEqual
check below should cover this case
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.
It left over from previous version, i will fix it.
pkg/proxy/ipvs/proxier.go
Outdated
} | ||
defer f.Close() | ||
|
||
bf := bufio.NewScanner(f) |
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.
Curious why not ioutil.ReadFile?
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.
ReadFile
reads all to memory and the issue you linked suggest 1K limit if i remember correctly.
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.
hmm good point, I think iotuil.ReadFile
is OK given the assumptions around /proc/sys/kernel/osrelease
. If we want the 1KB limit, I don't think a Scanner is required can just use a bytes.Buffer (see bytes.NewBuffer) and read from os.File
returned from os.Open
.
Thanks for this PR! This problem has been a pain working on kube-proxy on Mac. |
pkg/proxy/ipvs/proxier.go
Outdated
for i := range mods { | ||
fields := strings.Fields(mods[i]) | ||
if len(fields) > 0 { | ||
mods[i] = fields[0] |
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.
define a new slice for this instead of reusing mods
pkg/proxy/ipvs/proxier.go
Outdated
return append(mods, bmods...), nil | ||
} | ||
|
||
// getFirstWordOfEachLine reads all the content from r into memory and return a | ||
// slice which consists of the first word from each line. | ||
func getFirstWordOfEachLine(r io.Reader) ([]string, error) { |
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.
getFirstColumn
?
pkg/proxy/ipvs/proxier.go
Outdated
return "", fmt.Errorf("error reading osrelease file %q: %v", kernelVersionFile, err) | ||
} | ||
|
||
fields := strings.Fields(string(fileContent)) |
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.
On second thought, this can just be strings.TrimSpace - same as before. I think strings.Fields is only required for the modules
Looks good, though I'm not very familiar with IPVS. |
I cant find any log for failed test so testing again... /retest |
/approve |
/priority important-soon |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewsykim, dcbw, ebati 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 |
/hold just noticed the commit messages, please squash them or group them into some meaningful way |
ipvs `getProxyMode` test fails on mac as `utilipvs.GetRequiredIPVSMods` try to reach `/proc/sys/kernel/osrelease` to find version of the running linux kernel. Linux kernel version is used to determine the list of required kernel modules for ipvs. Logic to determine kernel version is moved to GetKernelVersion method in LinuxKernelHandler which implements ipvs.KernelHandler. Mock KernelHandler is used in the test cases. Read and parse file is converted to go function instead of execing cut.
0fd3683
to
90ce2d5
Compare
/lgtm |
ipvs
getProxyMode
test fails on mac asutilipvs.GetRequiredIPVSMods
try to reach
/proc/sys/kernel/osrelease
to find version of the runninglinux kernel. Linux kernel version is used to determine the list of required
kernel modules for ipvs.
Logic to determine kernel version is moved to GetKernelVersion
method in LinuxKernelHandler which implements ipvs.KernelHandler.
Mock KernelHandler is used in the test cases.
Fixes #80504.
/kind cleanup
Special notes for your reviewer:
I write
NONE
to release-note block. However this PR changes an exported interface, do i need to write a note?Does this PR introduce a user-facing change?: