bug: nil pointer dereference in Flux plugin when NumProcPerNode is unset
- Dominant language
- Go
- Stars
- 2.2k
- Forks
- 1.1k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 39
Description
## What happened?
`generateFluxEntrypoint` in `pkg/runtime/framework/plugins/flux/flux.go` unconditionally dereferences `info.RuntimePolicy.MLPolicySource.Flux.NumProcPerNode` without a nil check.
The field has a `+kubebuilder:default=1` CRD schema default, but that default is only applied by the API server when the object is admitted. Objects constructed directly in code (unit tests, or a runtime snapshot loaded before the default existed) may have this field unset, causing a nil pointer dereference panic in `generateFluxEntrypoint`.
## Affected code
`pkg/runtime/framework/plugins/flux/flux.go`, inside `generateFluxEntrypoint`:
```go
// before fix — panics if NumProcPerNode is nil
tasks = *info.RuntimePolicy.MLPolicySource.Flux.NumProcPerNode
```
## What should happen?
The code should fall back to the documented default of 1 when the field is nil, matching the field's own CRD schema intent:
```go
tasks = ptr.Deref(info.RuntimePolicy.MLPolicySource.Flux.NumProcPerNode, 1)
```
## How to reproduce
Run the new regression test added in the accompanying PR with the fix temporarily reverted — it panics with a nil dereference inside `buildInitScriptConfigMap`.
## Why existing tests did not catch it
All existing test cases in `TestOptionalTrainerFields` hardcoded `NumProcPerNode: ptr.To[int32](1)` in the runtime fixture, so the nil path was never exercised.
Note: This contribution was developed with AI assistance (Claude), in accordance with the Kubeflow AI Policy.
Contributor guide
Research direction
Start in pkg/runtime/framework/plugins/flux/flux.go at generateFluxEntrypoint, then inspect TestOptionalTrainerFields and run the Flux plugin package tests. Done means a runtime policy with NumProcPerNode unset no longer panics and uses the documented default of 1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- backend, machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100