/
service.go
114 lines (100 loc) · 4.46 KB
/
service.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
/*
Copyright 2020 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 eks
import (
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/aws/aws-sdk-go/service/eks/eksiface"
"github.com/aws/aws-sdk-go/service/sts/stsiface"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/eks/iam"
)
// EKSAPI defines the EKS API interface.
type EKSAPI interface {
eksiface.EKSAPI
WaitUntilClusterUpdating(input *eks.DescribeClusterInput, opts ...request.WaiterOption) error
}
// EKSClient defines a wrapper over EKS API.
type EKSClient struct {
eksiface.EKSAPI
}
// Service holds a collection of interfaces.
// The interfaces are broken down like this to group functions together.
// One alternative is to have a large list of functions from the ec2 client.
type Service struct {
scope *scope.ManagedControlPlaneScope
EC2Client ec2iface.EC2API
EKSClient EKSAPI
iam.IAMService
STSClient stsiface.STSAPI
}
// NewService returns a new service given the api clients.
func NewService(controlPlaneScope *scope.ManagedControlPlaneScope) *Service {
return &Service{
scope: controlPlaneScope,
EC2Client: scope.NewEC2Client(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
EKSClient: EKSClient{
EKSAPI: scope.NewEKSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
},
IAMService: iam.IAMService{
Logger: controlPlaneScope.Logger,
IAMClient: scope.NewIAMClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
},
STSClient: scope.NewSTSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
}
}
// NodegroupService holds a collection of interfaces.
// The interfaces are broken down like this to group functions together.
// One alternative is to have a large list of functions from the ec2 client.
type NodegroupService struct {
scope *scope.ManagedMachinePoolScope
AutoscalingClient autoscalingiface.AutoScalingAPI
EKSClient eksiface.EKSAPI
iam.IAMService
STSClient stsiface.STSAPI
}
// NewNodegroupService returns a new service given the api clients.
func NewNodegroupService(machinePoolScope *scope.ManagedMachinePoolScope) *NodegroupService {
return &NodegroupService{
scope: machinePoolScope,
AutoscalingClient: scope.NewASGClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
EKSClient: scope.NewEKSClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
IAMService: iam.IAMService{
Logger: machinePoolScope.Logger,
IAMClient: scope.NewIAMClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
},
STSClient: scope.NewSTSClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
}
}
// FargateService holds a collection of interfaces.
// The interfaces are broken down like this to group functions together.
type FargateService struct {
scope *scope.FargateProfileScope
EKSClient eksiface.EKSAPI
iam.IAMService
STSClient stsiface.STSAPI
}
// NewFargateService returns a new service given the api clients.
func NewFargateService(fargatePoolScope *scope.FargateProfileScope) *FargateService {
return &FargateService{
scope: fargatePoolScope,
EKSClient: scope.NewEKSClient(fargatePoolScope, fargatePoolScope, fargatePoolScope, fargatePoolScope.FargateProfile),
IAMService: iam.IAMService{
Logger: fargatePoolScope.Logger,
IAMClient: scope.NewIAMClient(fargatePoolScope, fargatePoolScope, fargatePoolScope, fargatePoolScope.FargateProfile),
},
STSClient: scope.NewSTSClient(fargatePoolScope, fargatePoolScope, fargatePoolScope, fargatePoolScope.FargateProfile),
}
}