Skip to content

[DEMO, do not merge] Generated EnsureReferences output for code-generator#738 - #242

Draft
gustavodiaz7722 wants to merge 1 commit into
aws-controllers-k8s:mainfrom
gustavodiaz7722:demo/ensure-references-generated-output
Draft

[DEMO, do not merge] Generated EnsureReferences output for code-generator#738#242
gustavodiaz7722 wants to merge 1 commit into
aws-controllers-k8s:mainfrom
gustavodiaz7722:demo/ensure-references-generated-output

Conversation

@gustavodiaz7722

Copy link
Copy Markdown
Member

Demonstration only — not for merge.

Opened at the request of a reviewer on aws-controllers-k8s/code-generator#738, to show what that PR emits in the context of a full service controller.

lambda-controller regenerated against code-generator#738 with no other change, so the diff is exactly the generated EnsureReferences methods and nothing else. Local build stamps (pkg/version/version.go, ack-generate-metadata.yaml) were reverted deliberately, since they would otherwise show a spurious generator downgrade.

Why lambda

It exercises all three reference shapes, so the per-shape behaviour is visible in one controller:

Resource Shape Emitted
function struct-nested — Code.S3BucketRef, VPCConfig.SecurityGroupRefs, VPCConfig.SubnetRefs yes
layer_version struct-nested yes
event_source_mapping list-nested no
alias, code_signing_config, function_url_config, version top-level only no

function is the shape reported in aws-controllers-k8s/community#2431.

The generated method

func (rm *resourceManager) EnsureReferences(
	desired acktypes.AWSResource,
	latest acktypes.AWSResource,
) acktypes.AWSResource {
	desiredKO := rm.concreteResource(desired).ko.DeepCopy()
	latestKO := rm.concreteResource(latest).ko.DeepCopy()
	if desiredKO.Spec.Code != nil && latestKO.Spec.Code != nil && desiredKO.Spec.Code.S3BucketRef != nil && latestKO.Spec.Code.S3BucketRef == nil {
		latestKO.Spec.Code.S3BucketRef = desiredKO.Spec.Code.S3BucketRef
	}
	if desiredKO.Spec.VPCConfig != nil && latestKO.Spec.VPCConfig != nil && len(desiredKO.Spec.VPCConfig.SecurityGroupRefs) > 0 && len(latestKO.Spec.VPCConfig.SecurityGroupRefs) == 0 {
		latestKO.Spec.VPCConfig.SecurityGroupRefs = desiredKO.Spec.VPCConfig.SecurityGroupRefs
	}
	if desiredKO.Spec.VPCConfig != nil && latestKO.Spec.VPCConfig != nil && len(desiredKO.Spec.VPCConfig.SubnetRefs) > 0 && len(latestKO.Spec.VPCConfig.SubnetRefs) == 0 {
		latestKO.Spec.VPCConfig.SubnetRefs = desiredKO.Spec.VPCConfig.SubnetRefs
	}
	return &resource{latestKO}
}

Each assignment is guarded on the container existing on both objects and on the target actually missing the reference, so it cannot clobber a reference the service did report.

Compatibility

go.mod is unchanged. The method compiles against the current runtime and stays inert until aws-controllers-k8s/runtime#267 lands, which defines the optional ReferenceEnsurer interface and invokes it after Create and after Update.

Relationship to the existing hooks

templates/hooks/function/sdk_create_post_set_output.go.tpl and sdk_read_one_post_set_output.go.tpl currently restore these same references by hand. This PR does not remove them, and they should not be removed on the strength of code-generator#738: only their create-path half is subsumed. EnsureReferences is not invoked after ReadOne, so the adoption path in Sync and deleteResource still need the read-path hook.

Related: aws-controllers-k8s/code-generator#738, aws-controllers-k8s/runtime#267, aws-controllers-k8s/community#2431.

Demonstration only, not for merge. Shows what
aws-controllers-k8s/code-generator#738 emits in the context of a full
service controller.

Regenerated with no other change, so the diff is exactly the generated
EnsureReferences methods. go.mod is untouched: the method compiles
against the current runtime and stays inert until
aws-controllers-k8s/runtime#267 lands, which is what invokes it.

lambda covers all three reference shapes, so the per-shape behaviour is
visible in one controller:

  function       struct-nested   Code.S3BucketRef, VPCConfig.SecurityGroupRefs,
                                 VPCConfig.SubnetRefs -> emitted
  layer_version  struct-nested   emitted
  event_source_mapping           list-nested -> nothing emitted
  alias, code_signing_config, function_url_config, version
                                 top-level only -> nothing emitted

function is the shape reported in
aws-controllers-k8s/community#2431.
@ack-prow

ack-prow Bot commented Sep 2, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ack-prow ack-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 2, 2026
@ack-prow
ack-prow Bot requested review from a-hilaly and knottnt September 2, 2026 17:53
@ack-prow

ack-prow Bot commented Sep 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gustavodiaz7722

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

The pull request process is described here

Details 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant