Skip to content

fix: improve error message when adoption-fields annotation is missing#231

Open
shinichitazawa wants to merge 1 commit intoaws-controllers-k8s:mainfrom
shinichitazawa:fix-adoption-fields-error-message
Open

fix: improve error message when adoption-fields annotation is missing#231
shinichitazawa wants to merge 1 commit intoaws-controllers-k8s:mainfrom
shinichitazawa:fix-adoption-fields-error-message

Conversation

@shinichitazawa
Copy link

Description

When using services.k8s.aws/adoption-policy: adopt without the services.k8s.aws/adoption-fields annotation, ExtractAdoptionFields in pkg/runtime/util.go calls json.Unmarshal on an empty string, producing the generic Go error unexpected end of JSON input.

This error gives no indication that the adoption-fields annotation is missing, making it very difficult to diagnose — especially since it becomes a TerminalError that permanently blocks reconciliation.

Changes

  • Added an explicit empty-string check in ExtractAdoptionFields that returns a descriptive error message explaining that the adoption-fields annotation is required when adoption-policy is set to adopt
  • Wrapped json.Unmarshal error with fmt.Errorf and %w to provide context about which annotation failed to parse
  • Added two unit tests for the new error cases

Before

{"level":"error","msg":"Reconciler error","error":"unexpected end of JSON input"}

After

{"level":"error","msg":"Reconciler error","error":"services.k8s.aws/adoption-fields annotation is required when adoption-policy is set to 'adopt'; please provide the resource identifier fields as a JSON object (e.g. '{\"name\": \"my-resource\"}')"}

Testing

  • Unit tests added and passing (go test ./pkg/runtime/...)
  • Manually verified with ACK IAM Controller v1.6.2 on EKS

Fixes aws-controllers-k8s/community#2824

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

@ack-prow
Copy link

ack-prow bot commented Mar 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shinichitazawa
Once this PR has been reviewed and has the lgtm label, please assign michaelhtm for approval by writing /assign @michaelhtm in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 requested review from a-hilaly and jlbutler March 13, 2026 01:43
@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 13, 2026
@ack-prow
Copy link

ack-prow bot commented Mar 13, 2026

Hi @shinichitazawa. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

When using `adoption-policy: adopt` without the `adoption-fields`
annotation, `ExtractAdoptionFields` calls `json.Unmarshal` on an empty
string, producing a generic "unexpected end of JSON input" error that
gives no indication of the actual problem.

This change adds an explicit empty-string check that returns a
descriptive error explaining that the `adoption-fields` annotation is
required, and wraps JSON parse errors with context about which
annotation failed.

Fixes aws-controllers-k8s/community#2824
@shinichitazawa shinichitazawa force-pushed the fix-adoption-fields-error-message branch from bd55eae to 64a8f3b Compare March 13, 2026 01:48
@shinichitazawa shinichitazawa changed the title Improve error message when adoption-fields annotation is missing fix: improve error message when adoption-fields annotation is missing Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading 'unexpected end of JSON input' error when adoption-fields annotation is missing with adoption-policy: adopt

1 participant