/
types.go
213 lines (185 loc) · 10.5 KB
/
types.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package client
import (
"context"
"sync"
"time"
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
ram "github.com/aliyun/alibaba-cloud-sdk-go/services/resourcemanager"
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
"github.com/aliyun/alibaba-cloud-sdk-go/services/sts"
"github.com/aliyun/alibaba-cloud-sdk-go/services/vpc"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/go-logr/logr"
"golang.org/x/time/rate"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
ros "github.com/gardener/gardener-extension-provider-alicloud/pkg/alicloud/client/ros"
)
// DefaultInternetChargeType is used for EIP
const DefaultInternetChargeType = "PayByTraffic"
// ClientFactory is the new factory to instantiate Alicloud clients.
type ClientFactory interface {
NewECSClient(region, accessKeyID, accessKeySecret string) (ECS, error)
NewSTSClient(region, accessKeyID, accessKeySecret string) (STS, error)
NewSLBClient(region, accessKeyID, accessKeySecret string) (SLB, error)
NewVPCClient(region, accessKeyID, accessKeySecret string) (VPC, error)
NewRAMClient(region, accessKeyID, accessKeySecret string) (RAM, error)
NewROSClient(region, accessKeyID, accessKeySecret string) (ROS, error)
NewOSSClient(endpoint, accessKeyID, accessKeySecret string) (OSS, error)
NewOSSClientFromSecretRef(ctx context.Context, client client.Client, secretRef *corev1.SecretReference, region string) (OSS, error)
NewDNSClient(region, accessKeyID, accessKeySecret string) (DNS, error)
}
// ecsClient implements the ECS interface.
type ecsClient struct {
ecs.Client
}
// ECS is an interface which declares ECS related methods.
type ECS interface {
CheckIfImageExists(imageID string) (bool, error)
CheckIfImageOwnedByAliCloud(imageID string) (bool, error)
ShareImageToAccount(ctx context.Context, regionID, imageID, accountID string) error
GetSecurityGroup(name string) (*ecs.DescribeSecurityGroupsResponse, error)
GetSecurityGroupWithID(id string) (*ecs.DescribeSecurityGroupsResponse, error)
DescribeSecurityGroups(request *ecs.DescribeSecurityGroupsRequest) (*ecs.DescribeSecurityGroupsResponse, error)
DescribeSecurityGroupAttribute(request *ecs.DescribeSecurityGroupAttributeRequest) (*ecs.DescribeSecurityGroupAttributeResponse, error)
DescribeKeyPairs(request *ecs.DescribeKeyPairsRequest) (*ecs.DescribeKeyPairsResponse, error)
DetachECSInstancesFromSSHKeyPair(keyName string) error
GetInstances(name string) (*ecs.DescribeInstancesResponse, error)
GetInstanceType(core int, zoneID string) (*ecs.DescribeAvailableResourceResponse, error)
CreateInstances(instanceName, securityGroupID, imageID, vSwitchId, zoneID, instanceTypeID, userData string) (*ecs.RunInstancesResponse, error)
DeleteInstances(id string, force bool) error
CreateSecurityGroups(vpcId, name string) (*ecs.CreateSecurityGroupResponse, error)
DeleteSecurityGroups(id string) error
AllocatePublicIp(id string) (*ecs.AllocatePublicIpAddressResponse, error)
CreateIngressRule(request *ecs.AuthorizeSecurityGroupRequest) error
CreateEgressRule(request *ecs.AuthorizeSecurityGroupEgressRequest) error
RevokeIngressRule(request *ecs.RevokeSecurityGroupRequest) error
RevokeEgressRule(request *ecs.RevokeSecurityGroupEgressRequest) error
CreateSecurityGroup(request *ecs.CreateSecurityGroupRequest) (response *ecs.CreateSecurityGroupResponse, err error)
DeleteSecurityGroup(request *ecs.DeleteSecurityGroupRequest) (response *ecs.DeleteSecurityGroupResponse, err error)
AuthorizeSecurityGroup(request *ecs.AuthorizeSecurityGroupRequest) (response *ecs.AuthorizeSecurityGroupResponse, err error)
RevokeSecurityGroup(request *ecs.RevokeSecurityGroupRequest) (response *ecs.RevokeSecurityGroupResponse, err error)
AuthorizeSecurityGroupEgress(request *ecs.AuthorizeSecurityGroupEgressRequest) (response *ecs.AuthorizeSecurityGroupEgressResponse, err error)
RevokeSecurityGroupEgress(request *ecs.RevokeSecurityGroupEgressRequest) (response *ecs.RevokeSecurityGroupEgressResponse, err error)
ListTagResources(request *ecs.ListTagResourcesRequest) (response *ecs.ListTagResourcesResponse, err error)
TagResources(request *ecs.TagResourcesRequest) (response *ecs.TagResourcesResponse, err error)
UntagResources(request *ecs.UntagResourcesRequest) (response *ecs.UntagResourcesResponse, err error)
}
// stsClient implements the STS interface.
type stsClient struct {
sts.Client
}
// STS is an interface which declares STS related methods.
type STS interface {
GetAccountIDFromCallerIdentity(ctx context.Context) (string, error)
}
// slbClient implements the SLB interface.
type slbClient struct {
slb.Client
}
// SLB is an interface which declares SLB related methods.
type SLB interface {
GetLoadBalancerIDs(ctx context.Context, region string) ([]string, error)
GetFirstVServerGroupName(ctx context.Context, region, loadBalancerID string) (string, error)
DeleteLoadBalancer(ctx context.Context, region, loadBalancerID string) error
SetLoadBalancerDeleteProtection(ctx context.Context, region, loadBalancerID string, protection bool) error
}
// vpcClient implements the VPC interface.
type vpcClient struct {
vpc.Client
}
// VPC is an interface which declares VPC related methods.
type VPC interface {
ListEnhanhcedNatGatewayAvailableZones(request *vpc.ListEnhanhcedNatGatewayAvailableZonesRequest) (response *vpc.ListEnhanhcedNatGatewayAvailableZonesResponse, err error)
GetVPCWithID(ctx context.Context, vpcID string) ([]vpc.Vpc, error)
GetNatGatewaysWithVPCID(ctx context.Context, vpcID string) ([]vpc.NatGateway, error)
GetEIPWithID(ctx context.Context, eipID string) ([]vpc.EipAddress, error)
GetEnhanhcedNatGatewayAvailableZones(ctx context.Context, region string) ([]string, error)
GetVPCInfo(ctx context.Context, vpcID string) (*VPCInfo, error)
GetVPCInfoByName(name string) (*VPCInfo, error)
FetchEIPInternetChargeType(ctx context.Context, natGateway *vpc.NatGateway, vpcID string) (string, error)
CreateVpc(request *vpc.CreateVpcRequest) (response *vpc.CreateVpcResponse, err error)
DescribeVpcs(request *vpc.DescribeVpcsRequest) (response *vpc.DescribeVpcsResponse, err error)
TagResources(request *vpc.TagResourcesRequest) (response *vpc.TagResourcesResponse, err error)
UnTagResources(request *vpc.UnTagResourcesRequest) (response *vpc.UnTagResourcesResponse, err error)
ListTagResources(request *vpc.ListTagResourcesRequest) (response *vpc.ListTagResourcesResponse, err error)
DeleteVpc(request *vpc.DeleteVpcRequest) (response *vpc.DeleteVpcResponse, err error)
CreateVSwitch(request *vpc.CreateVSwitchRequest) (response *vpc.CreateVSwitchResponse, err error)
DescribeVSwitches(request *vpc.DescribeVSwitchesRequest) (response *vpc.DescribeVSwitchesResponse, err error)
GetVSwitchesInfoByID(name string) (*VSwitchInfo, error)
DeleteVSwitch(request *vpc.DeleteVSwitchRequest) (response *vpc.DeleteVSwitchResponse, err error)
CreateNatGateway(request *vpc.CreateNatGatewayRequest) (response *vpc.CreateNatGatewayResponse, err error)
DescribeNatGateways(request *vpc.DescribeNatGatewaysRequest) (response *vpc.DescribeNatGatewaysResponse, err error)
DeleteNatGateway(request *vpc.DeleteNatGatewayRequest) (response *vpc.DeleteNatGatewayResponse, err error)
DescribeSnatTableEntries(request *vpc.DescribeSnatTableEntriesRequest) (response *vpc.DescribeSnatTableEntriesResponse, err error)
DescribeEipAddresses(request *vpc.DescribeEipAddressesRequest) (response *vpc.DescribeEipAddressesResponse, err error)
AllocateEipAddress(request *vpc.AllocateEipAddressRequest) (response *vpc.AllocateEipAddressResponse, err error)
ReleaseEipAddress(request *vpc.ReleaseEipAddressRequest) (response *vpc.ReleaseEipAddressResponse, err error)
ModifyEipAddressAttribute(request *vpc.ModifyEipAddressAttributeRequest) (response *vpc.ModifyEipAddressAttributeResponse, err error)
AssociateEipAddress(request *vpc.AssociateEipAddressRequest) (response *vpc.AssociateEipAddressResponse, err error)
UnassociateEipAddress(request *vpc.UnassociateEipAddressRequest) (response *vpc.UnassociateEipAddressResponse, err error)
CreateSnatEntry(request *vpc.CreateSnatEntryRequest) (response *vpc.CreateSnatEntryResponse, err error)
DeleteSnatEntry(request *vpc.DeleteSnatEntryRequest) (response *vpc.DeleteSnatEntryResponse, err error)
}
// ramClient implements the RAM interface.
type ramClient struct {
ram.Client
}
// RAM is an interface which declares RAM related methods.
type RAM interface {
CreateServiceLinkedRole(regionID, serviceName string) error
GetServiceLinkedRole(roleName string) (*ram.Role, error)
}
// ROS is an interface which declares ROS related methods.
type ROS interface {
ListStacks(request *ros.ListStacksRequest) (response *ros.ListStacksResponse, err error)
GetStack(request *ros.GetStackRequest) (response *ros.GetStackResponse, err error)
CreateStack(request *ros.CreateStackRequest) (response *ros.CreateStackResponse, err error)
DeleteStack(request *ros.DeleteStackRequest) (response *ros.DeleteStackResponse, err error)
}
// ossClient implements the OSS interface.
type ossClient struct {
oss.Client
}
// OSS is an interface which declares OSS related methods.
type OSS interface {
DeleteObjectsWithPrefix(ctx context.Context, bucketName, prefix string) error
CreateBucketIfNotExists(ctx context.Context, bucketName string) error
DeleteBucketIfExists(ctx context.Context, bucketName string) error
GetBucketInfo(ctx context.Context, bucketName string) (*oss.BucketInfo, error)
}
// VPCInfo contains info about an existing VPC.
type VPCInfo struct {
CIDR string
NATGatewayID string
SNATTableIDs string
InternetChargeType string
VSwitchID string
VPCID string
}
// VSwitchInfo contains info about an existing VSwitchInfo.
type VSwitchInfo struct {
ZoneID string
}
// dnsClient implements the DNS interface.
type dnsClient struct {
alidns.Client
accessKeyID string
domainsCache *cache.Expiring
domainsCacheMutex *sync.Mutex
RateLimiter *rate.Limiter
RateLimiterWaitTimeout time.Duration
Logger logr.Logger
}
// DNS is an interface which declares DNS related methods.
type DNS interface {
GetDomainNames(context.Context) (map[string]string, error)
GetDomainName(context.Context, string) (string, error)
CreateOrUpdateDomainRecords(context.Context, string, string, string, []string, int64) error
DeleteDomainRecords(context.Context, string, string, string) error
}