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

Inconsistent code-styles and potential nil-dereferences #173

Closed
dholbach opened this issue Oct 27, 2021 · 3 comments
Closed

Inconsistent code-styles and potential nil-dereferences #173

dholbach opened this issue Oct 27, 2021 · 3 comments

Comments

@dholbach
Copy link
Member

From Ada Logics

Flux is composed of projects across different repositories and there is often similar logic happening across the controllers but performed in quite different ways. This leads to a more complex overall codebase and can make it difficult to reason about properties of the code.

Event recording and checking status of similar elements in the controllers is performed differently. This came up as an issue through fuzzing. Each of the controllers rely on an EventRecoder, and the way these EventRecorder variables are used differs between the controllers. Some controllers check for nil-status and others do not. The HelmRelease reconciler and the Kustomization reconciler assume that the EventRecorder is not nil in their respective event() implementations, whereas the other controls do not:

Helm Release Reconciler

https://github.com/fluxcd/helm-controller/blob/e9d31e9f1f8df5149b10ce7719b2d272f617a44f/controllers/helmrelease_controller.go#L739-L745

Kustomize Reconciler

https://github.com/fluxcd/kustomize-controller/blob/72bc54477aa89aadc40d1444d0f30b1e9963806f/controllers/kustomization_controller.go#L788-L795

Image Update Automation Reconciler

https://github.com/fluxcd/image-automation-controller/blob/bc3d7b21121851ffe75ebb9c9dcd530c38db3d4e/controllers/imageupdateautomation_controller.go#L717-L720

Git Repository Reconciler

https://github.com/fluxcd/source-controller/blob/c4d7e46b90dc48aac7d5c74def2a82e7b7ea9333/controllers/gitrepository_controller.go#L427-L432

Recommendation
The same code pattern should be used across the controllers. Through our analysis we determined the EventRecorder cannot be nil using the current main.go files and thus the nil check should be removed.

@pjbgf
Copy link
Member

pjbgf commented Dec 22, 2021

The two open PRs should align the way controllers deal with EventRecorder properties. The approach taken was to add nil checks at both helm and kustomize controllers. The reason being:

  • The majority of the controllers are checking for nil.
  • The kuberecorder.EventRecorder is an interface, which can be nil.
  • The controllers are public, and can therefore be used outside the project and initialised in different ways.

@pjbgf
Copy link
Member

pjbgf commented Jan 4, 2022

@dholbach I believe this can be moved to done.

@pjbgf
Copy link
Member

pjbgf commented Jan 25, 2022

@dholbach should we also close this issue given that the work has concluded?

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

3 participants