Skip to content

Commit 44338b6

Browse files
authored
Merge pull request #3430 from sedefsavas/scope-cleanup
Scope cleanup
2 parents eb74db4 + 43f1d4f commit 44338b6

File tree

9 files changed

+176
-92
lines changed

9 files changed

+176
-92
lines changed

pkg/cloud/scope/awsnode.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package scope
18+
19+
import (
20+
"sigs.k8s.io/controller-runtime/pkg/client"
21+
22+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
23+
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
24+
)
25+
26+
// AWSNodeScope is the interface for the scope to be used with the awsnode reconciling service.
27+
type AWSNodeScope interface {
28+
cloud.ClusterScoper
29+
30+
// RemoteClient returns the Kubernetes client for connecting to the workload cluster.
31+
RemoteClient() (client.Client, error)
32+
// Subnets returns the cluster subnets.
33+
Subnets() infrav1.Subnets
34+
// SecondaryCidrBlock returns the optional secondary CIDR block to use for pod IPs
35+
SecondaryCidrBlock() *string
36+
// SecurityGroups returns the control plane security groups as a map, it creates the map if empty.
37+
SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup
38+
// DisableVPCCNI returns whether the AWS VPC CNI should be disabled
39+
DisableVPCCNI() bool
40+
}

pkg/cloud/scope/iamauth.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package scope
18+
19+
import (
20+
"sigs.k8s.io/controller-runtime/pkg/client"
21+
22+
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1"
23+
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
24+
)
25+
26+
// IAMAuthScope is the interface for the scope to be used with iamauth reconciling service.
27+
type IAMAuthScope interface {
28+
cloud.ClusterScoper
29+
30+
// RemoteClient returns the Kubernetes client for connecting to the workload cluster.
31+
RemoteClient() (client.Client, error)
32+
// IAMAuthConfig returns the IAM authenticator config
33+
IAMAuthConfig() *ekscontrolplanev1.IAMAuthenticatorConfig
34+
}

pkg/cloud/scope/network.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package scope
18+
19+
import (
20+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
21+
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
22+
)
23+
24+
// NetworkScope is the interface for the scope to be used with the network services.
25+
type NetworkScope interface {
26+
cloud.ClusterScoper
27+
28+
// Network returns the cluster network object.
29+
Network() *infrav1.NetworkStatus
30+
// VPC returns the cluster VPC.
31+
VPC() *infrav1.VPCSpec
32+
// Subnets returns the cluster subnets.
33+
Subnets() infrav1.Subnets
34+
// SetSubnets updates the clusters subnets.
35+
SetSubnets(subnets infrav1.Subnets)
36+
// CNIIngressRules returns the CNI spec ingress rules.
37+
CNIIngressRules() infrav1.CNIIngressRules
38+
// SecurityGroups returns the cluster security groups as a map, it creates the map if empty.
39+
SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup
40+
// SecondaryCidrBlock returns the optional secondary CIDR block to use for pod IPs
41+
SecondaryCidrBlock() *string
42+
43+
// Bastion returns the bastion details for the cluster.
44+
Bastion() *infrav1.Bastion
45+
}

pkg/cloud/scope/sg.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package scope
18+
19+
import (
20+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
21+
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
22+
)
23+
24+
// SGScope is the interface for the scope to be used with the sg service.
25+
type SGScope interface {
26+
cloud.ClusterScoper
27+
28+
// Network returns the cluster network object.
29+
Network() *infrav1.NetworkStatus
30+
31+
// SecurityGroups returns the cluster security groups as a map, it creates the map if empty.
32+
SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup
33+
34+
// SecurityGroupOverrides returns the security groups that are overridden in the cluster spec
35+
SecurityGroupOverrides() map[infrav1.SecurityGroupRole]string
36+
37+
// VPC returns the cluster VPC.
38+
VPC() *infrav1.VPCSpec
39+
40+
// CNIIngressRules returns the CNI spec ingress rules.
41+
CNIIngressRules() infrav1.CNIIngressRules
42+
43+
// Bastion returns the bastion details for the cluster.
44+
Bastion() *infrav1.Bastion
45+
}

