diff --git a/Makefile b/Makefile index c890087..32ef4b8 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ build: # TODO: check if oc is installed generate: build + rm -rf $(DEST_DIR)/communication-matrix mkdir -p $(DEST_DIR)/communication-matrix ./$(EXECUTABLE) -format=$(FORMAT) -env=$(CLUSTER_ENV) -destDir=$(DEST_DIR)/communication-matrix -deployment=$(DEPLOYMENT) diff --git a/commatrix/commatrix.go b/commatrix/commatrix.go index e7165ed..1e0bd6f 100644 --- a/commatrix/commatrix.go +++ b/commatrix/commatrix.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "slices" "github.com/openshift-kni/commatrix/client" "github.com/openshift-kni/commatrix/endpointslices" @@ -69,6 +70,8 @@ func New(kubeconfigPath string, customEntriesPath string, e Env, d Deployment) ( res = append(res, customComDetails...) } + slices.SortFunc(res, types.CmpComDetails) + return &types.ComMatrix{Matrix: res}, nil } diff --git a/commatrix/static-custom-entries.go b/commatrix/static-custom-entries.go index e9ac0e8..fec3005 100644 --- a/commatrix/static-custom-entries.go +++ b/commatrix/static-custom-entries.go @@ -5,92 +5,92 @@ package commatrix var generalStaticEntriesWorker = ` [ { - "direction": "ingress", - "protocol": "TCP", - "port": "22", - "nodeRole": "worker", - "service": "sshd", - "namespace": "system", - "pod": "system", - "container": "system", - "optional": true - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9637", - "nodeRole": "worker", - "service": "kube-rbac-proxy", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10250", - "nodeRole": "worker", - "service": "kubelet", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9107", - "nodeRole": "worker", - "service": "egressip-node-healthcheck", - "namespace": "openshift-ovn-kubernetes", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "111", - "nodeRole": "worker", - "service": "rpcbind", - "namespace": "system", - "pod": "system", - "container": "system", - "optional": true - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10256", - "nodeRole": "worker", - "service": "openshift-sdn", - "namespace": "", - "pod": "", - "container": "", - "optional": true - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9001", - "nodeRole": "worker", - "service": "machine-config-daemon", - "namespace": "openshift-machine-config-operator", - "pod": "machine-config-daemon", - "container": "kube-rbac-proxy", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9537", - "nodeRole": "worker", - "service": "crio-metrics", - "namespace": "", - "pod": "", - "container": "", - "optional": false + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "22", + "Node Role": "worker", + "Service": "sshd", + "Namespace": "system", + "Pod": "system", + "Container": "system", + "Optional": true + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9637", + "Node Role": "worker", + "Service": "kube-rbac-proxy", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10250", + "Node Role": "worker", + "Service": "kubelet", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9107", + "Node Role": "worker", + "Service": "egressip-node-healthcheck", + "Namespace": "openshift-ovn-kubernetes", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "111", + "Node Role": "worker", + "Service": "rpcbind", + "Namespace": "system", + "Pod": "system", + "Container": "system", + "Optional": true + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10256", + "Node Role": "worker", + "Service": "openshift-sdn", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": true + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9001", + "Node Role": "worker", + "Service": "machine-config-daemon", + "Namespace": "openshift-machine-config-operator", + "Pod": "machine-config-daemon", + "Container": "kube-rbac-proxy", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9537", + "Node Role": "worker", + "Service": "crio-metrics", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false } ] ` @@ -98,224 +98,224 @@ var generalStaticEntriesWorker = ` var generalStaticEntriesMaster = ` [ { - "direction": "ingress", - "protocol": "TCP", - "port": "9637", - "nodeRole": "master", - "service": "kube-rbac-proxy", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10256", - "nodeRole": "master", - "service": "openshift-sdn", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9537", - "nodeRole": "master", - "service": "crio-metrics", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10250", - "nodeRole": "master", - "service": "kubelet", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9107", - "nodeRole": "master", - "service": "egressip-node-healthcheck", - "namespace": "openshift-ovn-kubernetes", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "111", - "nodeRole": "master", - "service": "rpcbind", - "namespace": "system", - "pod": "system", - "container": "system", - "optional": true - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "22", - "nodeRole": "master", - "service": "sshd", - "namespace": "system", - "pod": "system", - "container": "system", - "optional": true - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9192", - "nodeRole": "master", - "service": "machine-approver", - "namespace": "openshift-cluster-machine-approver", - "pod": "machine-approver", - "container": "kube-rbac-proxy", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9258", - "nodeRole": "master", - "service": "machine-approver", - "namespace": "openshift-cloud-controller-manager-operator", - "pod": "cluster-cloud-controller-manager", - "container": "cluster-cloud-controller-manager", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9099", - "nodeRole": "master", - "service": "cluster-version-operator", - "namespace": "openshift-cluster-version", - "pod": "cluster-version-operator", - "container": "cluster-version-operator", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9980", - "nodeRole": "master", - "service": "etcd", - "namespace": "openshift-etcd", - "pod": "etcd", - "container": "etcd", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9979", - "nodeRole": "master", - "service": "etcd", - "namespace": "openshift-etcd", - "pod": "etcd", - "container": "etcd-metrics", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9978", - "nodeRole": "master", - "service": "etcd", - "namespace": "openshift-etcd", - "pod": "etcd-metrics", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10357", - "nodeRole": "master", - "service": "cluster-policy-controller-apiserver-healthz", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "17697", - "nodeRole": "master", - "service": "no-service", - "namespace": "openshift-kube-apiserver", - "pod": "kube-apiserve", - "container": "kube-apiserver-check-endpoints", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "2380", - "nodeRole": "master", - "service": "healthz", - "namespace": "etcd", - "pod": "etcd", - "container": "etcd", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "2379", - "nodeRole": "master", - "service": "etcd", - "namespace": "openshift-etcd", - "pod": "etcd", - "container": "etcdctl", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "6080", - "nodeRole": "master", - "service": "no-service", - "namespace": "openshift-kube-apiserver", - "pod": "kube-apiserver", - "container": "kube-apiserver-insecure-readyz", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "22624", - "nodeRole": "master", - "service": "machine-config-server", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "22623", - "nodeRole": "master", - "service": "machine-config-server", - "namespace": "", - "pod": "", - "container": "", - "optional": false + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9637", + "Node Role": "master", + "Service": "kube-rbac-proxy", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10256", + "Node Role": "master", + "Service": "openshift-sdn", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9537", + "Node Role": "master", + "Service": "crio-metrics", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10250", + "Node Role": "master", + "Service": "kubelet", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9107", + "Node Role": "master", + "Service": "egressip-node-healthcheck", + "Namespace": "openshift-ovn-kubernetes", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "111", + "Node Role": "master", + "Service": "rpcbind", + "Namespace": "system", + "Pod": "system", + "Container": "system", + "Optional": true + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "22", + "Node Role": "master", + "Service": "sshd", + "Namespace": "system", + "Pod": "system", + "Container": "system", + "Optional": true + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9192", + "Node Role": "master", + "Service": "machine-approver", + "Namespace": "openshift-cluster-machine-approver", + "Pod": "machine-approver", + "Container": "kube-rbac-proxy", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9258", + "Node Role": "master", + "Service": "machine-approver", + "Namespace": "openshift-cloud-controller-manager-operator", + "Pod": "cluster-cloud-controller-manager", + "Container": "cluster-cloud-controller-manager", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9099", + "Node Role": "master", + "Service": "cluster-version-operator", + "Namespace": "openshift-cluster-version", + "Pod": "cluster-version-operator", + "Container": "cluster-version-operator", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9980", + "Node Role": "master", + "Service": "etcd", + "Namespace": "openshift-etcd", + "Pod": "etcd", + "Container": "etcd", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9979", + "Node Role": "master", + "Service": "etcd", + "Namespace": "openshift-etcd", + "Pod": "etcd", + "Container": "etcd-metrics", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9978", + "Node Role": "master", + "Service": "etcd", + "Namespace": "openshift-etcd", + "Pod": "etcd-metrics", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10357", + "Node Role": "master", + "Service": "cluster-policy-controller-apiserver-healthz", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "17697", + "Node Role": "master", + "Service": "no-Service", + "Namespace": "openshift-kube-apiserver", + "Pod": "kube-apiserve", + "Container": "kube-apiserver-check-endpoints", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "2380", + "Node Role": "master", + "Service": "healthz", + "Namespace": "etcd", + "Pod": "etcd", + "Container": "etcd", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "2379", + "Node Role": "master", + "Service": "etcd", + "Namespace": "openshift-etcd", + "Pod": "etcd", + "Container": "etcdctl", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "6080", + "Node Role": "master", + "Service": "no-Service", + "Namespace": "openshift-kube-apiserver", + "Pod": "kube-apiserver", + "Container": "kube-apiserver-insecure-readyz", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "22624", + "Node Role": "master", + "Service": "machine-config-server", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "22623", + "Node Role": "master", + "Service": "machine-config-server", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false } ] ` @@ -323,26 +323,26 @@ var generalStaticEntriesMaster = ` var baremetalStaticEntriesWorker = ` [ { - "direction": "ingress", - "protocol": "TCP", - "port": "53", - "nodeRole": "worker", - "service": "none", - "namespace": "openshift-dns", - "pod": "dnf-default", - "container": "dns", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "18080", - "service": "openshift-kni-infra-coredns", - "nodeRole": "worker", - "namespace": "openshift-kni-infra", - "pod": "coredns", - "container": "coredns", - "optional": false + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "53", + "Node Role": "worker", + "Service": "none", + "Namespace": "openshift-dns", + "Pod": "dnf-default", + "Container": "dns", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "18080", + "Service": "openshift-kni-infra-coredns", + "Node Role": "worker", + "Namespace": "openshift-kni-infra", + "Pod": "coredns", + "Container": "coredns", + "Optional": false } ] ` @@ -350,103 +350,103 @@ var baremetalStaticEntriesWorker = ` var baremetalStaticEntriesMaster = ` [ { - "direction": "ingress", - "protocol": "TCP", - "port": "53", - "nodeRole": "master", - "service": "dns-default", - "namespace": "openshift-dns", - "pod": "dnf-default", - "container": "dns", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "5050", - "nodeRole": "master", - "service": "metal3", - "namespace": "openshift-machine-api", - "pod": "ironic-proxy", - "container": "ironic-proxy", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9444", - "nodeRole": "master", - "service": "openshift-kni-infra-haproxy-haproxy", - "namespace": "openshift-kni-infra", - "pod": "haproxy", - "container": "haproxy", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9445", - "nodeRole": "master", - "service": "haproxy-openshift-dsn-internal-loadbalancer", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9191", - "nodeRole": "master", - "service": "machine-approver", - "namespace": "machine-approver", - "pod": "machine-approver", - "container": "machine-approver-controller", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "6385", - "nodeRole": "master", - "service": "no-service", - "namespace": "openshift-machine-api", - "pod": "ironic-proxy", - "container": "ironic-proxy", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "29445", - "nodeRole": "master", - "service": "haproxy-openshift-dsn", - "namespace": "", - "pod": "", - "container": "", - "optional": true - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "18080", - "nodeRole": "master", - "service": "openshift-kni-infra-coredns", - "namespace": "openshift-kni-infra", - "pod": "corend", - "container": "coredns", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "9447", - "nodeRole": "master", - "service": "baremetal-operator-webhook-baremetal provisioning", - "namespace": "", - "pod": "", - "container": "", - "optional": false + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "53", + "Node Role": "master", + "Service": "dns-default", + "Namespace": "openshift-dns", + "Pod": "dnf-default", + "Container": "dns", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "5050", + "Node Role": "master", + "Service": "metal3", + "Namespace": "openshift-machine-api", + "Pod": "ironic-proxy", + "Container": "ironic-proxy", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9444", + "Node Role": "master", + "Service": "openshift-kni-infra-haproxy-haproxy", + "Namespace": "openshift-kni-infra", + "Pod": "haproxy", + "Container": "haproxy", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9445", + "Node Role": "master", + "Service": "haproxy-openshift-dsn-internal-loadbalancer", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9191", + "Node Role": "master", + "Service": "machine-approver", + "Namespace": "machine-approver", + "Pod": "machine-approver", + "Container": "machine-approver-controller", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "6385", + "Node Role": "master", + "Service": "no-Service", + "Namespace": "openshift-machine-api", + "Pod": "ironic-proxy", + "Container": "ironic-proxy", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "29445", + "Node Role": "master", + "Service": "haproxy-openshift-dsn", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": true + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "18080", + "Node Role": "master", + "Service": "openshift-kni-infra-coredns", + "Namespace": "openshift-kni-infra", + "Pod": "corend", + "Container": "coredns", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "9447", + "Node Role": "master", + "Service": "baremetal-operator-webhook-baremetal provisioning", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false } ] ` @@ -454,26 +454,26 @@ var baremetalStaticEntriesMaster = ` var awsCloudStaticEntriesWorker = ` [ { - "direction": "ingress", - "protocol": "TCP", - "port": "10304", - "nodeRole": "worker", - "service": "csi-node-driver", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10300", - "nodeRole": "worker", - "service": "csi-livenessprobe", - "namespace": "", - "pod": "", - "container": "", - "optional": false + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10304", + "Node Role": "worker", + "Service": "csi-node-driver", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10300", + "Node Role": "worker", + "Service": "csi-livenessprobe", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false } ] ` @@ -481,59 +481,59 @@ var awsCloudStaticEntriesWorker = ` var awsCloudStaticEntriesMaster = ` [ { - "direction": "ingress", - "protocol": "TCP", - "port": "8080", - "nodeRole": "master", - "service": "cluster-network", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10260", - "nodeRole": "master", - "service": "aws-cloud-controller", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10258", - "nodeRole": "master", - "service": "aws-cloud-controller", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10304", - "nodeRole": "master", - "service": "csi-node-driver", - "namespace": "", - "pod": "", - "container": "", - "optional": false - }, - { - "direction": "ingress", - "protocol": "TCP", - "port": "10300", - "nodeRole": "master", - "service": "csi-livenessprobe", - "namespace": "", - "pod": "", - "container": "", - "optional": false + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "8080", + "Node Role": "master", + "Service": "cluster-network", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10260", + "Node Role": "master", + "Service": "aws-cloud-controller", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10258", + "Node Role": "master", + "Service": "aws-cloud-controller", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10304", + "Node Role": "master", + "Service": "csi-node-driver", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false + }, + { + "Direction": "Ingress", + "Protocol": "TCP", + "Port": "10300", + "Node Role": "master", + "Service": "csi-livenessprobe", + "Namespace": "", + "Pod": "", + "Container": "", + "Optional": false } ] ` diff --git a/consts/consts.go b/consts/consts.go index d7c54fb..0f31a5d 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -2,7 +2,7 @@ package consts const ( DefaultAddressType = "IPv4" - IngressLabel = "ingress" + IngressLabel = "Ingress" OptionalLabel = "optional" OptionalTrue = "true" RoleLabel = "node-role.kubernetes.io/" diff --git a/debug/debug.go b/debug/debug.go index 869cdd2..a35aba1 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -14,6 +14,7 @@ import ( "k8s.io/utils/ptr" "github.com/openshift-kni/commatrix/client" + errutil "k8s.io/apimachinery/pkg/api/errors" ) type DebugPod struct { @@ -115,7 +116,8 @@ func waitPodPhase(cs *client.ClientSet, interval time.Duration, timeout time.Dur getErr := errors.New("") err := wait.PollUntilContextTimeout(context.TODO(), interval, timeout, true, func(ctx context.Context) (bool, error) { pod, getErr := cs.Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}) - if getErr != nil && errors.Is(getErr, exec.ErrNotFound) { + + if errutil.IsNotFound(getErr) { return false, getErr } diff --git a/endpointslices/endpointslices.go b/endpointslices/endpointslices.go index eca436a..35f6869 100644 --- a/endpointslices/endpointslices.go +++ b/endpointslices/endpointslices.go @@ -233,7 +233,7 @@ func (epSliceinfo *EndpointSlicesInfo) toComDetails(nodes []corev1.Node) ([]type res = append(res, types.ComDetails{ Direction: consts.IngressLabel, Protocol: string(*port.Protocol), - Port: fmt.Sprint(int(*port.Port)), + Port: int(*port.Port), Namespace: namespace, Pod: name, Container: containerName, diff --git a/ss/ss.go b/ss/ss.go index 937ae02..3e6029e 100644 --- a/ss/ss.go +++ b/ss/ss.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "regexp" + "slices" + "strconv" "strings" "time" @@ -83,6 +85,8 @@ func CreateComDetailsFromNode(cs *client.ClientSet, node *corev1.Node, tcpFile, res = append(res, udpComDetails...) res = append(res, tcpComDetails...) + slices.SortFunc(res, types.CmpComDetails) + return res, nil } @@ -211,7 +215,12 @@ func parseComDetail(ssEntry string) (*types.ComDetails, error) { fields := strings.Fields(ssEntry) portIdx := strings.LastIndex(fields[localAddrPortFieldIdx], ":") - port := fields[localAddrPortFieldIdx][portIdx+1:] + portStr := fields[localAddrPortFieldIdx][portIdx+1:] + + port, err := strconv.Atoi(portStr) + if err != nil { + return nil, err + } return &types.ComDetails{ Direction: consts.IngressLabel, diff --git a/types/types.go b/types/types.go index cfa46bd..7be5196 100644 --- a/types/types.go +++ b/types/types.go @@ -2,6 +2,7 @@ package types import ( "bytes" + "cmp" "encoding/csv" "encoding/json" "fmt" @@ -15,19 +16,19 @@ type ComMatrix struct { } type ComDetails struct { - Direction string `json:"direction"` - Protocol string `json:"protocol"` - Port string `json:"port"` - Namespace string `json:"namespace"` - Service string `json:"service"` - Pod string `json:"pod"` - Container string `json:"container"` - NodeRole string `json:"nodeRole"` - Optional bool `json:"optional"` + Direction string `json:"Direction"` + Protocol string `json:"Protocol"` + Port int `json:"Port,string"` + Namespace string `json:"Namespace"` + Service string `json:"Service"` + Pod string `json:"Pod"` + Container string `json:"Container"` + NodeRole string `json:"Node Role"` + Optional bool `json:"Optional"` } func ToCSV(m ComMatrix) ([]byte, error) { - var header = "direction,protocol,port,namespace,service,pod,container,nodeRole,optional" + var header = "Direction,Protocol,Port,Namespace,Service,Pod,Container,Node Role,Optional" out := make([]byte, 0) w := bytes.NewBuffer(out) @@ -78,14 +79,14 @@ func (m *ComMatrix) String() string { } func (cd ComDetails) String() string { - return fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%v", cd.Direction, cd.Protocol, cd.Port, cd.Namespace, cd.Service, cd.Pod, cd.Container, cd.NodeRole, cd.Optional) + return fmt.Sprintf("%s,%s,%d,%s,%s,%s,%s,%s,%v", cd.Direction, cd.Protocol, cd.Port, cd.Namespace, cd.Service, cd.Pod, cd.Container, cd.NodeRole, cd.Optional) } func RemoveDups(outPuts []ComDetails) []ComDetails { allKeys := make(map[string]bool) res := []ComDetails{} for _, item := range outPuts { - str := fmt.Sprintf("%s-%s-%s", item.NodeRole, item.Port, item.Protocol) + str := fmt.Sprintf("%s-%d-%s", item.NodeRole, item.Port, item.Protocol) if _, value := allKeys[str]; !value { allKeys[str] = true res = append(res, item) @@ -96,8 +97,8 @@ func RemoveDups(outPuts []ComDetails) []ComDetails { } func (cd ComDetails) Equals(other ComDetails) bool { - strComDetail1 := fmt.Sprintf("%s-%s-%s", cd.NodeRole, cd.Port, cd.Protocol) - strComDetail2 := fmt.Sprintf("%s-%s-%s", other.NodeRole, other.Port, other.Protocol) + strComDetail1 := fmt.Sprintf("%s-%d-%s", cd.NodeRole, cd.Port, cd.Protocol) + strComDetail2 := fmt.Sprintf("%s-%d-%s", other.NodeRole, other.Port, other.Protocol) return strComDetail1 == strComDetail2 } @@ -130,3 +131,17 @@ func (m ComMatrix) Contains(cd ComDetails) bool { return false } + +func CmpComDetails(a, b ComDetails) int { + res := cmp.Compare(a.NodeRole, b.NodeRole) + if res != 0 { + return res + } + + res = cmp.Compare(a.Protocol, b.Protocol) + if res != 0 { + return res + } + + return cmp.Compare(a.Port, b.Port) +}