Skip to content

Commit a8283f5

Browse files
Add sdk addon hook (#94)
Issue #, if available: Ability for service controllers to add code (additional functions, variables etc as needed) to sdk.go file using hooks as extension mechanism. Description of changes: This PR adds `sdk_addon` hook to `sdk.go.tpl`. Using this hook, service controllers can append code to a custom resource's `sdk.go` file. It will help in placing reusable code/functions which are generated dynamically using hook templates. Following PR contains changes showcasing how this facility helps service controllers auto generate reusable code: aws-controllers-k8s/elasticache-controller#36 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent c77aa9c commit a8283f5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/generate/ack/hook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ code paths:
5656
* sdk_get_attributes_post_set_output
5757
* sdk_create_post_set_output
5858
* sdk_update_post_set_output
59+
* sdk_file_end
5960
* delta_pre_compare
6061
* delta_post_compare
6162
@@ -91,6 +92,10 @@ is merged with the copy of the original Kubernetes object. These hooks will
9192
have access to the updated Kubernetes object `ko`, the response of the API call
9293
(and the original Kubernetes CR object if its sdkUpdate)
9394
95+
The "sdk_file_end" is a generic hook point that occurs outside the scope of any
96+
specific AWSResourceManager method and can be used to place commonly-generated
97+
code inside the sdk.go file
98+
9499
The "delta_pre_compare" hooks are called BEFORE the generated code that
95100
compares two resources.
96101

templates/pkg/resource/sdk.go.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,6 @@ func (rm *resourceManager) handleImmutableFieldsChangedCondition(
362362
return &resource{ko}
363363
}
364364
{{- end }}
365+
{{- if $hookCode := Hook .CRD "sdk_file_end" }}
366+
{{ $hookCode }}
367+
{{- end }}

0 commit comments

Comments
 (0)