@@ -10,6 +10,7 @@ import (
1010 corev1 "k8s.io/api/core/v1"
1111 networkingv1 "k8s.io/api/networking/v1"
1212 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+ "k8s.io/apimachinery/pkg/util/intstr"
1314 "k8s.io/client-go/kubernetes"
1415 "k8s.io/client-go/tools/clientcmd"
1516)
@@ -74,7 +75,7 @@ func main() {
7475
7576 fmt .Println ("Migration Summary:" )
7677 fmt .Println ("+------------------------------+-------------------------------+" )
77- fmt .Printf ("%-30s | %-30s \n " , "Breaking Change" , "No Impact / Safe to Migrate " )
78+ fmt .Printf ("%-30s | %-30s \n " , "Breaking Change" , "No Policy Changes Needed " )
7879 fmt .Println ("+------------------------------+-------------------------------+" )
7980
8081 // Check the endports of the network policies
@@ -294,7 +295,7 @@ func hasIngressPolicies(policies []networkingv1.NetworkPolicy) bool {
294295 // Check if any policy is ingress
295296 for _ , policy := range policies {
296297 for _ , ingress := range policy .Spec .Ingress {
297- if len (ingress .From ) > 0 {
298+ if len (ingress .From ) > 0 || len ( ingress . Ports ) > 0 {
298299 return true
299300 }
300301 }
@@ -365,8 +366,15 @@ func checkServiceTargetPortMatchPolicyPorts(servicePorts []corev1.ServicePort, p
365366
366367 // Check if all the services target ports are in the policies ingress ports
367368 for _ , port := range servicePorts {
369+ // If the target port is a string then it is a named port and service is at risk
370+ if port .TargetPort .Type == intstr .String {
371+ return false
372+ }
368373 servicePort := fmt .Sprintf ("%d/%s" , port .TargetPort .IntValue (), port .Protocol )
374+ fmt .Printf ("servicePort %s\n " , servicePort )
375+ fmt .Printf ("ingressPorts %v\n " , ingressPorts )
369376 if ! contains (ingressPorts , servicePort ) {
377+ fmt .Printf ("Service port %s is not allowed in the policy\n " , servicePort )
370378 return false
371379 }
372380 }
0 commit comments