Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized EventRecorder Instances in Controller Factory Methods #1420

Closed
sundegan opened this issue Mar 16, 2024 · 0 comments
Closed

Uninitialized EventRecorder Instances in Controller Factory Methods #1420

sundegan opened this issue Mar 16, 2024 · 0 comments

Comments

@sundegan
Copy link
Contributor

sundegan commented Mar 16, 2024

[Description]
I've observed that in the pkg/apiserver/manager/manager.go file, instances of EventRecorder are declared for various controller factory methods but are not properly initialized. Although the current codebase does not actively use these EventRecorder instances, if any future modifications attempt to use them, this could lead to runtime panic due to nil pointer dereference. This uninitialized usage poses a risk for potential runtime errors, which could affect the stability of the application.

[Steps to Reproduce]
Currently, this issue does not manifest in runtime errors because the EventRecorder instances are not actively used. However, the issue can be conceptualized through the following steps:

Navigate to pkg/apiserver/manager/manager.go .
Review the controller factory methods such as VolumeController(), where EventRecorder is declared but not initialized.
Imagine a scenario where a future code update involves using these EventRecorder instances to log events.

[Possible Fix]
All instances of EventRecorder should be properly initialized within each controller factory method before being passed to the respective controller constructors.For example:

func (m *ServerManager) VolumeController() *hwameistorctr.LocalVolumeController {
    var recorder record.EventRecorder
    if m.lvController == nil {
        recorder = m.mgr.GetEventRecorderFor("apiserver-local-volume-controller")
        m.lvController = hwameistorctr.NewLocalVolumeController(m.mgr.GetClient(), recorder)
    }
    return m.lvController
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants