mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
feat: support builtin kernel mods
This PR adds the combination of dynamic and builtin kernel modules into one feature called `kernel.enabledmodule`. It's a superset of the `kernel.loadedmodule` feature. Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
parent
adea670ded
commit
109caa1f28
7 changed files with 67 additions and 6 deletions
|
@ -13,6 +13,9 @@
|
|||
- name: host-usr-lib
|
||||
hostPath:
|
||||
path: "/usr/lib"
|
||||
- name: host-lib
|
||||
hostPath:
|
||||
path: "/lib"
|
||||
- name: source-d
|
||||
hostPath:
|
||||
path: "/etc/kubernetes/node-feature-discovery/source.d/"
|
||||
|
@ -38,6 +41,9 @@
|
|||
- name: host-usr-lib
|
||||
mountPath: "/host-usr/lib"
|
||||
readOnly: true
|
||||
- name: host-lib
|
||||
mountPath: "/host-lib"
|
||||
readOnly: true
|
||||
- name: source-d
|
||||
mountPath: "/etc/kubernetes/node-feature-discovery/source.d/"
|
||||
readOnly: true
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
- name: host-usr-lib
|
||||
hostPath:
|
||||
path: "/usr/lib"
|
||||
- name: host-lib
|
||||
hostPath:
|
||||
path: "/lib"
|
||||
- name: source-d
|
||||
hostPath:
|
||||
path: "/etc/kubernetes/node-feature-discovery/source.d/"
|
||||
|
@ -38,6 +41,9 @@
|
|||
- name: host-usr-lib
|
||||
mountPath: "/host-usr/lib"
|
||||
readOnly: true
|
||||
- name: host-lib
|
||||
mountPath: "/host-lib"
|
||||
readOnly: true
|
||||
- name: source-d
|
||||
mountPath: "/etc/kubernetes/node-feature-discovery/source.d/"
|
||||
readOnly: true
|
||||
|
|
|
@ -67,6 +67,9 @@ spec:
|
|||
- name: host-usr-lib
|
||||
mountPath: "/host-usr/lib"
|
||||
readOnly: true
|
||||
- name: host-lib
|
||||
mountPath: "/host-lib"
|
||||
readOnly: true
|
||||
{{- if .Values.worker.mountUsrSrc }}
|
||||
- name: host-usr-src
|
||||
mountPath: "/host-usr/src"
|
||||
|
@ -99,6 +102,9 @@ spec:
|
|||
- name: host-usr-lib
|
||||
hostPath:
|
||||
path: "/usr/lib"
|
||||
- name: host-lib
|
||||
hostPath:
|
||||
path: "/lib"
|
||||
{{- if .Values.worker.mountUsrSrc }}
|
||||
- name: host-usr-src
|
||||
hostPath:
|
||||
|
|
|
@ -619,7 +619,8 @@ The following features are available for matching:
|
|||
| | | **`nx_gzip`** | bool | Nest Accelerator GZIP support is enabled
|
||||
| **`kernel.config`** | attribute | | | Kernel configuration options
|
||||
| | | **`<config-flag>`** | string | Value of the kconfig option
|
||||
| **`kernel.loadedmodule`** | flag | | | Loaded kernel modules
|
||||
| **`kernel.loadedmodule`** | flag | | | Kernel modules loaded on the node as reported by `/proc/modules`
|
||||
| **`kernel.enabledmodule`** | flag | | | Kernel modules loaded on the node and available as built-ins as reported by `modules.builtin`
|
||||
| | | **`mod-name`** | | Kernel module `<mod-name>` is loaded
|
||||
| **`kernel.selinux`** | attribute | | | Kernel SELinux related features
|
||||
| | | **`enabled`** | bool | `true` if SELinux has been enabled and is in enforcing mode, otherwise `false`
|
||||
|
|
|
@ -32,6 +32,8 @@ var (
|
|||
UsrDir = HostDir(pathPrefix + "usr")
|
||||
// VarDir is where the /var directory of the system to be inspected is located
|
||||
VarDir = HostDir(pathPrefix + "var")
|
||||
// LibDir is where the /lib directory of the system to be inspected is located
|
||||
LibDir = HostDir(pathPrefix + "lib")
|
||||
)
|
||||
|
||||
// HostDir is a helper for handling host system directories
|
||||
|
|
|
@ -30,10 +30,11 @@ import (
|
|||
const Name = "kernel"
|
||||
|
||||
const (
|
||||
ConfigFeature = "config"
|
||||
LoadedModuleFeature = "loadedmodule"
|
||||
SelinuxFeature = "selinux"
|
||||
VersionFeature = "version"
|
||||
ConfigFeature = "config"
|
||||
LoadedModuleFeature = "loadedmodule"
|
||||
SelinuxFeature = "selinux"
|
||||
VersionFeature = "version"
|
||||
EnabledModuleFeature = "enabledmodule"
|
||||
)
|
||||
|
||||
// Configuration file options
|
||||
|
@ -135,12 +136,21 @@ func (s *kernelSource) Discover() error {
|
|||
s.legacyKconfig = legacyKconfig
|
||||
}
|
||||
|
||||
var enabledModules []string
|
||||
if kmods, err := getLoadedModules(); err != nil {
|
||||
klog.Errorf("failed to get loaded kernel modules: %v", err)
|
||||
} else {
|
||||
enabledModules = append(enabledModules, kmods...)
|
||||
s.features.Flags[LoadedModuleFeature] = nfdv1alpha1.NewFlagFeatures(kmods...)
|
||||
}
|
||||
|
||||
if builtinMods, err := getBuiltinModules(); err != nil {
|
||||
klog.Errorf("failed to get builtin kernel modules: %v", err)
|
||||
} else {
|
||||
enabledModules = append(enabledModules, builtinMods...)
|
||||
s.features.Flags[EnabledModuleFeature] = nfdv1alpha1.NewFlagFeatures(enabledModules...)
|
||||
}
|
||||
|
||||
if selinux, err := SelinuxEnabled(); err != nil {
|
||||
klog.Warning(err)
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,10 @@ package kernel
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath"
|
||||
)
|
||||
|
||||
const kmodProcfsPath = "/proc/modules"
|
||||
|
@ -31,7 +34,7 @@ func getLoadedModules() ([]string, error) {
|
|||
}
|
||||
|
||||
lines := strings.Split(string(out), "\n")
|
||||
loadedMods := make([]string, len(lines))
|
||||
loadedMods := make([]string, 0, len(lines))
|
||||
for _, line := range lines {
|
||||
// skip empty lines
|
||||
if len(line) == 0 {
|
||||
|
@ -42,3 +45,30 @@ func getLoadedModules() ([]string, error) {
|
|||
}
|
||||
return loadedMods, nil
|
||||
}
|
||||
|
||||
func getBuiltinModules() ([]string, error) {
|
||||
kVersion, err := getVersion()
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
kBuiltinModPath := hostpath.LibDir.Path("modules/" + kVersion + "/modules.builtin")
|
||||
out, err := os.ReadFile(kBuiltinModPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read file %s: %s", kBuiltinModPath, err.Error())
|
||||
}
|
||||
|
||||
lines := strings.Split(string(out), "\n")
|
||||
builtinMods := make([]string, 0, len(lines))
|
||||
for _, line := range lines {
|
||||
// skip empty lines
|
||||
line = strings.TrimSpace(line)
|
||||
if !strings.HasSuffix(line, ".ko") {
|
||||
continue
|
||||
}
|
||||
|
||||
// append loaded module
|
||||
builtinMods = append(builtinMods, strings.TrimSuffix(path.Base(line), ".ko"))
|
||||
}
|
||||
return builtinMods, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue