-
Notifications
You must be signed in to change notification settings - Fork 699
Expand file tree
/
Copy pathinterfaces.go
More file actions
201 lines (175 loc) · 11.4 KB
/
Copy pathinterfaces.go
File metadata and controls
201 lines (175 loc) · 11.4 KB
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
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package services contains the interfaces for the AWS services.
package services
import (
"context"
autoscalingtypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
apimachinerytypes "k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
)
const (
// TemporaryResourceID is the name used temporarily when creating AWS resources.
TemporaryResourceID = "temporary-resource-id"
// AnyIPv4CidrBlock is the CIDR block to match all IPv4 addresses.
AnyIPv4CidrBlock = "0.0.0.0/0"
// AnyIPv6CidrBlock is the CIDR block to match all IPv6 addresses.
AnyIPv6CidrBlock = "::/0"
// NAT64CidrBlock is the well-known CIDR block defined in RFC6052 for NAT64.
NAT64CidrBlock = "64:ff9b::/96"
)
// LaunchTemplateNeedsUpdateReason describes why a launch template needs to be updated. Only the first found difference
// is shown, not all reasons.
type LaunchTemplateNeedsUpdateReason string
const (
// LaunchTemplateNeedsUpdateReasonNone means no update reason was found (no relevant differences).
LaunchTemplateNeedsUpdateReasonNone LaunchTemplateNeedsUpdateReason = ""
// LaunchTemplateNeedsUpdateReasonIamInstanceProfile means a difference in the IAM instance profile was found.
LaunchTemplateNeedsUpdateReasonIamInstanceProfile LaunchTemplateNeedsUpdateReason = "IamInstanceProfile"
// LaunchTemplateNeedsUpdateReasonInstanceType means a difference in the instance type was found.
LaunchTemplateNeedsUpdateReasonInstanceType LaunchTemplateNeedsUpdateReason = "InstanceType"
// LaunchTemplateNeedsUpdateReasonCPUOptions means a difference in the CPU options was found.
LaunchTemplateNeedsUpdateReasonCPUOptions LaunchTemplateNeedsUpdateReason = "CPUOptions"
// LaunchTemplateNeedsUpdateReasonInstanceMetadataOptions means a difference in the instance metadata options was found.
LaunchTemplateNeedsUpdateReasonInstanceMetadataOptions LaunchTemplateNeedsUpdateReason = "InstanceMetadataOptions"
// LaunchTemplateNeedsUpdateReasonSpotMarketOptions means a difference in the spot market options was found.
LaunchTemplateNeedsUpdateReasonSpotMarketOptions LaunchTemplateNeedsUpdateReason = "SpotMarketOptions"
// LaunchTemplateNeedsUpdateReasonCapacityReservationID means a difference in the capacity reservation ID was found.
LaunchTemplateNeedsUpdateReasonCapacityReservationID LaunchTemplateNeedsUpdateReason = "CapacityReservationID"
// LaunchTemplateNeedsUpdateReasonPrivateDNSName means a difference in the private DNS name was found.
LaunchTemplateNeedsUpdateReasonPrivateDNSName LaunchTemplateNeedsUpdateReason = "PrivateDNSName"
// LaunchTemplateNeedsUpdateReasonSSHKeyName means a difference in the SSH key name was found.
LaunchTemplateNeedsUpdateReasonSSHKeyName LaunchTemplateNeedsUpdateReason = "SSHKeyName"
// LaunchTemplateNeedsUpdateReasonAdditionalSecurityGroupIDs means a difference in the additional security group IDs was found.
LaunchTemplateNeedsUpdateReasonAdditionalSecurityGroupIDs LaunchTemplateNeedsUpdateReason = "AdditionalSecurityGroupIDs"
// LaunchTemplateNeedsUpdateReasonEnclaveOptions means a difference in the enclave options was found.
LaunchTemplateNeedsUpdateReasonEnclaveOptions LaunchTemplateNeedsUpdateReason = "EnclaveOptions"
)
// ASGInterface encapsulates the methods exposed to the machinepool
// actuator.
type ASGInterface interface {
ASGIfExists(id *string) (*expinfrav1.AutoScalingGroup, error)
GetASGByName(scope *scope.MachinePoolScope) (*expinfrav1.AutoScalingGroup, error)
CreateASG(scope *scope.MachinePoolScope) (*expinfrav1.AutoScalingGroup, error)
UpdateASG(scope *scope.MachinePoolScope) error
CancelASGInstanceRefresh(scope *scope.MachinePoolScope) error
StartASGInstanceRefresh(scope *scope.MachinePoolScope) error
CanStartASGInstanceRefresh(scope *scope.MachinePoolScope) (bool, *autoscalingtypes.InstanceRefreshStatus, error)
UpdateResourceTags(resourceID *string, create, remove map[string]string) error
DeleteASGAndWait(id string) error
SuspendProcesses(name string, processes []string) error
ResumeProcesses(name string, processes []string) error
SubnetIDs(scope *scope.MachinePoolScope) ([]string, error)
DescribeLifecycleHooks(asgName string) ([]*expinfrav1.AWSLifecycleHook, error)
CreateLifecycleHook(ctx context.Context, asgName string, hook *expinfrav1.AWSLifecycleHook) error
UpdateLifecycleHook(ctx context.Context, asgName string, hook *expinfrav1.AWSLifecycleHook) error
DeleteLifecycleHook(ctx context.Context, asgName string, hook *expinfrav1.AWSLifecycleHook) error
}
// EC2Interface encapsulates the methods exposed to the machine
// actuator.
type EC2Interface interface {
InstanceIfExists(id *string) (*infrav1.Instance, error)
TerminateInstance(id string) error
CreateInstance(ctx context.Context, scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error)
GetRunningInstanceByTags(scope *scope.MachineScope) (*infrav1.Instance, error)
GetAdditionalSecurityGroupsIDs(securityGroup []infrav1.AWSResourceReference) ([]string, error)
GetCoreSecurityGroups(machine *scope.MachineScope) ([]string, error)
GetInstanceSecurityGroups(instanceID string) (map[string][]string, error)
UpdateInstanceSecurityGroups(id string, securityGroups []string) error
UpdateResourceTags(resourceID *string, create, remove map[string]string) error
ModifyInstanceMetadataOptions(instanceID string, options *infrav1.InstanceMetadataOptions) error
TerminateInstanceAndWait(instanceID string) error
DetachSecurityGroupsFromNetworkInterface(groups []string, interfaceID string) error
DiscoverLaunchTemplateAMI(ctx context.Context, scope scope.LaunchTemplateScope) (*string, error)
GetLaunchTemplate(id string) (lt *expinfrav1.AWSLaunchTemplate, userDataHash string, userDataSecretKey *apimachinerytypes.NamespacedName, bootstrapDataHash *string, err error)
GetLaunchTemplateID(id string) (string, error)
GetLaunchTemplateLatestVersion(id string) (string, error)
CreateLaunchTemplate(scope scope.LaunchTemplateScope, imageID *string, userDataSecretKey apimachinerytypes.NamespacedName, userData []byte, bootstrapDataHash string) (string, error)
CreateLaunchTemplateVersion(id string, scope scope.LaunchTemplateScope, imageID *string, userDataSecretKey apimachinerytypes.NamespacedName, userData []byte, bootstrapDataHash string) error
PruneLaunchTemplateVersions(id string) (*ec2types.LaunchTemplateVersion, error)
DeleteLaunchTemplate(id string) error
LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, incoming *expinfrav1.AWSLaunchTemplate, existing *expinfrav1.AWSLaunchTemplate) (bool, LaunchTemplateNeedsUpdateReason, error)
DeleteBastion() error
ReconcileBastion() error
// ReconcileElasticIPFromPublicPool reconciles the elastic IP from a custom Public IPv4 Pool.
ReconcileElasticIPFromPublicPool(pool *infrav1.ElasticIPPool, instance *infrav1.Instance) (bool, error)
// ReleaseElasticIP reconciles the elastic IP from a custom Public IPv4 Pool.
ReleaseElasticIP(instanceID string) error
// Dedicated Host management
AllocateDedicatedHost(ctx context.Context, spec *infrav1.DynamicHostAllocationSpec, instanceType, availabilityZone string, scope *scope.MachineScope) (string, error)
ReleaseDedicatedHost(ctx context.Context, hostID string) error
DescribeDedicatedHost(ctx context.Context, hostID string) (*infrav1.DedicatedHostInfo, error)
}
// MachinePoolReconcileInterface encapsulates high-level reconciliation functions regarding EC2 reconciliation. It is
// separate from EC2Interface so that we can mock AWS requests separately. For example, by not mocking the
// ReconcileLaunchTemplate function, but mocking EC2Interface, we can test which EC2 API operations would have been called.
type MachinePoolReconcileInterface interface {
ReconcileLaunchTemplate(ctx context.Context, ignitionScope scope.IgnitionScope, scope scope.LaunchTemplateScope, s3Scope scope.S3Scope, ec2svc EC2Interface, objectStoreSvc ObjectStoreInterface, canUpdateLaunchTemplate func() (bool, *autoscalingtypes.InstanceRefreshStatus, error), cancelInstanceRefresh func() error, runPostLaunchTemplateUpdateOperation func() error) (*ctrl.Result, error)
ReconcileTags(scope scope.LaunchTemplateScope, resourceServicesToUpdate []scope.ResourceServiceToUpdate) error
}
// SecretInterface encapsulated the methods exposed to the
// machine actuator.
type SecretInterface interface {
Delete(m *scope.MachineScope) error
Create(m *scope.MachineScope, data []byte) (string, int32, error)
UserData(secretPrefix string, chunks int32, region string) ([]byte, error)
}
// ELBInterface encapsulates the methods exposed to the cluster and machine
// controller.
type ELBInterface interface {
DeleteLoadbalancers(ctx context.Context) error
ReconcileLoadbalancers(ctx context.Context) error
IsInstanceRegisteredWithAPIServerELB(ctx context.Context, i *infrav1.Instance) (bool, error)
IsInstanceRegisteredWithAPIServerLB(ctx context.Context, i *infrav1.Instance, lb *infrav1.AWSLoadBalancerSpec) ([]string, bool, error)
DeregisterInstanceFromAPIServerELB(ctx context.Context, i *infrav1.Instance) error
DeregisterInstanceFromAPIServerLB(ctx context.Context, targetGroupArn string, i *infrav1.Instance) error
RegisterInstanceWithAPIServerELB(ctx context.Context, i *infrav1.Instance) error
RegisterInstanceWithAPIServerLB(ctx context.Context, i *infrav1.Instance, lb *infrav1.AWSLoadBalancerSpec) error
}
// NetworkInterface encapsulates the methods exposed to the cluster
// controller.
type NetworkInterface interface {
DeleteNetwork(ctx context.Context) error
ReconcileNetwork() error
}
// SecurityGroupInterface encapsulates the methods exposed to the cluster
// controller.
type SecurityGroupInterface interface {
DeleteSecurityGroups() error
ReconcileSecurityGroups() error
}
// ObjectStoreInterface encapsulates the methods exposed to the machine actuator.
type ObjectStoreInterface interface {
DeleteBucket(ctx context.Context) error
ReconcileBucket(ctx context.Context) error
Delete(ctx context.Context, m *scope.MachineScope) error
Create(ctx context.Context, m *scope.MachineScope, data []byte) (objectURL string, err error)
CreateForMachinePool(ctx context.Context, scope scope.LaunchTemplateScope, data []byte) (objectURL string, err error)
DeleteForMachinePool(ctx context.Context, scope scope.LaunchTemplateScope, bootstrapDataHash string) error
}
// AWSNodeInterface installs the CNI for EKS clusters.
type AWSNodeInterface interface {
ReconcileCNI(ctx context.Context) error
}
// IAMAuthenticatorInterface installs aws-iam-authenticator for EKS clusters.
type IAMAuthenticatorInterface interface {
ReconcileIAMAuthenticator(ctx context.Context) error
}
// KubeProxyInterface installs kube-proxy for EKS clusters.
type KubeProxyInterface interface {
ReconcileKubeProxy(ctx context.Context) error
}