Skip to content

Commit b7ac5cd

Browse files
TruongHoangPhuLock8s-infra-cherrypick-robot
authored andcommitted
corrected lint requirements
1 parent e955814 commit b7ac5cd

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed

pkg/cloud/services/networking/securitygroups_rules.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,19 @@ func getSGWorkerAllowAll(remoteGroupIDSelf, secControlPlaneGroupID string) []res
258258
// Permit ports that defined in openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts.
259259
func getSGControlPlaneAdditionalPorts(ports []int) []resolvedSecurityGroupRuleSpec {
260260
controlPlaneRules := []resolvedSecurityGroupRuleSpec{}
261-
262-
r := []resolvedSecurityGroupRuleSpec{
263-
{
264-
Description: "Additional ports",
265-
Direction: "ingress",
266-
EtherType: "IPv4",
267-
Protocol: "tcp",
268-
},
269-
}
261+
// Preallocate r with len(ports)
262+
r := make([]resolvedSecurityGroupRuleSpec, len(ports))
270263
for i, p := range ports {
271-
r[i].PortRangeMin = p
272-
r[i].PortRangeMax = p
273-
controlPlaneRules = append(controlPlaneRules, r...)
264+
r[i] = resolvedSecurityGroupRuleSpec{
265+
Description: "Additional port",
266+
Direction: "ingress",
267+
EtherType: "IPv4",
268+
Protocol: "tcp",
269+
PortRangeMin: p,
270+
PortRangeMax: p,
271+
}
274272
}
273+
controlPlaneRules = append(controlPlaneRules, r...)
275274
return controlPlaneRules
276275
}
277276

pkg/cloud/services/networking/securitygroups_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,62 @@ func TestService_ReconcileSecurityGroups(t *testing.T) {
660660
})
661661
}
662662
}
663+
664+
func TestGetSGControlPlaneAdditionalPorts(t *testing.T) {
665+
tests := []struct {
666+
name string
667+
ports []int
668+
want []resolvedSecurityGroupRuleSpec
669+
}{
670+
{
671+
name: "no ports",
672+
ports: []int{},
673+
want: []resolvedSecurityGroupRuleSpec{},
674+
},
675+
{
676+
name: "single port",
677+
ports: []int{6443},
678+
want: []resolvedSecurityGroupRuleSpec{
679+
{
680+
Description: "Additional port",
681+
Direction: "ingress",
682+
EtherType: "IPv4",
683+
Protocol: "tcp",
684+
PortRangeMin: 6443,
685+
PortRangeMax: 6443,
686+
},
687+
},
688+
},
689+
{
690+
name: "multiple ports",
691+
ports: []int{80, 443},
692+
want: []resolvedSecurityGroupRuleSpec{
693+
{
694+
Description: "Additional port",
695+
Direction: "ingress",
696+
EtherType: "IPv4",
697+
Protocol: "tcp",
698+
PortRangeMin: 80,
699+
PortRangeMax: 80,
700+
},
701+
{
702+
Description: "Additional port",
703+
Direction: "ingress",
704+
EtherType: "IPv4",
705+
Protocol: "tcp",
706+
PortRangeMin: 443,
707+
PortRangeMax: 443,
708+
},
709+
},
710+
},
711+
}
712+
713+
for _, tt := range tests {
714+
t.Run(tt.name, func(t *testing.T) {
715+
got := getSGControlPlaneAdditionalPorts(tt.ports)
716+
if !reflect.DeepEqual(got, tt.want) {
717+
t.Errorf("getSGControlPlaneAdditionalPorts() = %v, want %v", got, tt.want)
718+
}
719+
})
720+
}
721+
}

0 commit comments

Comments
 (0)