@@ -17,12 +17,13 @@ limitations under the License.
17
17
package addons
18
18
19
19
import (
20
+ "context"
20
21
"fmt"
21
22
"os"
22
23
23
- "github.com/aws/aws-sdk-go/aws"
24
- "github.com/aws/aws-sdk-go/aws/session "
25
- "github.com/aws/aws-sdk-go/service/eks"
24
+ "github.com/aws/aws-sdk-go-v2 /aws"
25
+ "github.com/aws/aws-sdk-go-v2/config "
26
+ "github.com/aws/aws-sdk-go-v2 /service/eks"
26
27
"github.com/spf13/cobra"
27
28
28
29
cmdout "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/printers"
@@ -51,26 +52,27 @@ func listAvailableCmd() *cobra.Command {
51
52
}
52
53
53
54
func listAvailableAddons (region , clusterName , printerType * string ) error {
54
- cfg := aws.Config {}
55
+ var regionOptsFunc config.LoadOptionsFunc
56
+ ctx := context .TODO ()
55
57
if * region != "" {
56
- cfg . Region = region
58
+ regionOptsFunc = config . WithRegion ( * region )
57
59
}
60
+ optFns := []func (* config.LoadOptions ) error {
61
+ regionOptsFunc ,
62
+ }
63
+
64
+ cfg , err := config .LoadDefaultConfig (context .Background (), optFns ... )
58
65
59
- sess , err := session .NewSessionWithOptions (session.Options {
60
- SharedConfigState : session .SharedConfigEnable ,
61
- Config : cfg ,
62
- })
63
66
if err != nil {
64
- fmt .Printf ("Error: %v\n " , err )
65
67
return err
66
68
}
67
69
68
- eksClient := eks .New ( sess )
70
+ eksClient := eks .NewFromConfig ( cfg )
69
71
70
72
input := & eks.ListAddonsInput {
71
73
ClusterName : clusterName ,
72
74
}
73
- output , err := eksClient .ListAddons (input )
75
+ output , err := eksClient .ListAddons (ctx , input )
74
76
if err != nil {
75
77
return fmt .Errorf ("list addons: %w" , err )
76
78
}
@@ -86,11 +88,11 @@ func listAvailableAddons(region, clusterName, printerType *string) error {
86
88
}
87
89
for _ , addon := range output .Addons {
88
90
describeInput := & eks.DescribeAddonVersionsInput {
89
- AddonName : addon ,
91
+ AddonName : aws . String ( addon ) ,
90
92
}
91
- describeOutput , err := eksClient .DescribeAddonVersions (describeInput )
93
+ describeOutput , err := eksClient .DescribeAddonVersions (ctx , describeInput )
92
94
if err != nil {
93
- return fmt .Errorf ("describing addon versions %s: %w" , * addon , err )
95
+ return fmt .Errorf ("describing addon versions %s: %w" , addon , err )
94
96
}
95
97
96
98
for _ , info := range describeOutput .Addons {
@@ -102,18 +104,15 @@ func listAvailableAddons(region, clusterName, printerType *string) error {
102
104
Architecture : []string {},
103
105
Compatibilities : []compatibility {},
104
106
}
105
- for _ , architecture := range version .Architecture {
106
- newAddon .Architecture = append (newAddon .Architecture , * architecture )
107
- }
107
+ newAddon .Architecture = append (newAddon .Architecture , version .Architecture ... )
108
+
108
109
for _ , compat := range version .Compatibilities {
109
110
compatibility := compatibility {
110
111
ClusterVersion : * compat .ClusterVersion ,
111
- DefaultVersion : * compat .DefaultVersion ,
112
+ DefaultVersion : compat .DefaultVersion ,
112
113
PlatformVersions : []string {},
113
114
}
114
- for _ , platformVersion := range compat .PlatformVersions {
115
- compatibility .PlatformVersions = append (compatibility .PlatformVersions , * platformVersion )
116
- }
115
+ compatibility .PlatformVersions = append (compatibility .PlatformVersions , compat .PlatformVersions ... )
117
116
newAddon .Compatibilities = append (newAddon .Compatibilities , compatibility )
118
117
}
119
118
addonsList .Addons = append (addonsList .Addons , newAddon )
0 commit comments