Skip to content

Commit

Permalink
Fixing panic in case worker pod has failed (#523) (#713)
Browse files Browse the repository at this point in the history
The status of the working pod that has completed with error
does not contain the valid Config field ( it is set only on success).
When processing NMC, the NMC controller tries to compare the Config
of the status and spec, and in that case it fails, since status Config
is nil.
Fix: in case status != nil, inProgress = false and Config is nil, just
create a loader worker pod, without futher comparison to the spec
  • Loading branch information
yevgeny-shnaidman authored Aug 24, 2023
1 parent f93a883 commit ed3e3a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion controllers/nodemodulesconfig_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func (w *workerHelper) ProcessModuleSpec(

if status == nil {
logger.Info("Missing status; creating loader Pod")

return w.pm.CreateLoaderPod(ctx, nmc, spec)
}

Expand All @@ -236,6 +235,11 @@ func (w *workerHelper) ProcessModuleSpec(
return nil
}

if status.Config == nil {
logger.Info("Missing status config and pod is not running: previously failed pod, creating loader Pod")
return w.pm.CreateLoaderPod(ctx, nmc, spec)
}

if !reflect.DeepEqual(spec.Config, *status.Config) {
logger.Info("Outdated config in status; creating unloader Pod")

Expand Down
21 changes: 21 additions & 0 deletions controllers/nodemodulesconfig_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,27 @@ var _ = Describe("workerHelper_ProcessModuleSpec", func() {
)
})

It("should create a loader Pod if inStatus is false, but the Config is not define (nil)", func() {
nmc := &kmmv1beta1.NodeModulesConfig{}
spec := &kmmv1beta1.NodeModuleSpec{
Name: name,
Namespace: namespace,
Config: kmmv1beta1.ModuleConfig{ContainerImage: "old-container-image"},
}

status := &kmmv1beta1.NodeModuleStatus{
Name: name,
Namespace: namespace,
}
pm.EXPECT().CreateLoaderPod(ctx, nmc, spec)

Expect(
wh.ProcessModuleSpec(ctx, &kmmv1beta1.NodeModulesConfig{}, spec, status),
).NotTo(
HaveOccurred(),
)
})

It("should create an unloader Pod if the spec is different from the status", func() {
nmc := &kmmv1beta1.NodeModulesConfig{}

Expand Down

0 comments on commit ed3e3a7

Please sign in to comment.