-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsapi.go
76 lines (61 loc) · 2.69 KB
/
awsapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
asg "github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/eks"
xfnaws "github.com/giantswarm/xfnlib/pkg/auth/aws"
)
// EC2API Describes the functions required to access data on the AWS EC2 api
type AwsEc2Api interface {
DescribeLaunchTemplateVersions(ctx context.Context,
params *ec2.DescribeLaunchTemplateVersionsInput,
optFns ...func(*ec2.Options)) (*ec2.DescribeLaunchTemplateVersionsOutput, error)
}
// DescribeLaunchTemplateVersions Get the EC2 Launch template versions for a given launch template
func DescribeLaunchTemplateVersions(c context.Context, api AwsEc2Api, input *ec2.DescribeLaunchTemplateVersionsInput) (*ec2.DescribeLaunchTemplateVersionsOutput, error) {
return api.DescribeLaunchTemplateVersions(c, input)
}
// EKSNodegroupAPI describes the AWS functions required by this composition function
// in order to track nodegroup objects for the desired cluster
type AwsEksApi interface {
ListNodegroups(ctx context.Context,
params *eks.ListNodegroupsInput,
optFns ...func(*eks.Options)) (*eks.ListNodegroupsOutput, error)
DescribeNodegroup(ctx context.Context,
params *eks.DescribeNodegroupInput,
optFns ...func(*eks.Options)) (*eks.DescribeNodegroupOutput, error)
}
// GetNodegroups Get the nodegroups attached to the provided cluster
func GetNodegroups(c context.Context, api AwsEksApi, input *eks.ListNodegroupsInput) (*eks.ListNodegroupsOutput, error) {
return api.ListNodegroups(c, input)
}
// DescribeNodegroup Describe a single nodegroup
func DescribeNodegroup(c context.Context, api AwsEksApi, input *eks.DescribeNodegroupInput) (*eks.DescribeNodegroupOutput, error) {
return api.DescribeNodegroup(c, input)
}
// AutoscalingAPI presents functions required for reading autoscaling groups from AWS
type AwsAsgApi interface {
DescribeAutoScalingGroups(ctx context.Context,
params *asg.DescribeAutoScalingGroupsInput,
optFns ...func(*asg.Options)) (*asg.DescribeAutoScalingGroupsOutput, error)
}
// GetAutoScalingGroups Get the autoscaling group(s) for a given nodegroup
func GetAutoScalingGroups(c context.Context, api AwsAsgApi, input *asg.DescribeAutoScalingGroupsInput) (*asg.DescribeAutoScalingGroupsOutput, error) {
return api.DescribeAutoScalingGroups(c, input)
}
var (
getEc2Client = func(cfg aws.Config) AwsEc2Api {
return ec2.NewFromConfig(cfg)
}
getEksClient = func(cfg aws.Config) AwsEksApi {
return eks.NewFromConfig(cfg)
}
getAsgClient = func(cfg aws.Config) AwsAsgApi {
return asg.NewFromConfig(cfg)
}
awsConfig = func(region, provider *string) (aws.Config, error) {
return xfnaws.Config(region, provider)
}
)