1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00
Commit graph

31 commits

Author SHA1 Message Date
Markus Lehtonen
a5e2d4ca16 source: make per-source unit tests stricter
Now the tests check that GetLabels() works even without calling
Discover() at all.
2021-12-03 10:26:26 +02:00
Markus Lehtonen
6f881a4822 source/kernel: unmangled kconfig values for custom rules
Stop converting "=y" and "=m" to "true" for the raw feature values used
in "kernel.config" custom rule processing.

In practice, this means that to check if a kernel config flag has been
set to "y" or "m", one needs to explicitly check for both of the values:

  matchFeatures:
    - feature: kernel.config
      matchExpressions:
        FOO: {op: In, value: ["y", "m"]}

instead of (how it used to be):

  matchFeatures:
    - feature: kernel.config
      matchExpressions:
        FOO: {op: IsTrue}

The legacy kconfig custom rule is unchanged as are the
kernel-config.<flag> feature labels.
2021-12-02 10:06:21 +02:00
Markus Lehtonen
0df88ac6f6 source/kernel: drop length check of kconfig values
Do not do length checking here. We do not need/want to limit the values
here because they could still be used in custom rules. Moreover, we do
more proper validation of label all label values in nfd-worker, anyway.
2021-12-01 17:21:53 +02:00
Markus Lehtonen
d4efc2ce0b source/kernel: ditch regexp in kconfig parsing
Regexp is just a resource hog here and does not simplify the code.
2021-11-30 14:43:05 +02:00
Markus Lehtonen
d60fcb98e4 source/kernel: don't advertise selinux.enabled=false
Commit 0945019161 changed the behavior so
that NFD started to advertise also "false" status of selinux.enabled
label. This patch reverts this behavior (i.e. we only have
selinux.enabled=true). The rationale behind is avoiding any excess
labels - selinux.enabled=false label would be pointless noise in most
deployments.
2021-11-23 20:12:20 +02:00
Markus Lehtonen
5cf25dc4e9 source/custom: move kernel module detection to source/kernel
Move the functionality responsible for detection of loeaded kernel
modules from source/custom over to the source/kernel package. Add a new
"loadedmodule" raw feature to the kernel source to store this
information.

Change loadedKmod custom rule to utilize kernel source.
2021-11-11 18:33:58 +02:00
Markus Lehtonen
0945019161 source/kernel: implement FeatureSource
Separate feature discovery and creation of feature labels in the kernel
source.

Move kernelutils from source/internal back to the source/kernel package.
Change the kconfig custom rule to rely on the FeatureSource interface
(GetFeatures()) of the kernel source.

Also, add minimalist unit test.
2021-11-11 18:33:40 +02:00
Markus Lehtonen
852cf4b61d source: introduce FeatureSource interface
Specify a new interface for managing "raw" feature data. This is the
first step to separate raw feature data from node labels. None of the
feature sources implement this interface, yet.

This patch unifies the data format of "raw" features by dividing them
into three different basic types.
- keys, a set of names without any associated values, e.g. CPUID flags
  or loaded kernel modules
- values, a map of key-value pairs, for features with a single value,
  e.g. kernel config flags or os version
- instances, a list of instances each of which has multiple attributes
  (key-value pairs of their own), e.g. PCI or USB devices

The new feature data types are defined in a new "pkg/api/feature"
package, catering decoupling and re-usability of code e.g. within future
extentions of the NFD gRPC API.

Rename the Discover() method of LabelSource interface to GetLabels().
2021-09-20 09:58:07 +03:00
Markus Lehtonen
81378a3235 source: make sources register themselves
Implement new registration infrastructure under the "source" package.
This change loosens the coupling between label sources and the
nfd-worker, making it easier to refactor and move the code around.

Also, create a separate interface (ConfigurableSource) for configurable
feature sources in order to eliminate boilerplate code.

Add safety checks to the sources that they actually implement the
interfaces they should.

In sake of consistency and predictability (of behavior) change all
methods of the sources to use pointer receivers.

Add simple unit tests for the new functionality and include source/...
into make test target.
2021-09-15 18:41:37 +03:00
Markus Lehtonen
befa7e9796 source: rename FeatureSource to LabelSource
Prepare for separating feature detection from label creation.
2021-09-13 22:48:33 +03:00
Markus Lehtonen
73704e2e11 source/kernel: better error reporting
Get rid of distracting error in the log in case selinux is not enabled
in the kernel. Still print an error only if sysfs/fs directory is not
available, though, which indicates that we're not able to correctly
detect the presence of selinux.
2021-08-13 09:13:19 +03:00
Markus Lehtonen
610b1c696c source: define source names as consts
Paves the way for future work on more general representation of
feature data and looser coupling of the data and feature source
interface.
2021-06-11 15:29:57 +03:00
Carlos Eduardo Arango Gutierrez
389a8f87cf
logging: start log messages with lower case
Standarize logs to be lower case.

Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>
2021-03-01 10:07:21 -05:00
Markus Lehtonen
7da7fde8f6 nfd-worker: switch to klog
Greatly expands logging capabilities and flexibility with verbosity
options, among other things.
2021-02-25 16:10:43 +02:00
Markus Lehtonen
ba4ecfe7dc kernel: more agressively sanitize full kernel version
Trim illegal characters from the beginning and end of the kernel version
string. Label values must start and end with an alphanumeric and we want
to have some 'version.full' label, even if a sanitized one.
2020-11-23 19:04:12 +02:00
Mikko Ylinen
8b156d49fc source/kernel: add internal helper to get kernel version
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
2020-09-14 12:07:35 +03:00
Mikko Ylinen
aeb7583315 source/kernel: move kconfig to a shared internal package
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
2020-09-14 12:07:33 +03:00
Mikko Ylinen
3fd314b600 source/kernel: add more search paths
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
2020-09-14 12:06:23 +03:00
Markus Lehtonen
a2b9df5cd3 nfd-worker: rework configuration handling
Extend the FeatureSource interface with new methods for configuration
handling. This enables easier on-the fly reconfiguration of the
feature sources. Further, it simplifies adding config support to feature
sources in the future. Stub methods are added to sources that do not
currently have any configurability.

