@@ -21,6 +21,7 @@ import (
2121 "net"
2222 "strings"
2323
24+ "k8s.io/apimachinery/pkg/util/sets"
2425 "k8s.io/klog/v2"
2526 "k8s.io/kops/pkg/apis/kops"
2627 "k8s.io/kops/pkg/apis/kops/model"
@@ -66,7 +67,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
6667 "209.85.152.0/22" ,
6768 },
6869 TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane )},
69- Allowed : [] string { "tcp" } ,
70+ Allowed : sets . New ( "tcp" ) ,
7071 })
7172 }
7273
@@ -82,7 +83,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
8283 Network : network ,
8384 SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
8485 TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
85- Allowed : allProtocols ,
86+ Allowed : sets . New ( allProtocols ... ) ,
8687 }
8788 c .AddTask (t )
8889 }
@@ -99,7 +100,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
99100 Network : network ,
100101 SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
101102 TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
102- Allowed : allProtocols ,
103+ Allowed : sets . New ( allProtocols ... ) ,
103104 }
104105 c .AddTask (t )
105106 }
@@ -116,7 +117,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
116117 Network : network ,
117118 SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
118119 TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
119- Allowed : allProtocols ,
120+ Allowed : sets . New ( allProtocols ... ) ,
120121 }
121122 c .AddTask (t )
122123 }
@@ -133,25 +134,25 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
133134 Network : network ,
134135 SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
135136 TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
136- Allowed : [] string {
137+ Allowed : sets . New (
137138 fmt .Sprintf ("tcp:%d" , wellknownports .KubeAPIServer ),
138139 fmt .Sprintf ("tcp:%d" , wellknownports .KubeletAPI ),
139140 fmt .Sprintf ("tcp:%d" , wellknownports .KopsControllerPort ),
140- } ,
141+ ) ,
141142 }
142143 if b .Cluster .UsesLegacyGossip () {
143- t .Allowed = append ( t . Allowed , fmt .Sprintf ("udp:%d" , wellknownports .DNSControllerGossipMemberlist ))
144- t .Allowed = append ( t . Allowed , fmt .Sprintf ("tcp:%d" , wellknownports .DNSControllerGossipMemberlist ))
145- t .Allowed = append ( t . Allowed , fmt .Sprintf ("udp:%d" , wellknownports .ProtokubeGossipMemberlist ))
146- t .Allowed = append ( t . Allowed , fmt .Sprintf ("tcp:%d" , wellknownports .ProtokubeGossipMemberlist ))
144+ t .Allowed . Insert ( fmt .Sprintf ("udp:%d" , wellknownports .DNSControllerGossipMemberlist ))
145+ t .Allowed . Insert ( fmt .Sprintf ("tcp:%d" , wellknownports .DNSControllerGossipMemberlist ))
146+ t .Allowed . Insert ( fmt .Sprintf ("udp:%d" , wellknownports .ProtokubeGossipMemberlist ))
147+ t .Allowed . Insert ( fmt .Sprintf ("tcp:%d" , wellknownports .ProtokubeGossipMemberlist ))
147148 }
148149 if b .NetworkingIsCalico () {
149- t .Allowed = append ( t . Allowed , "ipip" )
150+ t .Allowed . Insert ( "ipip" )
150151 }
151152 if b .NetworkingIsCilium () {
152- t .Allowed = append ( t . Allowed , fmt .Sprintf ("udp:%d" , wellknownports .VxlanUDP ))
153+ t .Allowed . Insert ( fmt .Sprintf ("udp:%d" , wellknownports .VxlanUDP ))
153154 if model .UseCiliumEtcd (b .Cluster ) {
154- t .Allowed = append ( t . Allowed , fmt .Sprintf ("tcp:%d" , wellknownports .EtcdCiliumClientPort ))
155+ t .Allowed . Insert ( fmt .Sprintf ("tcp:%d" , wellknownports .EtcdCiliumClientPort ))
155156 }
156157 }
157158 c .AddTask (t )
@@ -176,7 +177,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
176177 Network : network ,
177178 SourceRanges : []string {b .Cluster .Spec .Networking .PodCIDR },
178179 TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
179- Allowed : allProtocols ,
180+ Allowed : sets . New ( allProtocols ... ) ,
180181 })
181182 }
182183 }
@@ -230,13 +231,13 @@ func (b *GCEModelContext) AddFirewallRulesTasks(c *fi.CloudupModelBuilderContext
230231 ipv6 .SourceRanges = []string {"::/0" }
231232 }
232233 }
233- var ipv6Allowed [] string
234- for _ , allowed := range ipv6 .Allowed {
234+ ipv6Allowed := sets . New [ string ]()
235+ for allowed := range ipv6 .Allowed {
235236 // Map icmp to icmpv6; easier than maintaining separate lists
236237 if allowed == "icmp" {
237238 allowed = "58" // 58 == the IANA protocol number for ICMPv6
238239 }
239- ipv6Allowed = append ( ipv6Allowed , allowed )
240+ ipv6Allowed . Insert ( allowed )
240241 }
241242 ipv6 .Allowed = ipv6Allowed
242243 c .AddTask (& ipv6 )
0 commit comments