@@ -80,9 +80,7 @@ func main() {
8080 printMigrationSummary (namespaces , policiesByNamespace , servicesByNamespace )
8181}
8282
83- func getEndportNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) ([]string , []string ) {
84- var ingressPoliciesWithEndport []string
85- var egressPoliciesWithEndport []string
83+ func getEndportNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (ingressPoliciesWithEndport []string , egressPoliciesWithEndport []string ) {
8684 for namespace , policies := range policiesByNamespace {
8785 for _ , policy := range policies {
8886 // Check the ingress field for endport
@@ -102,7 +100,7 @@ func getEndportNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Ne
102100 }
103101 }
104102 }
105- return ingressPoliciesWithEndport , egressPoliciesWithEndport
103+ return
106104}
107105
108106func checkEndportInPolicyRules (ports * []networkingv1.NetworkPolicyPort ) bool {
@@ -114,9 +112,7 @@ func checkEndportInPolicyRules(ports *[]networkingv1.NetworkPolicyPort) bool {
114112 return false
115113}
116114
117- func getCIDRNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) ([]string , []string ) {
118- var ingressPoliciesWithCIDR []string
119- var egressPoliciesWithCIDR []string
115+ func getCIDRNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (ingressPoliciesWithCIDR []string , egressPoliciesWithCIDR []string ) {
120116 for namespace , policies := range policiesByNamespace {
121117 for _ , policy := range policies {
122118 // Check the ingress field for cidr
@@ -137,7 +133,7 @@ func getCIDRNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Netwo
137133 }
138134 }
139135 }
140- return ingressPoliciesWithCIDR , egressPoliciesWithCIDR
136+ return
141137}
142138
143139// Check for CIDR in ingress or egress rules
@@ -166,10 +162,11 @@ func getEgressPolicies(policiesByNamespace map[string][]*networkingv1.NetworkPol
166162 return egressPolicies
167163}
168164
169- func getExternalTrafficPolicyClusterServices (namespaces * corev1.NamespaceList , servicesByNamespace map [string ][]* corev1.Service , policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) ([]string , []string ) {
170- var servicesAtRisk , noSelectorServices , safeServices []string
165+ func getExternalTrafficPolicyClusterServices (namespaces * corev1.NamespaceList , servicesByNamespace map [string ][]* corev1.Service , policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (unsafeServices []string , noSelectorServices []string ) {
166+ var servicesAtRisk , safeServices []string
171167
172- for _ , namespace := range namespaces .Items {
168+ for i := range namespaces .Items {
169+ namespace := & namespaces .Items [i ]
173170 // Check if are there ingress policies in the namespace if not skip
174171 policyListAtNamespace := policiesByNamespace [namespace .Name ]
175172 if ! hasIngressPolicies (policyListAtNamespace ) {
@@ -188,21 +185,20 @@ func getExternalTrafficPolicyClusterServices(namespaces *corev1.NamespaceList, s
188185 // If the service has no selector add it to the noSelectorServices list
189186 if service .Spec .Selector == nil {
190187 noSelectorServices = append (noSelectorServices , fmt .Sprintf ("%s/%s" , namespace .Name , service .Name ))
191- } else {
192- // Check if are there services with selector that match the network policy
193- if checkServiceRisk (service , & namespace .Name , policyListAtNamespace ) {
194- safeServices = append (safeServices , fmt .Sprintf ("%s/%s" , namespace .Name , service .Name ))
195- }
188+ }
189+ // Check if are there services with selector that match the network policy
190+ if checkServiceRisk (service , & namespace .Name , policyListAtNamespace ) {
191+ safeServices = append (safeServices , fmt .Sprintf ("%s/%s" , namespace .Name , service .Name ))
196192 }
197193 }
198194 }
199195 }
200196 }
201197
202198 // Get the services that are at risk but not in the safe services or no selector services lists
203- unsafeServices : = difference (& servicesAtRisk , & safeServices , & noSelectorServices )
199+ unsafeServices = difference (& servicesAtRisk , & safeServices , & noSelectorServices )
204200
205- return unsafeServices , noSelectorServices
201+ return
206202}
207203
208204func hasIngressPolicies (policies []* networkingv1.NetworkPolicy ) bool {
@@ -254,7 +250,7 @@ func checkPolicySelectorsAreEmpty(podSelector *metav1.LabelSelector) bool {
254250 return len (podSelector .MatchLabels ) == 0 && len (podSelector .MatchExpressions ) == 0
255251}
256252
257- func checkPolicyMatchServiceLabels (serviceLabels * map [ string ] string , policyLabels * map [string ]string ) bool {
253+ func checkPolicyMatchServiceLabels (serviceLabels , policyLabels * map [string ]string ) bool {
258254 // Return false if the policy has more labels than the service
259255 if len (* policyLabels ) > len (* serviceLabels ) {
260256 return false
@@ -303,7 +299,7 @@ func checkServiceTargetPortMatchPolicyPorts(servicePorts *[]corev1.ServicePort,
303299 return true
304300}
305301
306- func difference (slice1 * [] string , slice2 * [] string , slice3 * []string ) []string {
302+ func difference (slice1 , slice2 , slice3 * []string ) []string {
307303 m := make (map [string ]bool )
308304 for _ , s := range * slice2 {
309305 m [s ] = true
@@ -367,7 +363,7 @@ func printMigrationSummary(namespaces *corev1.NamespaceList, policiesByNamespace
367363 }
368364}
369365
370- func printPoliciesWithEndport (ingressEndportNetworkPolicy * [] string , egressEndportNetworkPolicy * []string ) {
366+ func printPoliciesWithEndport (ingressEndportNetworkPolicy , egressEndportNetworkPolicy * []string ) {
371367 if len (* ingressEndportNetworkPolicy ) == 0 && len (* egressEndportNetworkPolicy ) == 0 {
372368 fmt .Printf ("%-30s | %-30s \n " , "NetworkPolicy with endport" , "✅" )
373369 } else {
@@ -386,7 +382,7 @@ func printPoliciesWithEndport(ingressEndportNetworkPolicy *[]string, egressEndpo
386382 }
387383}
388384
389- func printPoliciesWithCIDR (ingressPoliciesWithCIDR * [] string , egressPoliciesWithCIDR * []string ) {
385+ func printPoliciesWithCIDR (ingressPoliciesWithCIDR , egressPoliciesWithCIDR * []string ) {
390386 if len (* ingressPoliciesWithCIDR ) == 0 && len (* egressPoliciesWithCIDR ) == 0 {
391387 fmt .Printf ("%-30s | %-30s \n " , "NetworkPolicy with CIDR" , "✅" )
392388 } else {
@@ -420,7 +416,7 @@ func printEgressPolicies(egressPolicies *[]string) {
420416 }
421417}
422418
423- func printUnsafeServices (unsafeServices * [] string , noSelectorServices * []string ) {
419+ func printUnsafeServices (unsafeServices , noSelectorServices * []string ) {
424420 // If there is no unsafe services then migration is safe for services with extranalTrafficPolicy=Cluster
425421 if len (* unsafeServices ) == 0 {
426422 fmt .Printf ("%-30s | %-30s \n " , "Disruption for some" , "✅" )
0 commit comments