The patch fixes some (corner) cases with the overrides (--options)
handling, too:
- Overrides were not applied if config file was missing or its parsing
  failed
- Overrides for a certain source did not have effect if an empty config
  for the source was specified in the config file. This was caused by
  the first pass of parsing (config file) setting a nil pointer to the
  source-specific config, effectively detaching it from the main config.
  The second pass would then create a new instance of the source
  specific config, but, this was not visible in the feature source, of
  course.
2020-05-21 00:59:37 +03:00
Markus Lehtonen
248859c64d source: parametrise host directory paths
Specify and handle system paths we use for discovery in a unified way.
2020-05-20 22:15:41 +03:00
Markus Lehtonen
640dc9fbf3 source: miscellaneous lint fixes 2020-05-20 21:48:06 +03:00
Pablo Rodriguez
3c81ff9d80 kernel.go: Replace forbidden symbols
Some Kernel versions include symbols such as "+".
Yocto L4T kernel is an example of this behaviour.
To fix this error all unknown symbols are replaced by an underscore.

Signed-off-by: Pablo Rodriguez <paroque28@gmail.com>
2020-05-15 17:58:08 +00:00
Markus Lehtonen
6002a00750 kernel: fix undefined symbol error
Fix a build failure that slipped through when adding support for
non-binary kconfig options in #197,
2019-06-10 15:25:41 +03:00
Kubernetes Prow Robot
8c666cbdc2
Merge pull request #197 from marquiz/devel/kconfig
Support non-binary kconfig options in kernel feature source
2019-06-07 11:44:00 -07:00
Markus Lehtonen
d4cb0e742b Use standard logger for all feature sources 2019-04-25 17:17:41 +03:00
Markus Lehtonen
eeed6d14b1 Support non-binary kconfig options in kernel feature source
Discover other than bool or tristate kconfig options, too. For bool and
tristate the node label is still binary (i.e. set to "true" if the
kconfig option has been enabled). For other kconfig types (e.g. string
or int) the value of the label directly corresponds to the value of the
kconfig flag, e.g. "32", "elf64-x86-64" etc.
2019-02-22 22:15:25 +02:00
Markus Lehtonen
e8249e6fa3 Move selinux detection to kernel feature source
Remove the 'selinux' feature source and move the functionality under the
'kernel' feature source. The selinux feature label is changed to
  feature.node.kubernetes.io/selinux.enabled

The selinux feature source was rather narrow in scope, and, the sole
feature it advertised naturally falls under the kernel feature source.
2019-01-03 10:08:28 +02:00
Markus Lehtonen
47a97db35a Import from sigs.k8s.io/node-feature-discovery 2018-12-04 15:15:46 +02:00
Markus Lehtonen
4053010dd9 Make the kernel feature source configurable
Adding two config options:
- kernel config file to read
- kconfig options that are detected
2018-12-04 09:34:56 +02:00
Markus Lehtonen
ce129aef88 Implement kernel config detection
This implementation only detects kconfig options ("NO_HZ", "NO_HZ_IDLE",
"NO_HZ_FULL" and "PREEMPT"). The corresponding node labels will be
  node.alpha.kubernetes-incubator.io/nfd-kernel-config.<option name>

Currently, only bool and tristate (i.e. '=y' or '=m') kernel config
options are supported. Other kconfig types (e.g. string or int) are
simply ignored. If the kconfig flag is set to '=y' or '=m', the
corresponding node label will be present and it's value will be 'true'.
2018-12-04 09:34:56 +02:00
Markus Lehtonen
86947fc16b Implement kernel version detection
Add a new 'kernel' feature source, detecting the kernel version. The
kernel version is split into multiple labels in order to make this more
usable in label selectors. Kernel version in the format X.Y.Z-patch will
be presented as
  node.alpha.kubernetes-incubator.io/nfd-kernel-version.full=X.Y.Z-patch
  node.alpha.kubernetes-incubator.io/nfd-kernel-version.major=X
  node.alpha.kubernetes-incubator.io/nfd-kernel-version.minor=Y
  node.alpha.kubernetes-incubator.io/nfd-kernel-version.revision=Z

The '.full' label will always be avaiable. The other labels if these
components can be parsed from the kernel version number.
2018-10-10 13:21:49 +03:00