Skip to content

Commit 4772809

Browse files
committed
BootID support for KMM
1 parent 56eddaf commit 4772809

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

internal/controllers/mock_nmc_reconciler.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controllers/nmc_reconciler.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type NMCReconciler struct {
4949
helper nmcReconcilerHelper
5050
nodeAPI node.Node
5151
podManager pod.WorkerPodManager
52+
bootIDMap map[string]string
5253
}
5354

5455
func NewNMCReconciler(
@@ -66,6 +67,7 @@ func NewNMCReconciler(
6667
helper: helper,
6768
nodeAPI: nodeAPI,
6869
podManager: podManager,
70+
bootIDMap: make(map[string]string),
6971
}
7072
}
7173

@@ -110,6 +112,10 @@ func (r *NMCReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
110112

111113
errs := make([]error, 0, len(nmcObj.Spec.Modules)+len(nmcObj.Status.Modules))
112114
var readyLabelsToRemove []string
115+
prevBootID, exists := r.bootIDMap[nmcObj.Name]
116+
currentBootID := node.Status.NodeInfo.BootID
117+
bootIDChanged := exists && prevBootID != currentBootID
118+
113119
for _, mod := range nmcObj.Spec.Modules {
114120
moduleNameKey := mod.Namespace + "/" + mod.Name
115121

@@ -121,7 +127,7 @@ func (r *NMCReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
121127
delete(statusMap, moduleNameKey)
122128
continue
123129
}
124-
if err := r.helper.ProcessModuleSpec(ctrl.LoggerInto(ctx, logger), &nmcObj, &mod, statusMap[moduleNameKey], &node); err != nil {
130+
if err := r.helper.ProcessModuleSpec(ctrl.LoggerInto(ctx, logger), &nmcObj, &mod, statusMap[moduleNameKey], &node, bootIDChanged); err != nil {
125131
errs = append(
126132
errs,
127133
fmt.Errorf("error processing Module %s: %v", moduleNameKey, err),
@@ -133,6 +139,8 @@ func (r *NMCReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
133139
delete(statusMap, moduleNameKey)
134140
}
135141

142+
r.bootIDMap[nmcObj.Name] = currentBootID
143+
136144
// We have processed all module specs.
137145
// Now, go through the remaining, "orphan" statuses that do not have a corresponding spec; those must be unloaded.
138146

@@ -217,7 +225,7 @@ func GetContainerStatus(statuses []v1.ContainerStatus, name string) v1.Container
217225
type nmcReconcilerHelper interface {
218226
GarbageCollectInUseLabels(ctx context.Context, nmc *kmmv1beta1.NodeModulesConfig) error
219227
GarbageCollectWorkerPods(ctx context.Context, nmc *kmmv1beta1.NodeModulesConfig) error
220-
ProcessModuleSpec(ctx context.Context, nmc *kmmv1beta1.NodeModulesConfig, spec *kmmv1beta1.NodeModuleSpec, status *kmmv1beta1.NodeModuleStatus, node *v1.Node) error
228+
ProcessModuleSpec(ctx context.Context, nmc *kmmv1beta1.NodeModulesConfig, spec *kmmv1beta1.NodeModuleSpec, status *kmmv1beta1.NodeModuleStatus, node *v1.Node, bootIDChanged bool) error
221229
ProcessUnconfiguredModuleStatus(ctx context.Context, nmc *kmmv1beta1.NodeModulesConfig, status *kmmv1beta1.NodeModuleStatus, node *v1.Node) error
222230
RemovePodFinalizers(ctx context.Context, nodeName string) error
223231
SyncStatus(ctx context.Context, nmc *kmmv1beta1.NodeModulesConfig) error
@@ -344,6 +352,7 @@ func (h *nmcReconcilerHelperImpl) ProcessModuleSpec(
344352
spec *kmmv1beta1.NodeModuleSpec,
345353
status *kmmv1beta1.NodeModuleStatus,
346354
node *v1.Node,
355+
bootIDChanged bool,
347356
) error {
348357
podName := pod.WorkerPodName(nmcObj.Name, spec.Name)
349358

@@ -374,7 +383,7 @@ func (h *nmcReconcilerHelperImpl) ProcessModuleSpec(
374383
return h.podManager.CreateLoaderPod(ctx, nmcObj, spec)
375384
}
376385

377-
if h.nodeAPI.NodeBecomeReadyAfter(node, status.LastTransitionTime) {
386+
if bootIDChanged || h.nodeAPI.NodeBecomeReadyAfter(node, status.LastTransitionTime) {
378387
logger.Info("node has been rebooted and become ready after kernel module was loaded; creating loader Pod")
379388
return h.podManager.CreateLoaderPod(ctx, nmcObj, spec)
380389
}

internal/controllers/nmc_reconciler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ var _ = Describe("NodeModulesConfigReconciler_Reconcile", func() {
298298
wh.EXPECT().SyncStatus(ctx, nmc),
299299
kubeClient.EXPECT().Get(ctx, types.NamespacedName{Name: nmc.Name}, &node).Return(nil),
300300
nm.EXPECT().IsNodeSchedulable(&node, nil).Return(true),
301-
wh.EXPECT().ProcessModuleSpec(contextWithValueMatch, nmc, &spec0, &status0, &node),
301+
wh.EXPECT().ProcessModuleSpec(contextWithValueMatch, nmc, &spec0, &status0, &node, false),
302302
nm.EXPECT().IsNodeSchedulable(&node, nil).Return(true),
303-
wh.EXPECT().ProcessModuleSpec(contextWithValueMatch, nmc, &spec1, nil, &node),
303+
wh.EXPECT().ProcessModuleSpec(contextWithValueMatch, nmc, &spec1, nil, &node, false),
304304
wh.EXPECT().ProcessUnconfiguredModuleStatus(contextWithValueMatch, nmc, &status2, &node),
305305
wh.EXPECT().GarbageCollectInUseLabels(ctx, nmc),
306306
wh.EXPECT().GarbageCollectWorkerPods(ctx, nmc),
@@ -380,7 +380,7 @@ var _ = Describe("NodeModulesConfigReconciler_Reconcile", func() {
380380
wh.EXPECT().SyncStatus(ctx, nmc).Return(nil),
381381
kubeClient.EXPECT().Get(ctx, types.NamespacedName{Name: nmc.Name}, &node).Return(nil),
382382
nm.EXPECT().IsNodeSchedulable(&node, nil).Return(true),
383-
wh.EXPECT().ProcessModuleSpec(contextWithValueMatch, nmc, &spec0, &status0, &node).Return(errors.New(errorMeassge)),
383+
wh.EXPECT().ProcessModuleSpec(contextWithValueMatch, nmc, &spec0, &status0, &node, false).Return(errors.New(errorMeassge)),
384384
wh.EXPECT().ProcessUnconfiguredModuleStatus(contextWithValueMatch, nmc, &status2, &node).Return(errors.New(errorMeassge)),
385385
wh.EXPECT().GarbageCollectInUseLabels(ctx, nmc).Return(errors.New(errorMeassge)),
386386
wh.EXPECT().GarbageCollectWorkerPods(ctx, nmc).Return(errors.New(errorMeassge)),

0 commit comments

Comments
 (0)