-
Notifications
You must be signed in to change notification settings - Fork 181
Initial changes for late initializing resource fields. #37
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
Changes from all commits
f505628
9cd907e
1055f3d
8a0cd3c
039d36c
0277100
1f6a4b8
00ef713
2a4ad5c
f075d12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,11 @@ func (r *resourceReconciler) Sync( | |
return latest, err | ||
} | ||
} | ||
// Attempt to late initialize the resource. If there are no fields to | ||
// late initialize, this operation will be a no-op. | ||
if latest, err = r.lateInitializeResource(ctx, rm, latest); err != nil { | ||
return latest, err | ||
} | ||
return r.handleRequeues(ctx, latest) | ||
} | ||
|
||
|
@@ -338,6 +343,43 @@ func (r *resourceReconciler) updateResource( | |
return latest, nil | ||
} | ||
|
||
// lateInitializeResource calls AWSResourceManager.LateInitialize() method and | ||
// returns the AWSResource with late initialized fields. | ||
// | ||
// When the late initialization is delayed for an AWSResource, an error is returned | ||
// with specific requeue delay to attempt lateInitialization again. | ||
// | ||
// This method also adds an annotation to K8s CR, indicating the number of | ||
// late initialization attempts to correctly calculate exponential backoff delay | ||
// | ||
// This method also adds Condition to CR's status indicating status of late initialization. | ||
func (r *resourceReconciler) lateInitializeResource( | ||
ctx context.Context, | ||
rm acktypes.AWSResourceManager, | ||
latest acktypes.AWSResource, | ||
) (acktypes.AWSResource, error) { | ||
var err error | ||
rlog := ackrtlog.FromContext(ctx) | ||
exit := rlog.Trace("r.lateInitializeResource") | ||
defer exit(err) | ||
|
||
rlog.Enter("rm.LateInitialize") | ||
lateInitializedLatest, err := rm.LateInitialize(ctx, latest) | ||
rlog.Exit("rm.LateInitialize", err) | ||
// Always patch after late initialize because some fields may have been initialized while | ||
// others require a retry after some delay. | ||
// This patching does not hurt because if there is no diff then 'patchResourceMetadataAndSpec' | ||
// acts as a no-op. | ||
if ackcompare.IsNotNil(lateInitializedLatest) { | ||
patchErr := r.patchResourceMetadataAndSpec(ctx, latest, lateInitializedLatest) | ||
// Throw the patching error if reconciler is unable to patch the resource with late initializations | ||
if patchErr != nil { | ||
err = patchErr | ||
} | ||
Comment on lines
+375
to
+378
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. We'll be shadowing any non-nil |
||
} | ||
return lateInitializedLatest, err | ||
} | ||
|
||
// patchResourceMetadataAndSpec patches the custom resource in the Kubernetes API to match the | ||
// supplied latest resource's metadata and spec. | ||
func (r *resourceReconciler) patchResourceMetadataAndSpec( | ||
|
Uh oh!
There was an error while loading. Please reload this page.