Skip to content

Commit 4086274

Browse files
Module version nodes' label management (#347)
This PR adds the management of the a module version labels management per node. It is done in a dedicated controller, which listens on the changes of the module version labels on the nodes. Once such a change is detected, the reconciliation flow is as following: 1) get all the module version labels of the node (module version, module_loader version, device-plugin version) 2) sort the labels per their module-name/namespace. Result: slice of structure (one structure per module), that holds the values of module/module-loader/device-lugin labels for that particular module 3) Per each module, based on a static action-table, determine what is the next action should be: none, adding label, deleting label. Per module it will always be only one label that will either be added or deleted 4) Gather all labels to be added/deleted for all the modules and update node in one operation Chnages in code: 1) new controller 2) static action table for that controller 3) adding filter function to trigger the controller only on changes to module version labels 4) mocks and unit-tests
1 parent b55ea5d commit 4086274

10 files changed

+842
-19
lines changed

cmd/manager/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ func main() {
159159
cmd.FatalError(setupLogger, err, "unable to create controller", "name", controllers.PodNodeModuleReconcilerName)
160160
}
161161

162+
if err = controllers.NewNodeLabelModuleVersionReconciler(client).SetupWithManager(mgr); err != nil {
163+
cmd.FatalError(setupLogger, err, "unable to create controller", "name", controllers.NodeLabelModuleVersionReconcilerName)
164+
}
165+
162166
preflightStatusUpdaterAPI := statusupdater.NewPreflightStatusUpdater(client)
163167
preflightAPI := preflight.NewPreflightAPI(client, buildAPI, signAPI, registryAPI, preflightStatusUpdaterAPI, kernelAPI)
164168

controllers/mock_node_label_module_version_reconciler.go

+93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package controllers
2+
3+
import "github.com/kubernetes-sigs/kernel-module-management/internal/utils"
4+
5+
const (
6+
labelMissing = "missing"
7+
labelPresent = "present"
8+
labelDifferent = "different"
9+
10+
addAction = "add"
11+
deleteAction = "delete"
12+
noneAction = "none"
13+
)
14+
15+
type labelActionKey struct {
16+
module string
17+
moduleLoader string
18+
devicePlugin string
19+
}
20+
21+
type labelAction struct {
22+
getLabelName func(string, string) string
23+
action string
24+
}
25+
26+
var labelActionTable = map[labelActionKey]labelAction{
27+
labelActionKey{
28+
module: labelMissing,
29+
moduleLoader: labelMissing,
30+
devicePlugin: labelMissing}: labelAction{getLabelName: nil, action: noneAction},
31+
32+
labelActionKey{
33+
module: labelMissing,
34+
moduleLoader: labelPresent,
35+
devicePlugin: labelPresent}: labelAction{getLabelName: utils.GetDevicePluginVersionLabelName, action: deleteAction},
36+
37+
labelActionKey{
38+
module: labelMissing,
39+
moduleLoader: labelPresent,
40+
devicePlugin: labelMissing}: labelAction{getLabelName: utils.GetModuleLoaderVersionLabelName, action: deleteAction},
41+
42+
labelActionKey{
43+
module: labelPresent,
44+
moduleLoader: labelMissing,
45+
devicePlugin: labelMissing}: labelAction{getLabelName: utils.GetModuleLoaderVersionLabelName, action: addAction},
46+
47+
labelActionKey{
48+
module: labelPresent,
49+
moduleLoader: labelPresent,
50+
devicePlugin: labelMissing}: labelAction{getLabelName: utils.GetDevicePluginVersionLabelName, action: addAction},
51+
52+
labelActionKey{
53+
module: labelPresent,
54+
moduleLoader: labelPresent,
55+
devicePlugin: labelPresent}: labelAction{getLabelName: nil, action: noneAction},
56+
57+
labelActionKey{
58+
module: labelPresent,
59+
moduleLoader: labelDifferent,
60+
devicePlugin: labelDifferent}: labelAction{getLabelName: utils.GetDevicePluginVersionLabelName, action: deleteAction},
61+
62+
labelActionKey{
63+
module: labelPresent,
64+
moduleLoader: labelDifferent,
65+
devicePlugin: labelMissing}: labelAction{getLabelName: utils.GetModuleLoaderVersionLabelName, action: deleteAction},
66+
}

0 commit comments

Comments
 (0)