@@ -57,15 +57,12 @@ import (
57
57
"sigs.k8s.io/cluster-api/util/predicates"
58
58
)
59
59
60
- var (
61
- awsSecurityGroupRoles = []infrav1.SecurityGroupRole {
62
- infrav1 .SecurityGroupBastion ,
63
- infrav1 .SecurityGroupAPIServerLB ,
64
- infrav1 .SecurityGroupLB ,
65
- infrav1 .SecurityGroupControlPlane ,
66
- infrav1 .SecurityGroupNode ,
67
- }
68
- )
60
+ var defaultAWSSecurityGroupRoles = []infrav1.SecurityGroupRole {
61
+ infrav1 .SecurityGroupAPIServerLB ,
62
+ infrav1 .SecurityGroupLB ,
63
+ infrav1 .SecurityGroupControlPlane ,
64
+ infrav1 .SecurityGroupNode ,
65
+ }
69
66
70
67
// AWSClusterReconciler reconciles a AwsCluster object.
71
68
type AWSClusterReconciler struct {
@@ -103,12 +100,24 @@ func (r *AWSClusterReconciler) getNetworkService(scope scope.ClusterScope) servi
103
100
return network .NewService (& scope )
104
101
}
105
102
103
+ // securityGroupRolesForCluster returns the security group roles determined by the cluster configuration.
104
+ func securityGroupRolesForCluster (scope scope.ClusterScope ) []infrav1.SecurityGroupRole {
105
+ roles := []infrav1.SecurityGroupRole {}
106
+ // Copy to ensure we do not modify the package-level variable.
107
+ copy (roles , defaultAWSSecurityGroupRoles )
108
+
109
+ if scope .Bastion ().Enabled {
110
+ roles = append (roles , infrav1 .SecurityGroupBastion )
111
+ }
112
+ return roles
113
+ }
114
+
106
115
// getSecurityGroupService factory func is added for testing purpose so that we can inject mocked SecurityGroupService to the AWSClusterReconciler.
107
116
func (r * AWSClusterReconciler ) getSecurityGroupService (scope scope.ClusterScope ) services.SecurityGroupInterface {
108
117
if r .securityGroupFactory != nil {
109
118
return r .securityGroupFactory (scope )
110
119
}
111
- return securitygroup .NewService (& scope , awsSecurityGroupRoles )
120
+ return securitygroup .NewService (& scope , securityGroupRolesForCluster ( scope ) )
112
121
}
113
122
114
123
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsclusters,verbs=get;list;watch;create;update;patch;delete
0 commit comments