Improve operator and auto-discovery log consistency and switch to json logs #3227
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Description
The operator and k8s auto-discovery have included leader election logs in a conflicting format on startup for a while.
e.g.
In addtion a lot of logs of the operator are more on the debug side, and don't have log levels set.
This sets log verbosity levels for those or adds additional context (names, namespaces) e.g. when serviceaccount, roles, rolebindings or jobs are created.
Example of this spam:
2025-08-20T19:20:05Z INFO controllers.execution.Scan Matching ScanType Found {"scan_init": "integration-tests/nmap-localhost-5dqvw", "ScanType": "nmap"} 2025-08-20T19:20:05Z INFO controllers.execution.Scan Service Account doesn't exist creating now 2025-08-20T19:20:05Z INFO controllers.execution.Scan Role doesn't exist creating now 2025-08-20T19:20:05Z INFO controllers.execution.Scan RoleBinding doesn't exist creating now 2025-08-20T19:20:05Z INFO controllers.execution.Scan Using Lurker Image {"seccompProfile": "RuntimeDefault"} 2025-08-20T19:20:05Z INFO controllers.execution.Scan Configuring customCACerts for lurker {"customCACertificate": "", "isConfigured": false} 2025-08-20T19:20:10Z INFO controllers.execution.Scan Matching ParseDefinition Found {"scan_parse": "integration-tests/nmap-localhost-5dqvw", "ParseDefinition": "nmap-xml"} 2025-08-20T19:20:10Z INFO controllers.execution.Scan Service Account doesn't exist creating now 2025-08-20T19:20:10Z INFO controllers.execution.Scan Role doesn't exist creating now 2025-08-20T19:20:10Z INFO controllers.execution.Scan RoleBinding doesn't exist creating now 2025-08-20T19:20:15Z INFO controllers.execution.Scan Found ScanCompletionHooks {"ScanCompletionHooks": 0} 2025-08-20T19:20:17Z INFO controllers.execution.Scan Matching ScanType Found {"scan_init": "integration-tests/nmap-localhost-f8rm5", "ScanType": "nmap"} 2025-08-20T19:20:17Z INFO controllers.execution.Scan Using Lurker Image {"seccompProfile": "RuntimeDefault"} 2025-08-20T19:20:17Z INFO controllers.execution.Scan Configuring customCACerts for lurker {"customCACertificate": "", "isConfigured": false}Afterwards:
{"level":"info","ts":"2025-08-20T19:37:39Z","logger":"controllers.execution.Scan","msg":"Creating missing service account","serviceAccountName":"lurker","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:39Z","logger":"controllers.execution.Scan","msg":"Creating missing Role","roleName":"lurker","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:39Z","logger":"controllers.execution.Scan","msg":"Creating missing RoleBinding","roleName":"lurker","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:39Z","logger":"controllers.execution.Scan","msg":"Creating scan job","scan_init":"integration-tests/nmap-localhost-b6k9h","job":"","scanType":"nmap","scan":"nmap-localhost-b6k9h","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:44Z","logger":"controllers.execution.Scan","msg":"Creating missing service account","serviceAccountName":"parser","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:44Z","logger":"controllers.execution.Scan","msg":"Creating missing Role","roleName":"parser","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:44Z","logger":"controllers.execution.Scan","msg":"Creating missing RoleBinding","roleName":"parser","namespace":"integration-tests"} {"level":"info","ts":"2025-08-20T19:37:44Z","logger":"controllers.execution.Scan","msg":"Creating parse job","scan_parse":"integration-tests/nmap-localhost-b6k9h","job":"","parseDefinition":"nmap-xml","scan":"nmap-localhost-b6k9h","namespace":"integration-tests"}Checklist