Skip to content

Commit 58a0129

Browse files
authored
Resolve references hooks (#294)
Issue #, if available: aws-controllers-k8s/community#1180 Description of changes: * This patch adds support for two custom hooks "pre_resolve_references" and "post_resolve_references" * These hooks are needed to support TargetRef inside APIGatewayv2 Route resource where "integrations/" prefix is added before the referred IntegrationID. * This patch also sets ResourceSynced condition to false when LateInitialization fails. This will help remove custom ResourceSynced condition handling inside `reconciler.go` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent ce5dc75 commit 58a0129

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pkg/generate/ack/hook.go

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ code paths:
6161
* delta_post_compare
6262
* late_initialize_pre_read_one
6363
* late_initialize_post_read_one
64+
* references_pre_resolve
65+
* references_post_resolve
6466
6567
The "pre_build_request" hooks are called BEFORE the call to construct
6668
the Input shape that is used in the API operation and therefore BEFORE
@@ -110,6 +112,13 @@ readOne call inside AWSResourceManager.LateInitialize() method
110112
The "late_initialize_post_read_one" hooks are called AFTER making the
111113
readOne call inside AWSResourceManager.LateInitialize() method
112114
115+
The "references_pre_resolve" hooks are called BEFORE resolving the
116+
references for all Reference fields inside AWSResourceManager.ResolveReferences()
117+
method
118+
119+
The "references_post_resolve" hooks are called AFTER resolving the
120+
references for all Reference fields inside AWSResourceManager.ResolveReferences()
121+
method
113122
*/
114123

115124
// ResourceHookCode returns a string with custom callback code for a resource

templates/pkg/resource/manager.go.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (rm *resourceManager) LateInitialize(
201201
lateInitConditionMessage = "Unable to complete Read operation required for late initialization"
202202
lateInitConditionReason = "Late Initialization Failure"
203203
ackcondition.SetLateInitialized(latestCopy, corev1.ConditionFalse, &lateInitConditionMessage, &lateInitConditionReason)
204+
ackcondition.SetSynced(latestCopy, corev1.ConditionFalse, nil, nil)
204205
return latestCopy, err
205206
}
206207
{{- if $hookCode := Hook .CRD "late_initialize_post_read_one" }}
@@ -213,6 +214,7 @@ func (rm *resourceManager) LateInitialize(
213214
lateInitConditionMessage = "Late initialization did not complete, requeuing with delay of 5 seconds"
214215
lateInitConditionReason = "Delayed Late Initialization"
215216
ackcondition.SetLateInitialized(lateInitializedRes, corev1.ConditionFalse, &lateInitConditionMessage, &lateInitConditionReason)
217+
ackcondition.SetSynced(lateInitializedRes, corev1.ConditionFalse, nil, nil)
216218
return lateInitializedRes, ackrequeue.NeededAfter(nil, time.Duration(5)*time.Second)
217219
}
218220
// Set LateInitialized condition to True

templates/pkg/resource/references.go.tpl

+6
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ func (rm *resourceManager) ResolveReferences(
5959
namespace := res.MetaObject().GetNamespace()
6060
ko := rm.concreteResource(res).ko.DeepCopy()
6161
err := validateReferenceFields(ko)
62+
{{- if $hookCode := Hook .CRD "references_pre_resolve" }}
63+
{{ $hookCode }}
64+
{{- end }}
6265
{{ range $fieldName, $field := .CRD.Fields -}}
6366
{{ if $field.HasReference -}}
6467
if err == nil {
6568
err = resolveReferenceFor{{ $field.Names.Camel }}(ctx, apiReader, namespace, ko)
6669
}
6770
{{ end -}}
6871
{{ end -}}
72+
{{- if $hookCode := Hook .CRD "references_post_resolve" }}
73+
{{ $hookCode }}
74+
{{- end }}
6975
if hasNonNilReferences(ko) {
7076
return ackcondition.WithReferencesResolvedCondition(&resource{ko}, err)
7177
}

0 commit comments

Comments
 (0)