@@ -80,7 +80,7 @@ func main() {
8080 printMigrationSummary (namespaces , policiesByNamespace , servicesByNamespace )
8181}
8282
83- func getEndportNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (ingressPoliciesWithEndport [] string , egressPoliciesWithEndport []string ) {
83+ func getEndportNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (ingressPoliciesWithEndport , egressPoliciesWithEndport []string ) {
8484 for namespace , policies := range policiesByNamespace {
8585 for _ , policy := range policies {
8686 // Check the ingress field for endport
@@ -100,7 +100,7 @@ func getEndportNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Ne
100100 }
101101 }
102102 }
103- return
103+ return ingressPoliciesWithEndport , egressPoliciesWithEndport
104104}
105105
106106func checkEndportInPolicyRules (ports * []networkingv1.NetworkPolicyPort ) bool {
@@ -112,7 +112,7 @@ func checkEndportInPolicyRules(ports *[]networkingv1.NetworkPolicyPort) bool {
112112 return false
113113}
114114
115- func getCIDRNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (ingressPoliciesWithCIDR [] string , egressPoliciesWithCIDR []string ) {
115+ func getCIDRNetworkPolicies (policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (ingressPoliciesWithCIDR , egressPoliciesWithCIDR []string ) {
116116 for namespace , policies := range policiesByNamespace {
117117 for _ , policy := range policies {
118118 // Check the ingress field for cidr
@@ -133,7 +133,7 @@ func getCIDRNetworkPolicies(policiesByNamespace map[string][]*networkingv1.Netwo
133133 }
134134 }
135135 }
136- return
136+ return ingressPoliciesWithCIDR , egressPoliciesWithCIDR
137137}
138138
139139// Check for CIDR in ingress or egress rules
@@ -162,7 +162,7 @@ func getEgressPolicies(policiesByNamespace map[string][]*networkingv1.NetworkPol
162162 return egressPolicies
163163}
164164
165- func getExternalTrafficPolicyClusterServices (namespaces * corev1.NamespaceList , servicesByNamespace map [string ][]* corev1.Service , policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (unsafeServices [] string , noSelectorServices []string ) {
165+ func getExternalTrafficPolicyClusterServices (namespaces * corev1.NamespaceList , servicesByNamespace map [string ][]* corev1.Service , policiesByNamespace map [string ][]* networkingv1.NetworkPolicy ) (unsafeServices , noSelectorServices []string ) {
166166 var servicesAtRisk , safeServices []string
167167
168168 for i := range namespaces .Items {
@@ -198,7 +198,7 @@ func getExternalTrafficPolicyClusterServices(namespaces *corev1.NamespaceList, s
198198 // Get the services that are at risk but not in the safe services or no selector services lists
199199 unsafeServices = difference (& servicesAtRisk , & safeServices , & noSelectorServices )
200200
201- return
201+ return unsafeServices , noSelectorServices
202202}
203203
204204func hasIngressPolicies (policies []* networkingv1.NetworkPolicy ) bool {
@@ -225,7 +225,7 @@ func checkServiceRisk(service *corev1.Service, namespace *string, policiesListAt
225225 return true
226226 }
227227 // Check if there is an allow all ingress policy that matches the service labels
228- if checkPolicyMatchServiceLabels (& service .Spec .Selector , & policy .Spec .PodSelector .MatchLabels ) {
228+ if checkPolicyMatchServiceLabels (service .Spec .Selector , policy .Spec .PodSelector .MatchLabels ) {
229229 // TODO add this to above logic and check in one if statement after i am done printing the logs
230230 fmt .Printf ("found an allow all ingress policy: %s with matching selectors so service %s in the namespace %s is safe\n " , policy .Name , service .Name , * namespace )
231231 return true
@@ -234,7 +234,7 @@ func checkServiceRisk(service *corev1.Service, namespace *string, policiesListAt
234234 // If there are no ingress from but there are ports in the policy; check if the service is safe
235235 if len (ingress .From ) == 0 && len (ingress .Ports ) > 0 {
236236 // If the policy targets all pods (allow all) or only pods that are in the service selector, check if traffic is allowed to all the service's target ports
237- if checkPolicySelectorsAreEmpty (& policy .Spec .PodSelector ) || checkPolicyMatchServiceLabels (& service .Spec .Selector , & policy .Spec .PodSelector .MatchLabels ) {
237+ if checkPolicySelectorsAreEmpty (& policy .Spec .PodSelector ) || checkPolicyMatchServiceLabels (service .Spec .Selector , policy .Spec .PodSelector .MatchLabels ) {
238238 if checkServiceTargetPortMatchPolicyPorts (& service .Spec .Ports , & ingress .Ports ) {
239239 fmt .Printf ("found an ingress port policy: %s with matching selectors and target ports so service %s in the namespace %s is safe\n " , policy .Name , service .Name , * namespace )
240240 return true
@@ -250,17 +250,17 @@ func checkPolicySelectorsAreEmpty(podSelector *metav1.LabelSelector) bool {
250250 return len (podSelector .MatchLabels ) == 0 && len (podSelector .MatchExpressions ) == 0
251251}
252252
253- func checkPolicyMatchServiceLabels (serviceLabels , policyLabels * map [string ]string ) bool {
253+ func checkPolicyMatchServiceLabels (serviceLabels , policyLabels map [string ]string ) bool {
254254 // Return false if the policy has more labels than the service
255- if len (* policyLabels ) > len (* serviceLabels ) {
255+ if len (policyLabels ) > len (serviceLabels ) {
256256 return false
257257 }
258258
259259 // Check for each policy label that that label is present in the service labels
260260 // Note does not check matchExpressions
261- for policyKey , policyValue := range * policyLabels {
261+ for policyKey , policyValue := range policyLabels {
262262 matchedPolicyLabelToServiceLabel := false
263- for serviceKey , serviceValue := range * serviceLabels {
263+ for serviceKey , serviceValue := range serviceLabels {
264264 if policyKey == serviceKey && policyValue == serviceValue {
265265 matchedPolicyLabelToServiceLabel = true
266266 break
0 commit comments