Skip to content

Conversation

kumargauravsharma
Copy link
Contributor

@kumargauravsharma kumargauravsharma commented Jun 17, 2021

Issue #, aws-controllers-k8s/community#838

Description of changes:
This PR enables support for crd variables and controller functions and hooks within hook templates.
The hook templates insides the service controllers can be similar to the templates that are inside code-generator.

For example, following hook template refers .CRD variable, invokes controller function GoCodeSetCreateOutput and has its own extension hook sdk_addon_set_output_post_populate:
and it can be used as hook inside generator.yaml for a resource:

{{ $outputShape := .CRD.GetOutputShape .CRD.Ops.Create }}
// This method copies the data from given {{ $outputShape.ShapeName }} by populating it
// into copy of supplied resource and returns that.
func (rm *resourceManager) set{{ $outputShape.ShapeName }}Output (
    r *resource,
    obj *svcsdk.{{ $outputShape.ShapeName }},
) (*resource, error) {
	if obj == nil ||
		r == nil ||
		r.ko == nil {
		return nil, nil
	}
	resp := &svcsdk.{{ .CRD.Ops.Create.OutputRef.Shape.ShapeName }}{ {{ $outputShape.ShapeName }}:obj }
	// Merge in the information we read from the API call above to the copy of
    // the original Kubernetes object we passed to the function
    ko := r.ko.DeepCopy()
{{ $createCode := GoCodeSetCreateOutput .CRD "resp" "ko" 1 true }}
{{ $createCode }}
	rm.setStatusDefaults(ko)
{{- if $hookCode := Hook .CRD "sdk_addon_set_output_post_populate" }}
{{ $hookCode }}
{{- end }}
    return &resource{ko}, nil
}

Testing:
make test passed for code-generator

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kumargauravsharma
Copy link
Contributor Author

Related PR: aws-controllers-k8s/elasticache-controller#36 where dynamic hook template is used to auto generate reusable setOutput method.

@a-hilaly
Copy link
Member

Nice!
/approve

@kumargauravsharma
Copy link
Contributor Author

Could this PR be merged?

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jaypipes
Copy link
Collaborator

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 21, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Jun 21, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, kumargauravsharma

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@a-hilaly
Copy link
Member

/ok-to-test

@ack-bot ack-bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jun 22, 2021
@ack-bot ack-bot merged commit 85436ab into aws-controllers-k8s:main Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants