Skip to content

Migrate AWS provider from aws-sdk-go v1 to aws-sdk-go-v2 - #861

Merged
cdalar merged 5 commits into
mainfrom
worktree-aws-sdk-v2-migration
May 29, 2026
Merged

cdalar merged 5 commits into
mainfrom
worktree-aws-sdk-v2-migration

Conversation

@cdalar

@cdalar cdalar commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

Migrates the AWS/EC2 provider code from the deprecated github.com/aws/aws-sdk-go (v1) to github.com/aws/aws-sdk-go-v2, removing the //nolint:staticcheck suppressions and the outstanding "migrate to AWS SDK v2" TODOs.

Changes

  • Client: *ec2.EC2 → *ec2.Client, constructed via config.LoadDefaultConfig + ec2.NewFromConfig instead of session.NewSessionWithOptions
  • Types: model types moved to ec2/types (types.Filter, types.Tag, types.Instance, types.Image, types.Subnet, …); pointer slices → value slices ([]*string → []string, []*ec2.Filter → []types.Filter)
  • Context: every API call now takes context.TODO() (matches the existing hetzner.go convention)
  • Errors: awserr.Error → smithy.APIError via errors.As (extracted a small printAwsError helper)
  • Waiter: WaitUntilInstanceRunning → ec2.NewInstanceRunningWaiter().Wait(ctx, …, 5*time.Minute)
  • Misc: aws.Int64 → aws.Int32; enum fields (InstanceType, ResourceType, State.Name) now typed
  • Config robustness: the shipped init template (internal/files/init/aws.yaml) now defaults aws.vm.image to the wildcard ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-* so GetImages resolves the latest jammy AMI instead of a dated name that expires when AWS deregisters it

Verification

  • make build, go vet ./..., go test ./... — all pass
  • golangci-lint run ./... — 0 issues
  • End-to-end on real AWS (eu-central-1): onctl up -n ad launched a t2.micro, reached running state via the v2 waiter, and onctl ls listed it correctly; key import exercised the new smithy error handling (InvalidKeyPair.Duplicate). Test instance was destroyed afterward.

Notes

  • The v2 instance waiter requires an explicit max-wait; set to 5 minutes (v1 defaulted to ~10). Adjust in internal/cloud/aws.go if the old ceiling is preferred.

cdalar added 2 commits May 29, 2026 18:10
Replace the deprecated github.com/aws/aws-sdk-go with aws-sdk-go-v2
across the EC2 provider code.

- Client *ec2.EC2 -> *ec2.Client, built via config.LoadDefaultConfig +
  ec2.NewFromConfig instead of session.NewSessionWithOptions
- Model types moved to ec2/types; pointer slices -> value slices
- All API calls now take context.TODO()
- Error handling via smithy.APIError + errors.As (printAwsError helper)
- WaitUntilInstanceRunning -> ec2.NewInstanceRunningWaiter().Wait()
- aws.Int64 -> aws.Int32; enum fields (InstanceType, ResourceType,
  State.Name) now typed

Build, go vet, tests, and golangci-lint all pass.
The shipped init config left aws.vm.image unset, and users who pinned an
exact dated Ubuntu AMI (e.g. ...-server-20250918) hit a panic once AWS
deregistered it, since GetImages returned zero results and Deploy indexed
images[0]. Default to the wildcard pattern so GetImages resolves the
latest jammy 22.04 image (it sorts wildcard matches newest-first).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26149d7f8d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cloud/aws.go Outdated
waiter := ec2.NewInstanceRunningWaiter(p.Client)
err = waiter.Wait(context.TODO(), &ec2.DescribeInstancesInput{
InstanceIds: []string{*result.Instances[0].InstanceId},
}, 5*time.Minute)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the old EC2 waiter window

When AWS takes more than 5 minutes to move a newly launched instance to running (for example, slow AMI boot or transient EC2 capacity delays), Deploy now calls log.Fatalln even though the instance may still become healthy; the v1 waiter this replaced used the standard EC2 waiter window of roughly 10 minutes (15s × 40 attempts). This can make onctl up report failure while leaving a real instance behind, so the migration should keep the previous timeout or make it configurable.

Useful? React with 👍 / 👎.

cdalar added 2 commits May 29, 2026 23:08
The v2 migration set the InstanceRunningWaiter max wait to 5m, but v1's
WaitUntilInstanceRunning defaulted to ~10m (15s x 40 attempts). A shorter
window can make 'onctl up' report failure (log.Fatalln) on slow AMI boots
or transient EC2 capacity delays while leaving a real instance behind.
Restore the previous ~10m window.
@socket-security

socket-security Bot commented May 29, 2026 •

Copy link
Copy Markdown

@codecov

codecov Bot commented May 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0.54945% with 181 lines in your changes missing coverage. Please review.
✅ Project coverage is 15.22%. Comparing base (172f588) to head (a184915).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
internal/provideraws/common.go 0.00% 112 Missing ⚠️
internal/cloud/aws.go 0.00% 55 Missing ⚠️
internal/tools/subnets.go 0.00% 7 Missing ⚠️
internal/tools/vpcs.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #861      +/-   ##
==========================================
+ Coverage   14.77%   15.22%   +0.44%     
==========================================
  Files          36       36              
  Lines        3127     3022     -105     
==========================================
- Hits          462      460       -2     
+ Misses       2614     2510     -104     
- Partials       51       52       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Much of onctl is thin cloud-SDK glue (provider wrappers) validated via
end-to-end runs rather than unit tests. A blocking patch-coverage gate
penalizes faithful refactors/migrations even when overall (project)
coverage holds or improves. Keep project as the gate; patch reports only.
@cdalar
cdalar merged commit 3e24db9 into main May 29, 2026
15 checks passed
@cdalar
cdalar deleted the worktree-aws-sdk-v2-migration branch August 19, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址