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

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

Conversation

@gustavodiaz7722

@gustavodiaz7722 gustavodiaz7722 commented Sep 2, 2026

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 {
	// Deep copy the source as well, so a reference handed over below does not
	// alias the caller's declared object.
	desiredKO := rm.concreteResource(desired).ko.DeepCopy()
	latestKO := rm.concreteResource(latest).ko.DeepCopy()

	if desiredKO.Spec.Code != nil {
		if desiredKO.Spec.Code.S3BucketRef != nil {
			if latestKO.Spec.Code == nil {
				latestKO.Spec.Code = &svcapitypes.FunctionCode{}
			}
			if latestKO.Spec.Code.S3BucketRef == nil {
				latestKO.Spec.Code.S3BucketRef = desiredKO.Spec.Code.S3BucketRef
			}
		}
	}
	if desiredKO.Spec.VPCConfig != nil {
		if len(desiredKO.Spec.VPCConfig.SecurityGroupRefs) > 0 {
			if latestKO.Spec.VPCConfig == nil {
				latestKO.Spec.VPCConfig = &svcapitypes.VPCConfig{}
			}
			if len(latestKO.Spec.VPCConfig.SecurityGroupRefs) == 0 {
				latestKO.Spec.VPCConfig.SecurityGroupRefs = desiredKO.Spec.VPCConfig.SecurityGroupRefs
			}
		}
	}
	if desiredKO.Spec.VPCConfig != nil {
		if len(desiredKO.Spec.VPCConfig.SubnetRefs) > 0 {
			if latestKO.Spec.VPCConfig == nil {
				latestKO.Spec.VPCConfig = &svcapitypes.VPCConfig{}
			}
			if len(latestKO.Spec.VPCConfig.SubnetRefs) == 0 {
				latestKO.Spec.VPCConfig.SubnetRefs = desiredKO.Spec.VPCConfig.SubnetRefs
			}
		}
	}

	return &resource{latestKO}
}

Each assignment is guarded on the declared resource actually holding a reference and on the target missing it, so it cannot clobber a reference the service did report. The container is constructed on the target when it is absent -- generated set-output code nils it when the response omits it, and without that the reference would be dropped in exactly the case it most needs restoring.

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 either. runtime#267 subsumes the create-path half. The read-path half is left alone, and AdoptionPolicy_Adopt deliberately replaces a declared reference along with the rest of the declared spec.

Related: aws-controllers-k8s/code-generator#738, aws-controllers-k8s/runtime#267, 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

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.
@gustavodiaz7722
gustavodiaz7722 force-pushed the demo/ensure-references-generated-output branch from d80a3c7 to b41ced4 Compare September 14, 2026 23:46
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