@@ -67,6 +67,11 @@ const (
6767 individualSgrRegex = "^(ah|esp|gre|ip_in_ip|l2tp|rsvp|sctp|vrrp|number_(?:0|2|3|5|[7-9]|1[0-6]|1[8-9]|[2-3][0-9]|4[0-5]|4[89]|5[2-9]|[6-9][0-9]|10[0-9]|11[0-1]|11[3-4]|11[6-9]|12[0-9]|13[0-1]|13[3-9]|1[4-9][0-9]|2[0-4][0-9]|25[0-5]))$"
6868)
6969
70+ var (
71+ // Compile the regexp object for the VPCSecurityGroupRuleProtocolIndividualType.
72+ individualSgrRegexp = regexp .MustCompile (individualSgrRegex )
73+ )
74+
7075// ClusterScopeParamsV2 defines the input parameters used to create a new ClusterScopeV2.
7176type ClusterScopeParamsV2 struct {
7277 Client client.Client
@@ -93,8 +98,6 @@ type ClusterScopeV2 struct {
9398 Cluster * clusterv1.Cluster
9499 IBMVPCCluster * infrav1.IBMVPCCluster
95100 ServiceEndpoint []endpoints.ServiceEndpoint
96-
97- individualSgrRegexp * regexp.Regexp
98101}
99102
100103// NewClusterScopeV2 creates a new ClusterScopeV2 from the supplied parameters.
@@ -185,9 +188,6 @@ func NewClusterScopeV2(params ClusterScopeParamsV2) (*ClusterScopeV2, error) {
185188 return nil , fmt .Errorf ("failed to create resource manager client: %w" , err )
186189 }
187190
188- // Compile the regexp object for the VPCSecurityGroupRuleProtocolIndividualType
189- individualSgrRegexp := regexp .MustCompile (individualSgrRegex )
190-
191191 clusterScope := & ClusterScopeV2 {
192192 Logger : params .Logger ,
193193 Client : params .Client ,
@@ -199,7 +199,6 @@ func NewClusterScopeV2(params ClusterScopeParamsV2) (*ClusterScopeV2, error) {
199199 ResourceControllerClient : resourceControllerClient ,
200200 ResourceManagerClient : resourceManagerClient ,
201201 VPCClient : vpcClient ,
202- individualSgrRegexp : individualSgrRegexp ,
203202 }
204203 return clusterScope , nil
205204}
@@ -1539,7 +1538,7 @@ func (s *ClusterScopeV2) findOrCreateSecurityGroupRule(ctx context.Context, secu
15391538 break
15401539 }
15411540 case infrav1 .VPCSecurityGroupRuleProtocolIndividualType :
1542- matched := s . individualSgrRegexp .MatchString (string (securityGroupRulePrototype .Protocol ))
1541+ matched := individualSgrRegexp .MatchString (string (securityGroupRulePrototype .Protocol ))
15431542
15441543 // If our Remote doesn't define one of the individual Protocol, we don't need further checks, move on to next Rule
15451544 if ! matched {
@@ -1824,7 +1823,7 @@ func (s *ClusterScopeV2) createSecurityGroupRule(ctx context.Context, securityGr
18241823 default :
18251824 // Check if protocol is part of the supported list else error
18261825 // If part of the supported list add it as Individual prototype
1827- matched := s . individualSgrRegexp .MatchString (string (securityGroupRulePrototype .Protocol ))
1826+ matched := individualSgrRegexp .MatchString (string (securityGroupRulePrototype .Protocol ))
18281827
18291828 if matched {
18301829 prototype := & vpcv1.SecurityGroupRulePrototypeSecurityGroupRuleProtocolIndividualPrototype {
0 commit comments