You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Status handling in the APIRule controller is one of the problematic pain points during code maintenance. APIRule Controller uses type ReconciliationStatus interface. This iface is then implemented by two structures ReconciliationV2alpha1Status and ReconciliationV1beta1Status.
To access the status function GetStatusBase(string) has to be used. Usually, code uses this function by providing the bogus string value as an argument, eg. s := cmd.GetStatusBase(string(gatewayv1beta1.StatusSkipped)), then we actually modify status using different interface function, eg. s.GenerateStatusFromFailures(failures)
Then to update the actual status of APIRule, we use err := s.UpdateStatus(&apiRule.Status) function.
Additionally in the code there is another interface that also manages statuses under controllers/status.go. This interface also defines two functions that operate on structures that operate on ReconciliationStatus iface. Not only that, but it also breaks the recommendation of Golang coding practices by defining the interface along with the implementation.
Another problematic implementation is function GetStatusForErrorMap which accepts a map of ResourceSelectors defined in internal/processing/status/status.go. I understand that this function is meant to aggregate the APIRule validation failures, but in the end it doesn't give proper access to aggregated errors, which resulted in a need to introduce small aggregation function #1490.
With the recommendations from the Golang team about the interfaces, and to make a foundation for new reconciliation for APIRule V2, I would like to propose some changes into how to handle the APIRule status.
Proposals
Reduce number of interfaces
Let's take an example of internal/validation/v1beta1/v1beta1.go. The APIRuleValidator uses 3 interfaces accessStrategyValidatormutatorValidator and rulesValidator.
Those interfaces are implemented by a single structure. We should not define interfaces if we do not plan on extending them.
Implement errors in Validation handling
Current implementation of Validation makes it hard follow during debugging. The chain for validation goes like this:
Reconciliation.Validate -> APIRuleValidator.Validate -> v1beta1/v2alpha1.Validate.
Each of the validations should return a custom error implementation. Example:
Implement ValidationError structure that implements error interface
Status handling in the APIRule controller is one of the problematic pain points during code maintenance. APIRule Controller uses
type ReconciliationStatus interface
. This iface is then implemented by two structuresReconciliationV2alpha1Status
andReconciliationV1beta1Status
.To access the status function
GetStatusBase(string)
has to be used. Usually, code uses this function by providing the bogus string value as an argument, eg.s := cmd.GetStatusBase(string(gatewayv1beta1.StatusSkipped))
, then we actually modify status using different interface function, eg.s.GenerateStatusFromFailures(failures)
api-gateway/controllers/gateway/apirule_controller.go
Lines 147 to 148 in 5690117
Then to update the actual status of APIRule, we use
err := s.UpdateStatus(&apiRule.Status)
function.Additionally in the code there is another interface that also manages statuses under
controllers/status.go
. This interface also defines two functions that operate on structures that operate onReconciliationStatus
iface. Not only that, but it also breaks the recommendation of Golang coding practices by defining the interface along with the implementation.Another problematic implementation is function
GetStatusForErrorMap
which accepts a map ofResourceSelectors
defined ininternal/processing/status/status.go
. I understand that this function is meant to aggregate the APIRule validation failures, but in the end it doesn't give proper access to aggregated errors, which resulted in a need to introduce small aggregation function #1490.With the recommendations from the Golang team about the interfaces, and to make a foundation for new reconciliation for APIRule V2, I would like to propose some changes into how to handle the APIRule status.
Proposals
Reduce number of interfaces
Let's take an example of
internal/validation/v1beta1/v1beta1.go
. TheAPIRuleValidator
uses 3 interfacesaccessStrategyValidator
mutatorValidator
andrulesValidator
.Those interfaces are implemented by a single structure. We should not define interfaces if we do not plan on extending them.
Implement errors in Validation handling
Current implementation of Validation makes it hard follow during debugging. The chain for validation goes like this:
Reconciliation.Validate -> APIRuleValidator.Validate -> v1beta1/v2alpha1.Validate.
Each of the validations should return a custom
error
implementation. Example:error
interfaceThen, instead of returning
Failure
, we can returnerror
, and treat it like usual error.If we need to aggregate errors, we should use apimachinery
errors.Aggregate
interface andNewAggregate()
function.TODOs (subject of change)
ReconciliationStatus
and remove if deemed unnecessaryGetStatusBase
from ReconciliationCommands and implement proper constructor forStatus
handlerResourceSelector
and replace it with separate errors for each of the resourcevalidation.Failure{}
with error interface implementationThe text was updated successfully, but these errors were encountered: