Skip to content

Commit ad7a804

Browse files
committed
migrate EKS package for clusterawsadm
Signed-off-by: Pankaj Walke <[email protected]>
1 parent 3ae8a18 commit ad7a804

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

cmd/clusterawsadm/cmd/eks/addons/list_available.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ limitations under the License.
1717
package addons
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"os"
2223

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"
2627
"github.com/spf13/cobra"
2728

2829
cmdout "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/printers"
@@ -51,26 +52,27 @@ func listAvailableCmd() *cobra.Command {
5152
}
5253

5354
func listAvailableAddons(region, clusterName, printerType *string) error {
54-
cfg := aws.Config{}
55+
var regionOptsFunc config.LoadOptionsFunc
56+
ctx := context.TODO()
5557
if *region != "" {
56-
cfg.Region = region
58+
regionOptsFunc = config.WithRegion(*region)
5759
}
60+
optFns := []func(*config.LoadOptions) error{
61+
regionOptsFunc,
62+
}
63+
64+
cfg, err := config.LoadDefaultConfig(context.Background(), optFns...)
5865

59-
sess, err := session.NewSessionWithOptions(session.Options{
60-
SharedConfigState: session.SharedConfigEnable,
61-
Config: cfg,
62-
})
6366
if err != nil {
64-
fmt.Printf("Error: %v\n", err)
6567
return err
6668
}
6769

68-
eksClient := eks.New(sess)
70+
eksClient := eks.NewFromConfig(cfg)
6971

7072
input := &eks.ListAddonsInput{
7173
ClusterName: clusterName,
7274
}
73-
output, err := eksClient.ListAddons(input)
75+
output, err := eksClient.ListAddons(ctx, input)
7476
if err != nil {
7577
return fmt.Errorf("list addons: %w", err)
7678
}
@@ -86,11 +88,11 @@ func listAvailableAddons(region, clusterName, printerType *string) error {
8688
}
8789
for _, addon := range output.Addons {
8890
describeInput := &eks.DescribeAddonVersionsInput{
89-
AddonName: addon,
91+
AddonName: aws.String(addon),
9092
}
91-
describeOutput, err := eksClient.DescribeAddonVersions(describeInput)
93+
describeOutput, err := eksClient.DescribeAddonVersions(ctx, describeInput)
9294
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)
9496
}
9597

9698
for _, info := range describeOutput.Addons {
@@ -102,18 +104,15 @@ func listAvailableAddons(region, clusterName, printerType *string) error {
102104
Architecture: []string{},
103105
Compatibilities: []compatibility{},
104106
}
105-
for _, architecture := range version.Architecture {
106-
newAddon.Architecture = append(newAddon.Architecture, *architecture)
107-
}
107+
newAddon.Architecture = append(newAddon.Architecture, version.Architecture...)
108+
108109
for _, compat := range version.Compatibilities {
109110
compatibility := compatibility{
110111
ClusterVersion: *compat.ClusterVersion,
111-
DefaultVersion: *compat.DefaultVersion,
112+
DefaultVersion: compat.DefaultVersion,
112113
PlatformVersions: []string{},
113114
}
114-
for _, platformVersion := range compat.PlatformVersions {
115-
compatibility.PlatformVersions = append(compatibility.PlatformVersions, *platformVersion)
116-
}
115+
compatibility.PlatformVersions = append(compatibility.PlatformVersions, compat.PlatformVersions...)
117116
newAddon.Compatibilities = append(newAddon.Compatibilities, compatibility)
118117
}
119118
addonsList.Addons = append(addonsList.Addons, newAddon)

cmd/clusterawsadm/cmd/eks/addons/list_installed.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ limitations under the License.
1717
package addons
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"os"
2223

24+
"github.com/aws/aws-sdk-go-v2/config"
25+
"github.com/aws/aws-sdk-go-v2/service/eks"
2326
"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"
2627
"github.com/spf13/cobra"
2728

2829
cmdout "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/printers"
@@ -51,26 +52,27 @@ func listInstalledCmd() *cobra.Command {
5152
}
5253

5354
func listInstalledAddons(region, clusterName, printerType *string) error {
54-
cfg := aws.Config{}
55+
var regionOptsFunc config.LoadOptionsFunc
56+
ctx := context.TODO()
5557
if *region != "" {
56-
cfg.Region = region
58+
regionOptsFunc = config.WithRegion(*region)
5759
}
60+
optFns := []func(*config.LoadOptions) error{
61+
regionOptsFunc,
62+
}
63+
64+
cfg, err := config.LoadDefaultConfig(context.Background(), optFns...)
5865

59-
sess, err := session.NewSessionWithOptions(session.Options{
60-
SharedConfigState: session.SharedConfigEnable,
61-
Config: cfg,
62-
})
6366
if err != nil {
64-
fmt.Printf("Error: %v\n", err)
6567
return err
6668
}
6769

68-
eksClient := eks.New(sess)
70+
eksClient := eks.NewFromConfig(cfg)
6971

7072
input := &eks.ListAddonsInput{
7173
ClusterName: clusterName,
7274
}
73-
output, err := eksClient.ListAddons(input)
75+
output, err := eksClient.ListAddons(ctx, input)
7476
if err != nil {
7577
return fmt.Errorf("list addons: %w", err)
7678
}
@@ -86,12 +88,12 @@ func listInstalledAddons(region, clusterName, printerType *string) error {
8688
}
8789
for _, addon := range output.Addons {
8890
describeInput := &eks.DescribeAddonInput{
89-
AddonName: addon,
91+
AddonName: aws.String(addon),
9092
ClusterName: clusterName,
9193
}
92-
describeOutput, err := eksClient.DescribeAddon(describeInput)
94+
describeOutput, err := eksClient.DescribeAddon(ctx, describeInput)
9395
if err != nil {
94-
return fmt.Errorf("describing addon %s: %w", *addon, err)
96+
return fmt.Errorf("describing addon %s: %w", addon, err)
9597
}
9698

9799
if describeOutput.Addon == nil {
@@ -103,21 +105,19 @@ func listInstalledAddons(region, clusterName, printerType *string) error {
103105
Version: *describeOutput.Addon.AddonVersion,
104106
AddonARN: *describeOutput.Addon.AddonArn,
105107
RoleARN: describeOutput.Addon.ServiceAccountRoleArn,
106-
Status: *describeOutput.Addon.Status,
108+
Status: string(describeOutput.Addon.Status),
107109
CreatedAt: *describeOutput.Addon.CreatedAt,
108110
ModifiedAt: *describeOutput.Addon.ModifiedAt,
109111
Tags: describeOutput.Addon.Tags,
110112
HealthIssues: []issue{},
111113
}
112114
for _, addonIssue := range describeOutput.Addon.Health.Issues {
113115
newIssue := issue{
114-
Code: *addonIssue.Code,
116+
Code: string(addonIssue.Code),
115117
Message: *addonIssue.Message,
116118
ResourceIDs: []string{},
117119
}
118-
for _, resID := range addonIssue.ResourceIds {
119-
newIssue.ResourceIDs = append(newIssue.ResourceIDs, *resID)
120-
}
120+
newIssue.ResourceIDs = append(newIssue.ResourceIDs, addonIssue.ResourceIds...)
121121
installedAddon.HealthIssues = append(installedAddon.HealthIssues, newIssue)
122122
}
123123

cmd/clusterawsadm/cmd/eks/addons/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type installedAddon struct {
9595
RoleARN *string
9696

9797
Status string
98-
Tags map[string]*string
98+
Tags map[string]string
9999

100100
HealthIssues []issue
101101

0 commit comments

Comments
 (0)