Remove panic from GetScanType/GetScannerType methods - #1337
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sebrandon1 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @sebrandon1. Thanks for your PR. I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Replace panic-prone wrapper methods with direct error handling: - Removed GetScanType() and GetScannerType() that panicked on invalid input - Updated getTargetNodes() to use GetScanTypeIfValid() with explicit error handling - Replaced strings.ToLower comparisons with strings.EqualFold for consistency - Added comprehensive test coverage (14 test cases) for scan type validation This eliminates operator crash risk if validation is bypassed while following existing error handling patterns in the controller. Fixes identified in brainstorm session as high-impact quick win.
0a551fa to
81388ec
Compare
Summary
GetScanType()andGetScannerType()wrapper functions with direct error handlingstrings.EqualFold()instead of doubleToLower()Changes
GetScanType()andGetScannerType()methods fromcompliancescan_types.gogetTargetNodes()inscantype.goto callGetScanTypeIfValid()with explicit error handlingstrings.ToLower()comparisons withstrings.EqualFold()for consistency with existing codebasecompliancescan_types_test.gowith validation test casesWhy This Matters
The removed methods called
GetScanTypeIfValid()internally but panicked on invalid input. While the controller validates scan types before this code executes, the panic created a defensive failure mode that could crash the entire operator pod if validation was somehow bypassed.This change:
Test Plan
Files Changed
Performance Impact
EqualFoldvs double allocation inToLower)