kubernetes-sigs / node-feature-discovery

Node feature discovery for Kubernetes
Apache License 2.0
769 stars 239 forks source link

Swap misidentified due to trailing newline in file #1751

Closed linuxdaemon closed 2 months ago

linuxdaemon commented 3 months ago

What happened:

While deploying NFD 0.16.0 on a k8s 1.30.2 node (Ubuntu 22.04), I noticed it assigned memory-swap=true despite swap not being enabled on this system.

What you expected to happen:

I expected NFD to recognize that no swap device is registered

How to reproduce it (as minimally and precisely as possible):

As far as I can tell, the issue is that /proc/swaps ends in a newline character \n, while the testdata has no such trailing newline. So any system which has /proc/swaps with a trailing newline will be misidentified.

Anything else we need to know?:

This system is a VM which was initially created with swap which was then removed as part of the k8s provisioning process. /proc/swaps contains only the header line and a single \n character now.

Environment:

I believe the fix is as simple as ignoring empty lines when checking number of lines in the file, though I won't have time to open a PR until next weekend at the earliest, so someone else is welcome to take this on as well.

marquiz commented 2 months ago

Thanks @linuxdaemon for reporting this issue.

ping @kannon92 @TessaIO

TessaIO commented 2 months ago

I will look into this ASAP!

TessaIO commented 2 months ago

/assign