Skip to content

Commit 171d6a0

Browse files
authored
Migrate ACK to AWS SDK GO V2 (#564)
Description of changes: Since `aws-sdk-go` will no longer be maintained after 07/31/2024. With this PR, we will be using the aws-sdk-go-v2 API models to generate our controllers. The changes are: * Introduced an apiv2 package that loads the V2 models into the API structure * Change how we set the resource and sdk, since most fields in V2 are now non-pointers * Add V2 model files for unit tests * Modify Unit test against these changes By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2442aa0 commit 171d6a0

File tree

211 files changed

+457846
-186012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+457846
-186012
lines changed

cmd/ack-generate/command/common.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ func loadModel(svcAlias string, apiVersion string, apiGroup string, defaultCfg a
5353
sdkHelper := acksdk.NewHelper(sdkDir, cfg)
5454
sdkAPI, err := sdkHelper.API(modelName)
5555
if err != nil {
56-
retryModelName, err := FallBackFindServiceID(sdkDir, svcAlias)
57-
if err != nil {
58-
return nil, err
59-
}
60-
// Retry using path found by querying service ID
61-
sdkAPI, err = sdkHelper.API(retryModelName)
62-
if err != nil {
63-
return nil, fmt.Errorf("service %s not found", svcAlias)
64-
}
56+
return nil, err
6557
}
6658

6759
if apiGroup != "" {

cmd/ack-generate/command/controller.go

-43
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
package command
1515

1616
import (
17-
"bufio"
1817
"context"
1918
"fmt"
2019
"io/ioutil"
21-
"os"
2220
"path/filepath"
23-
"regexp"
2421
"strings"
2522

2623
"github.com/spf13/cobra"
@@ -101,43 +98,3 @@ func generateController(cmd *cobra.Command, args []string) error {
10198
}
10299
return nil
103100
}
104-
105-
// FallBackFindServiceID reads through aws-sdk-go/models/apis/*/*/api-2.json
106-
// Returns ServiceID (as newSuppliedAlias) if supplied service Alias matches with serviceID in api-2.json
107-
// If not a match, return the supllied alias.
108-
func FallBackFindServiceID(sdkDir, svcAlias string) (string, error) {
109-
basePath := filepath.Join(sdkDir, "models", "apis")
110-
var files []string
111-
err := filepath.Walk(basePath, func(path string, info os.FileInfo, err error) error {
112-
if err != nil {
113-
return err
114-
}
115-
files = append(files, path)
116-
return nil
117-
})
118-
if err != nil {
119-
return svcAlias, err
120-
}
121-
for _, file := range files {
122-
if strings.Contains(file, "api-2.json") {
123-
f, err := os.Open(file)
124-
if err != nil {
125-
return svcAlias, err
126-
}
127-
defer f.Close()
128-
scanner := bufio.NewScanner(f)
129-
for scanner.Scan() {
130-
if strings.Contains(scanner.Text(), "serviceId") && !strings.Contains(scanner.Text(), "serviceIdentifier") {
131-
getServiceID := strings.Split(scanner.Text(), ":")
132-
re := regexp.MustCompile(`[," \t]`)
133-
svcID := strings.ToLower(re.ReplaceAllString(getServiceID[1], ``))
134-
if svcAlias == svcID {
135-
getNewSvcAlias := strings.Split(file, string(os.PathSeparator))
136-
return getNewSvcAlias[len(getNewSvcAlias)-3], nil
137-
}
138-
}
139-
}
140-
}
141-
}
142-
return svcAlias, nil
143-
}

cmd/ack-generate/command/root.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ func init() {
107107
&optServicesDir, "services-dir", defaultServicesDir, "Path to directory to output service-specific code",
108108
)
109109
rootCmd.PersistentFlags().StringVar(
110-
&optCacheDir, "cache-dir", defaultCacheDir, "Path to directory to store cached files (including clone'd aws-sdk-go repo)",
110+
&optCacheDir, "cache-dir", defaultCacheDir, "Path to directory to store cached files (including clone'd aws-sdk-go-v2 repo)",
111111
)
112112
rootCmd.PersistentFlags().BoolVar(
113-
&optRefreshCache, "refresh-cache", true, "If true, and aws-sdk-go repo is already cloned, will git pull the latest aws-sdk-go commit",
113+
&optRefreshCache, "refresh-cache", true, "If true, and aws-sdk-go-v2 repo is already cloned, will git pull the latest aws-sdk-go-v2 commit",
114114
)
115115
rootCmd.PersistentFlags().StringVar(
116116
&optGeneratorConfigPath, "generator-config-path", "", "Path to file containing instructions for code generation to use",
@@ -125,7 +125,7 @@ func init() {
125125
&optOutputPath, "output", "o", "", "Path to directory to output generated files (if generating crossplane providers, this should be the root of the aws-crossplane directory)",
126126
)
127127
rootCmd.PersistentFlags().StringVar(
128-
&optAWSSDKGoVersion, "aws-sdk-go-version", "", "Version of github.com/aws/aws-sdk-go used to generate apis and controllers files",
128+
&optAWSSDKGoVersion, "aws-sdk-go-version", "", "Version of github.com/aws/aws-sdk-go-v2 used to generate apis and controllers files",
129129
)
130130
rootCmd.PersistentFlags().StringVar(
131131
&optServiceAccountName, "service-account-name", "", "The name of the ServiceAccount used for ACK service controller",

go.mod

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ toolchain go1.22.4
66

77
require (
88
github.com/aws-controllers-k8s/pkg v0.0.15
9-
github.com/aws-controllers-k8s/runtime v0.41.0
9+
github.com/aws-controllers-k8s/runtime v0.41.1-0.20250204215244-e48dd7b2d6d0
1010
github.com/aws/aws-sdk-go v1.49.0
11+
github.com/aws/aws-sdk-go-v2 v1.32.7
1112
github.com/dlclark/regexp2 v1.10.0 // indirect
1213
// pin to v0.1.1 due to release problem with v0.1.2
1314
github.com/gertd/go-pluralize v0.1.1
@@ -29,6 +30,18 @@ require (
2930
dario.cat/mergo v1.0.0 // indirect
3031
github.com/Microsoft/go-winio v0.6.1 // indirect
3132
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
33+
github.com/aws/aws-sdk-go-v2/config v1.28.6 // indirect
34+
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 // indirect
35+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 // indirect
36+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 // indirect
37+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 // indirect
38+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
39+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
40+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 // indirect
41+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 // indirect
42+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
43+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
44+
github.com/aws/smithy-go v1.22.2 // indirect
3245
github.com/beorn7/perks v1.0.1 // indirect
3346
github.com/blang/semver/v4 v4.0.0 // indirect
3447
github.com/cespare/xxhash/v2 v2.3.0 // indirect

go.sum

+28-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,36 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
7373
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
7474
github.com/aws-controllers-k8s/pkg v0.0.15 h1:C1pnD/aDqJsU9oYf5upHkpSc+Hv4JQVtkdCpfZQIPig=
7575
github.com/aws-controllers-k8s/pkg v0.0.15/go.mod h1:VvdjLWmR6IJ3KU8KByKiq/lJE8M+ur2piXysXKTGUS0=
76-
github.com/aws-controllers-k8s/runtime v0.41.0 h1:WumDnUiVlqnYYGEIGSOUBgDPWTIEozW8HT0qwGapDgA=
77-
github.com/aws-controllers-k8s/runtime v0.41.0/go.mod h1:Tuq5AFGJQcU00MY+J5hBYbLctpR50I8iGs5TPLox+u8=
76+
github.com/aws-controllers-k8s/runtime v0.41.1-0.20250204215244-e48dd7b2d6d0 h1:ygZwhPfearlE8/P0HY8rXpFsbarwJ5tzBIov+3xgQfk=
77+
github.com/aws-controllers-k8s/runtime v0.41.1-0.20250204215244-e48dd7b2d6d0/go.mod h1:Oy0JKvDxZMZ+SVupm4NZVqP00KLIIAMfk93KnOwlt5c=
7878
github.com/aws/aws-sdk-go v1.49.0 h1:g9BkW1fo9GqKfwg2+zCD+TW/D36Ux+vtfJ8guF4AYmY=
7979
github.com/aws/aws-sdk-go v1.49.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
80+
github.com/aws/aws-sdk-go-v2 v1.32.7 h1:ky5o35oENWi0JYWUZkB7WYvVPP+bcRF5/Iq7JWSb5Rw=
81+
github.com/aws/aws-sdk-go-v2 v1.32.7/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
82+
github.com/aws/aws-sdk-go-v2/config v1.28.6 h1:D89IKtGrs/I3QXOLNTH93NJYtDhm8SYa9Q5CsPShmyo=
83+
github.com/aws/aws-sdk-go-v2/config v1.28.6/go.mod h1:GDzxJ5wyyFSCoLkS+UhGB0dArhb9mI+Co4dHtoTxbko=
84+
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 h1:48bA+3/fCdi2yAwVt+3COvmatZ6jUDNkDTIsqDiMUdw=
85+
github.com/aws/aws-sdk-go-v2/credentials v1.17.47/go.mod h1:+KdckOejLW3Ks3b0E3b5rHsr2f9yuORBum0WPnE5o5w=
86+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 h1:AmoU1pziydclFT/xRV+xXE/Vb8fttJCLRPv8oAkprc0=
87+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21/go.mod h1:AjUdLYe4Tgs6kpH4Bv7uMZo7pottoyHMn4eTcIcneaY=
88+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 h1:I/5wmGMffY4happ8NOCuIUEWGUvvFp5NSeQcXl9RHcI=
89+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26/go.mod h1:FR8f4turZtNy6baO0KJ5FJUmXH/cSkI9fOngs0yl6mA=
90+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 h1:zXFLuEuMMUOvEARXFUVJdfqZ4bvvSgdGRq/ATcrQxzM=
91+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26/go.mod h1:3o2Wpy0bogG1kyOPrgkXA8pgIfEEv0+m19O9D5+W8y8=
92+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
93+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
94+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y=
95+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE=
96+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 h1:50+XsN70RS7dwJ2CkVNXzj7U2L1HKP8nqTd3XWEXBN4=
97+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6/go.mod h1:WqgLmwY7so32kG01zD8CPTJWVWM+TzJoOVHwTg4aPug=
98+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 h1:rLnYAfXQ3YAccocshIH5mzNNwZBkBo+bP6EhIxak6Hw=
99+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7/go.mod h1:ZHtuQJ6t9A/+YDuxOLnbryAmITtr8UysSny3qcyvJTc=
100+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 h1:JnhTZR3PiYDNKlXy50/pNeix9aGMo6lLpXwJ1mw8MD4=
101+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6/go.mod h1:URronUEGfXZN1VpdktPSD1EkAL9mfrV+2F4sjH38qOY=
102+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 h1:s4074ZO1Hk8qv65GqNXqDjmkf4HSQqJukaLuuW0TpDA=
103+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2/go.mod h1:mVggCnIWoM09jP71Wh+ea7+5gAp53q+49wDFs1SW5z8=
104+
github.com/aws/smithy-go v1.22.2 h1:6D9hW43xKFrRx/tXXfAlIZc4JI+yQe6snnWcQyxSyLQ=
105+
github.com/aws/smithy-go v1.22.2/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
80106
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
81107
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
82108
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

0 commit comments

Comments
 (0)