@@ -21,6 +21,7 @@ import (
21
21
"net"
22
22
"strings"
23
23
24
+ "k8s.io/apimachinery/pkg/util/sets"
24
25
"k8s.io/klog/v2"
25
26
"k8s.io/kops/pkg/apis/kops"
26
27
"k8s.io/kops/pkg/apis/kops/model"
@@ -66,7 +67,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
66
67
"209.85.152.0/22" ,
67
68
},
68
69
TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane )},
69
- Allowed : [] string { "tcp" } ,
70
+ Allowed : sets . New ( "tcp" ) ,
70
71
})
71
72
}
72
73
@@ -82,7 +83,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
82
83
Network : network ,
83
84
SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
84
85
TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
85
- Allowed : allProtocols ,
86
+ Allowed : sets . New ( allProtocols ... ) ,
86
87
}
87
88
c .AddTask (t )
88
89
}
@@ -99,7 +100,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
99
100
Network : network ,
100
101
SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
101
102
TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
102
- Allowed : allProtocols ,
103
+ Allowed : sets . New ( allProtocols ... ) ,
103
104
}
104
105
c .AddTask (t )
105
106
}
@@ -116,7 +117,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
116
117
Network : network ,
117
118
SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
118
119
TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
119
- Allowed : allProtocols ,
120
+ Allowed : sets . New ( allProtocols ... ) ,
120
121
}
121
122
c .AddTask (t )
122
123
}
@@ -133,25 +134,25 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
133
134
Network : network ,
134
135
SourceTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
135
136
TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleControlPlane ), b .GCETagForRole ("Master" )},
136
- Allowed : [] string {
137
+ Allowed : sets . New (
137
138
fmt .Sprintf ("tcp:%d" , wellknownports .KubeAPIServer ),
138
139
fmt .Sprintf ("tcp:%d" , wellknownports .KubeletAPI ),
139
140
fmt .Sprintf ("tcp:%d" , wellknownports .KopsControllerPort ),
140
- } ,
141
+ ) ,
141
142
}
142
143
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 ))
147
148
}
148
149
if b .NetworkingIsCalico () {
149
- t .Allowed = append ( t . Allowed , "ipip" )
150
+ t .Allowed . Insert ( "ipip" )
150
151
}
151
152
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 ))
153
154
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 ))
155
156
}
156
157
}
157
158
c .AddTask (t )
@@ -176,7 +177,7 @@ func (b *FirewallModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
176
177
Network : network ,
177
178
SourceRanges : []string {b .Cluster .Spec .Networking .PodCIDR },
178
179
TargetTags : []string {b .GCETagForRole (kops .InstanceGroupRoleNode )},
179
- Allowed : allProtocols ,
180
+ Allowed : sets . New ( allProtocols ... ) ,
180
181
})
181
182
}
182
183
}
@@ -230,13 +231,13 @@ func (b *GCEModelContext) AddFirewallRulesTasks(c *fi.CloudupModelBuilderContext
230
231
ipv6 .SourceRanges = []string {"::/0" }
231
232
}
232
233
}
233
- var ipv6Allowed [] string
234
- for _ , allowed := range ipv6 .Allowed {
234
+ ipv6Allowed := sets . New [ string ]()
235
+ for allowed := range ipv6 .Allowed {
235
236
// Map icmp to icmpv6; easier than maintaining separate lists
236
237
if allowed == "icmp" {
237
238
allowed = "58" // 58 == the IANA protocol number for ICMPv6
238
239
}
239
- ipv6Allowed = append ( ipv6Allowed , allowed )
240
+ ipv6Allowed . Insert ( allowed )
240
241
}
241
242
ipv6 .Allowed = ipv6Allowed
242
243
c .AddTask (& ipv6 )
0 commit comments