pkg/cloud/services/awsnode/service.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,16 @@ limitations under the License.
1717
package awsnode
1818

1919
import (
20-
"sigs.k8s.io/controller-runtime/pkg/client"
21-
22-
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
23-
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
20+
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
2421
)
2522

26-
// Scope is a scope for use with the awsnode reconciling service.
27-
type Scope interface {
28-
cloud.ClusterScoper
29-
30-
// RemoteClient returns the Kubernetes client for connecting to the workload cluster.
31-
RemoteClient() (client.Client, error)
32-
// Subnets returns the cluster subnets.
33-
Subnets() infrav1.Subnets
34-
// SecondaryCidrBlock returns the optional secondary CIDR block to use for pod IPs
35-
SecondaryCidrBlock() *string
36-
// SecurityGroups returns the control plane security groups as a map, it creates the map if empty.
37-
SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup
38-
// DisableVPCCNI returns whether the AWS VPC CNI should be disabled
39-
DisableVPCCNI() bool
40-
}
41-
4223
// Service defines the spec for a service.
4324
type Service struct {
44-
scope Scope
25+
scope scope.AWSNodeScope
4526
}
4627

4728
// NewService will create a new service.
48-
func NewService(awsnodeScope Scope) *Service {
29+
func NewService(awsnodeScope scope.AWSNodeScope) *Service {
4930
return &Service{
5031
scope: awsnodeScope,
5132
}

pkg/cloud/services/iamauth/service.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,19 @@ import (
2020
"github.com/aws/aws-sdk-go/service/sts/stsiface"
2121
"sigs.k8s.io/controller-runtime/pkg/client"
2222

23-
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1"
24-
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
2523
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
2624
)
2725

28-
// Scope is a scope for use with the iamauth reconciling service.
29-
type Scope interface {
30-
cloud.ClusterScoper
31-
32-
// RemoteClient returns the Kubernetes client for connecting to the workload cluster.
33-
RemoteClient() (client.Client, error)
34-
// IAMAuthConfig returns the IAM authenticator config
35-
IAMAuthConfig() *ekscontrolplanev1.IAMAuthenticatorConfig
36-
}
37-
3826
// Service defines the specs for a service.
3927
type Service struct {
40-
scope Scope
28+
scope scope.IAMAuthScope
4129
backend BackendType
4230
client client.Client
4331
STSClient stsiface.STSAPI
4432
}
4533

4634
// NewService will create a new Service object.
47-
func NewService(iamScope Scope, backend BackendType, client client.Client) *Service {
35+
func NewService(iamScope scope.IAMAuthScope, backend BackendType, client client.Client) *Service {
4836
return &Service{
4937
scope: iamScope,
5038
backend: backend,

pkg/cloud/services/network/service.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,19 @@ package network
1919
import (
2020
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
2121

22-
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
23-
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
2422
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
2523
)
2624

27-
// Scope is scope for use with the network service.
28-
type Scope interface {
29-
cloud.ClusterScoper
30-
31-
// Network returns the cluster network object.
32-
Network() *infrav1.NetworkStatus
33-
// VPC returns the cluster VPC.
34-
VPC() *infrav1.VPCSpec
35-
// Subnets returns the cluster subnets.
36-
Subnets() infrav1.Subnets
37-
// SetSubnets updates the clusters subnets.
38-
SetSubnets(subnets infrav1.Subnets)
39-
// CNIIngressRules returns the CNI spec ingress rules.
40-
CNIIngressRules() infrav1.CNIIngressRules
41-
// SecurityGroups returns the cluster security groups as a map, it creates the map if empty.
42-
SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup
43-
// SecondaryCidrBlock returns the optional secondary CIDR block to use for pod IPs
44-
SecondaryCidrBlock() *string
45-
46-
// Bastion returns the bastion details for the cluster.
47-
Bastion() *infrav1.Bastion
48-
}
49-
5025
// Service holds a collection of interfaces.
5126
// The interfaces are broken down like this to group functions together.
5227
// One alternative is to have a large list of functions from the ec2 client.
5328
type Service struct {
54-
scope Scope
29+
scope scope.NetworkScope
5530
EC2Client ec2iface.EC2API
5631
}
5732

5833
// NewService returns a new service given the ec2 api client.
59-
func NewService(networkScope Scope) *Service {
34+
func NewService(networkScope scope.NetworkScope) *Service {
6035
return &Service{
6136
scope: networkScope,
6237
EC2Client: scope.NewEC2Client(networkScope, networkScope, networkScope, networkScope.InfraCluster()),

pkg/cloud/services/network/subnets_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ func TestDeleteSubnets(t *testing.T) {
21152115
// Test helpers
21162116

21172117
type ScopeBuilder interface {
2118-
Build() (Scope, error)
2118+
Build() (scope.NetworkScope, error)
21192119
}
21202120

21212121
func NewClusterScope() *ClusterScopeBuilder {
@@ -2136,7 +2136,7 @@ func (b *ClusterScopeBuilder) WithNetwork(n *infrav1.NetworkSpec) *ClusterScopeB
21362136
return b
21372137
}
21382138

2139-
func (b *ClusterScopeBuilder) Build() (Scope, error) {
2139+
func (b *ClusterScopeBuilder) Build() (scope.NetworkScope, error) {
21402140
scheme := runtime.NewScheme()
21412141
_ = infrav1.AddToScheme(scheme)
21422142
client := fake.NewClientBuilder().WithScheme(scheme).Build()
@@ -2185,7 +2185,7 @@ func (b *ManagedControlPlaneScopeBuilder) WithEKSClusterName(name string) *Manag
21852185
return b
21862186
}
21872187

2188-
func (b *ManagedControlPlaneScopeBuilder) Build() (Scope, error) {
2188+
func (b *ManagedControlPlaneScopeBuilder) Build() (scope.NetworkScope, error) {
21892189
scheme := runtime.NewScheme()
21902190
_ = infrav1.AddToScheme(scheme)
21912191
_ = ekscontrolplanev1.AddToScheme(scheme)

pkg/cloud/services/securitygroup/service.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,21 @@ import (
2020
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
2121

2222
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
23-
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
2423
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
2524
)
2625

27-
// Scope is a scope for use with the security group reconciling service.
28-
type Scope interface {
29-
cloud.ClusterScoper
30-
31-
// Network returns the cluster network object.
32-
Network() *infrav1.NetworkStatus
33-
34-
// SecurityGroups returns the cluster security groups as a map, it creates the map if empty.
35-
SecurityGroups() map[infrav1.SecurityGroupRole]infrav1.SecurityGroup
36-
37-
// SecurityGroupOverrides returns the security groups that are overridden in the cluster spec
38-
SecurityGroupOverrides() map[infrav1.SecurityGroupRole]string
39-
40-
// VPC returns the cluster VPC.
41-
VPC() *infrav1.VPCSpec
42-
43-
// CNIIngressRules returns the CNI spec ingress rules.
44-
CNIIngressRules() infrav1.CNIIngressRules
45-
46-
// Bastion returns the bastion details for the cluster.
47-
Bastion() *infrav1.Bastion
48-
}
49-
5026
// Service holds a collection of interfaces.
5127
// The interfaces are broken down like this to group functions together.
5228
// One alternative is to have a large list of functions from the ec2 client.
5329
type Service struct {
54-
scope Scope
30+
scope scope.SGScope
5531
roles []infrav1.SecurityGroupRole
5632
EC2Client ec2iface.EC2API
5733
}
5834

5935
// NewService returns a new service given the api clients with a defined
6036
// set of roles.
61-
func NewService(sgScope Scope, roles []infrav1.SecurityGroupRole) *Service {
37+
func NewService(sgScope scope.SGScope, roles []infrav1.SecurityGroupRole) *Service {
6238
return &Service{
6339
scope: sgScope,
6440
roles: roles,

0 commit comments

Comments
 (0)