Skip to content

feat: migrate from aws-sdk-go v1 to aws-sdk-go-v2 #523

@tekenstam

Description

@tekenstam

Background

AWS announced end-of-support for aws-sdk-go v1 on July 31, 2025. The repo currently imports `github.com/aws/aws-sdk-go v1.55.8` across 35+ files. Golangci-lint v2 (staticcheck SA1019) now flags every import as a deprecation warning, which we are currently suppressing in `.golangci.yml` pending this migration.

AWS Services Used (v1 → v2 module mapping)

v1 package v2 module
`aws/aws-sdk-go/aws` `aws/aws-sdk-go-v2/aws`
`aws/aws-sdk-go/aws/arn` `aws/aws-sdk-go-v2/aws/arn`
`aws/aws-sdk-go/aws/awserr` removed — use `errors.As` with service error types
`aws/aws-sdk-go/aws/client` `aws/aws-sdk-go-v2/aws` (retry via `aws.RetryerV2`)
`aws/aws-sdk-go/aws/ec2metadata` `aws/aws-sdk-go-v2/feature/ec2/imds`
`aws/aws-sdk-go/aws/request` `aws/aws-sdk-go-v2/aws` (middleware)
`aws/aws-sdk-go/aws/session` `aws/aws-sdk-go-v2/config` (`config.LoadDefaultConfig`)
`aws/aws-sdk-go/service/autoscaling` `aws/aws-sdk-go-v2/service/autoscaling`
`aws/aws-sdk-go/service/ec2` `aws/aws-sdk-go-v2/service/ec2`
`aws/aws-sdk-go/service/eks` `aws/aws-sdk-go-v2/service/eks`
`aws/aws-sdk-go/service/iam` `aws/aws-sdk-go-v2/service/iam`
`aws/aws-sdk-go/service/ssm` `aws/aws-sdk-go-v2/service/ssm`

Note: v2 drops the *iface interface packages (`autoscalingiface`, `ec2iface`, `eksiface`, `iamiface`, `ssmiface`). Mocking for tests must be done via `smithy-go` middleware or hand-written interfaces.

Blocking Dependency

`github.com/keikoproj/aws-sdk-go-cache` currently wraps v1 SDK. It must be updated to v2 before or in parallel with this migration. See keikoproj/aws-sdk-go-cache for a corresponding issue.

Migration Plan

Phase 1 — Update `aws-sdk-go-cache` (prerequisite)

  • Open issue and PR in `keikoproj/aws-sdk-go-cache` to migrate the caching layer to v2 SDK
  • Release new minor version (e.g. `v0.2.0`) of `aws-sdk-go-cache`

Phase 2 — Session / config layer (`controllers/providers/aws/aws.go`)

  • Replace `aws/session` + `session.NewSession()` with `config.LoadDefaultConfig(ctx)`
  • Replace `aws.NewConfig()` with `aws.Config` struct
  • Update custom retry logic (`aws/client`, `aws/request`) to use v2 `aws.RetryerV2` / middleware

Phase 3 — Service clients

  • AutoScaling (`controllers/providers/aws/autoscaling.go`): replace `autoscaling.New(sess)` with `autoscaling.NewFromConfig(cfg)`; update all API call signatures (v2 uses input/output structs, not pointer chaining)
  • EC2 (`controllers/providers/aws/ec2.go`): replace client construction; update `ec2metadata` → `imds` client
  • EKS (`controllers/providers/aws/eks.go`, `constructors.go`): replace client construction and API calls
  • IAM (`controllers/providers/aws/iam.go`): replace client construction and API calls
  • SSM (`controllers/providers/aws/ssm.go`): replace client construction and API calls

Phase 4 — EKS provisioner (`controllers/provisioners/eks/`)

  • Update all v1 SDK type references (`*autoscaling.Group`, `*eks.Cluster`, etc.) to v2 types
  • Replace `aws.StringValue()` / `aws.String()` helpers with direct pointer derefs / address-of (v2 uses plain Go types, not pointer helpers for most fields)
  • Replace `awserr.Error` error handling with `errors.As` against v2 service error types (e.g. `*types.ResourceNotFoundException`)
  • Fix `QF1012` style issues surfaced by staticcheck (3× `WriteString(fmt.Sprintf)` in `helpers.go`)

Phase 5 — EKS Fargate / Managed provisioners

  • `controllers/provisioners/eksfargate/`: same type + error handling updates
  • `controllers/provisioners/eksmanaged/`: same type + error handling updates

Phase 6 — Tests

  • Replace `*iface` mock interfaces with hand-written interfaces or `smithy-go` transport mocks
  • Update all test fixtures referencing v1 types

Phase 7 — Cleanup

  • Remove SA1019 and QF1012 suppressions from `.golangci.yml`
  • Remove `github.com/aws/aws-sdk-go` from `go.mod`
  • Run `go mod tidy`

Key Differences to Watch For

  • Pointer helpers: v1 used `aws.String("x")` / `aws.StringValue(p)` everywhere; v2 uses plain `string` values in most structs — a mechanical but large change
  • Paginators: v2 has first-class paginator support via `NewXxxPaginator` — replace manual next-token loops
  • Error handling: v2 errors implement `smithy.APIError`; use `errors.As` instead of type-asserting to `awserr.Error`
  • Context: v2 requires `context.Context` on every API call — ensure context propagation through the controller reconcile loop

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions