Skip to content

fix: resolve Go field names correctly in late_initialize code generation#708

Open
michaelhtm wants to merge 1 commit into
aws-controllers-k8s:mainfrom
michaelhtm:fix/late-init-field-go-name
Open

fix: resolve Go field names correctly in late_initialize code generation#708
michaelhtm wants to merge 1 commit into
aws-controllers-k8s:mainfrom
michaelhtm:fix/late-init-field-go-name

Conversation

@michaelhtm
Copy link
Copy Markdown
Member

Description of changes:
The late_initialize template was using config field keys directly as Go
struct accessors. For fields from unpack_attributes_map (e.g. SQS
"SqsManagedSseEnabled"), the config key differs from the Go field name
("SQSManagedSSEEnabled"). This caused compilation errors in generated
controllers.

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

@ack-prow ack-prow Bot requested review from a-hilaly and knottnt May 26, 2026 22:13
@ack-prow
Copy link
Copy Markdown

ack-prow Bot commented May 26, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: michaelhtm

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

@ack-prow ack-prow Bot added the approved label May 26, 2026
@michaelhtm
Copy link
Copy Markdown
Member Author

michaelhtm commented May 26, 2026

generated aws-controllers-k8s/sqs-controller#107 with these changes

Copy link
Copy Markdown
Contributor

@knottnt knottnt left a comment

Choose a reason for hiding this comment

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

Left a comment to see if we can use a shared utility for determining the Go field name that should be used. I'd guess we already have one that is being used elsewhere.

// fieldGoName resolves a config field name to its Go-exported name using the
// CRD's field model. For attribute-unpacked fields, the config key may differ
// from the Go name (e.g. "SqsManagedSseEnabled" -> "SQSManagedSSEEnabled").
func fieldGoName(r *model.CRD, configName string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q: It seems like this should be a problem we've already solved for the sdk.go code. How are we determining the Go field name there and can we re-use it here? Ideally, we should have one way of doing this that is shared by all of our generation functions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There isn't a standalone shared utility for this today.. sdk.go does it inline since it already has the field from iterating operation shapes. late_initialize is the only codepath starting from bare config keys.
Modified the function to lookup the existing field, instead of re-initializing names.New()

Comment thread pkg/generate/code/late_initialize.go
@michaelhtm
Copy link
Copy Markdown
Member Author

/retest

The late_initialize template was using config field keys directly as Go
struct accessors. For fields from unpack_attributes_map (e.g. SQS
"SqsManagedSseEnabled"), the config key differs from the Go field name
("SQSManagedSSEEnabled"). This caused compilation errors in generated
controllers.

Resolves aws-controllers-k8s/community#2695
@michaelhtm michaelhtm force-pushed the fix/late-init-field-go-name branch from 227fba8 to ffbd449 Compare May 29, 2026 16:19
@michaelhtm
Copy link
Copy Markdown
Member Author

/retest

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants