@@ -11,12 +11,10 @@ import (
1111 . "github.com/Azure/azure-service-operator/v2/internal/logging"
1212
1313 "github.com/go-logr/logr"
14- "github.com/rotisserie/eris"
1514
1615 "github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
1716 "github.com/Azure/azure-service-operator/v2/internal/resolver"
1817 "github.com/Azure/azure-service-operator/v2/pkg/genruntime"
19- "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
2018)
2119
2220// PreReconciliationChecker is implemented by resources that want to do extra checks before proceeding with
@@ -28,6 +26,8 @@ type PreReconciliationChecker interface {
2826 // Returns BlockReconcile and a human-readable reason if the reconciliation should be skipped.
2927 // ctx is the current operation context.
3028 // obj is the resource about to be reconciled. The resource's State will be freshly updated.
29+ // owner is the owner of the resource about to be reconciled. The owner's State will be freshly updated. May be nil
30+ // if the resource has no owner, or if it has been referenced via ARMID directly.
3131 // kubeClient allows access to the cluster for any required queries.
3232 // armClient allows access to ARM for any required queries.
3333 // log is the logger for the current operation.
@@ -52,72 +52,6 @@ type PreReconcileCheckFunc func(
5252 log logr.Logger ,
5353) (PreReconcileCheckResult , error )
5454
55- type PreReconcileCheckResult struct {
56- action preReconcileCheckResultType
57- severity conditions.ConditionSeverity
58- reason conditions.Reason
59- message string
60- }
61-
62- // ProceedWithReconcile indicates that a resource is ready for reconciliation by returning a PreReconcileCheckResult
63- // with action `Proceed`.
64- func ProceedWithReconcile () PreReconcileCheckResult {
65- return PreReconcileCheckResult {
66- action : preReconcileCheckResultTypeProceed ,
67- }
68- }
69-
70- // BlockReconcile indicates reconciliation of a resource is currently blocked by returning a PreReconcileCheckResult
71- // with action `Block`. The reconciliation will automatically be retried after a short delay.
72- // reason is an explanatory reason to show to the user via a warning condition on the resource.
73- func BlockReconcile (reason string ) PreReconcileCheckResult {
74- return PreReconcileCheckResult {
75- action : preReconcileCheckResultTypeBlock ,
76- severity : conditions .ConditionSeverityWarning ,
77- reason : conditions .ReasonReconcileBlocked ,
78- message : reason ,
79- }
80- }
81-
82- // PostponeReconcile indicates reconciliation of a resource is not currently required by returning a
83- // PreReconcileCheckResult with action `Postpone`. Reconciliation will not be retried until the usual scheduled check.
84- func PostponeReconcile () PreReconcileCheckResult {
85- return PreReconcileCheckResult {
86- action : preReconcileCheckResultTypePostpone ,
87- severity : conditions .ConditionSeverityInfo ,
88- reason : conditions .ReasonReconcilePostponed ,
89- }
90- }
91-
92- func (r PreReconcileCheckResult ) PostponeReconciliation () bool {
93- return r .action == preReconcileCheckResultTypePostpone
94- }
95-
96- func (r PreReconcileCheckResult ) BlockReconciliation () bool {
97- return r .action == preReconcileCheckResultTypeBlock
98- }
99-
100- func (r PreReconcileCheckResult ) Message () string {
101- return r .message
102- }
103-
104- // CreateConditionError returns an error that can be used to set a condition on the resource.
105- func (r PreReconcileCheckResult ) CreateConditionError () error {
106- return conditions .NewReadyConditionImpactingError (
107- eris .New (r .message ),
108- r .severity ,
109- r .reason )
110- }
111-
112- // PreReconcileCheckResultType is the type of result returned by PreReconcileCheck.
113- type preReconcileCheckResultType string
114-
115- const (
116- preReconcileCheckResultTypeBlock preReconcileCheckResultType = "Block"
117- preReconcileCheckResultTypeProceed preReconcileCheckResultType = "Proceed"
118- preReconcileCheckResultTypePostpone preReconcileCheckResultType = "Postpone"
119- )
120-
12155// CreatePreReconciliationChecker creates a checker that can be used to check if a resource is ready for reconciliation.
12256// If the resource in question has not implemented the PreReconciliationChecker interface, the provided default checker
12357// is returned directly.
@@ -128,7 +62,7 @@ func CreatePreReconciliationChecker(
12862) (PreReconcileCheckFunc , bool ) {
12963 impl , ok := host .(PreReconciliationChecker )
13064 if ! ok {
131- return alwaysReconcile , false
65+ return preReconciliationCheckerAlways , false
13266 }
13367
13468 return func (
@@ -141,7 +75,7 @@ func CreatePreReconciliationChecker(
14175 ) (PreReconcileCheckResult , error ) {
14276 log .V (Status ).Info ("Extension pre-reconcile check running" )
14377
144- result , err := impl .PreReconcileCheck (ctx , obj , owner , resourceResolver , armClient , log , alwaysReconcile )
78+ result , err := impl .PreReconcileCheck (ctx , obj , owner , resourceResolver , armClient , log , preReconciliationCheckerAlways )
14579 if err != nil {
14680 log .V (Status ).Info (
14781 "Extension pre-reconcile check failed" ,
@@ -160,10 +94,10 @@ func CreatePreReconciliationChecker(
16094 }, true
16195}
16296
163- // alwaysReconcile is a PreReconciliationChecker that always indicates a reconciliation is required.
97+ // preReconciliationCheckerAlways is a PreReconciliationChecker that always indicates a reconciliation is required.
16498// We have this here so we can set up a chain, even if it's only one link long.
16599// When we start doing proper comparisons between Spec and Status, we'll have an actual chain of checkers.
166- func alwaysReconcile (
100+ func preReconciliationCheckerAlways (
167101 _ context.Context ,
168102 _ genruntime.MetaObject ,
169103 _ genruntime.MetaObject ,
0 commit comments