From fbf07d7fa6dd8d4861ce652454368742c8fa831f Mon Sep 17 00:00:00 2001 From: Sabina Aledort Date: Thu, 25 Apr 2024 12:10:18 +0300 Subject: [PATCH 1/5] Sort commatrix --- Makefile | 1 + cmd/main.go | 2 +- commatrix/commatrix.go | 2 +- commatrix/static-custom-entries.go | 196 ++++++++++++++--------------- consts/consts.go | 2 +- debug/debug.go | 3 +- endpointslices/endpointslices.go | 2 +- ss/ss.go | 9 +- types/types.go | 30 +++-- 9 files changed, 136 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index 557ddbc..bd115c2 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ ifeq (, $(shell which oc)) endif generate: oc 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/cmd/main.go b/cmd/main.go index 2785987..b1a224e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -157,7 +157,7 @@ func main() { panic(err) } - cleanedComDetails := types.RemoveDups(nodesComDetails) + cleanedComDetails := types.CleanComDetails(nodesComDetails) ssComMat := types.ComMatrix{Matrix: cleanedComDetails} res, err = printFn(ssComMat) diff --git a/commatrix/commatrix.go b/commatrix/commatrix.go index e0866fd..fc9931a 100644 --- a/commatrix/commatrix.go +++ b/commatrix/commatrix.go @@ -69,7 +69,7 @@ func New(kubeconfigPath string, customEntriesPath string, e Env, d Deployment) ( res = append(res, customComDetails...) } - cleanedComDetails := types.RemoveDups(res) + cleanedComDetails := types.CleanComDetails(res) return &types.ComMatrix{Matrix: cleanedComDetails}, nil } diff --git a/commatrix/static-custom-entries.go b/commatrix/static-custom-entries.go index 129bbb4..47c7c2a 100644 --- a/commatrix/static-custom-entries.go +++ b/commatrix/static-custom-entries.go @@ -4,9 +4,9 @@ import "github.com/openshift-kni/commatrix/types" var generalStaticEntriesWorker = []types.ComDetails{ { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "22", + Port: 22, NodeRole: "worker", Service: "sshd", Namespace: "", @@ -14,9 +14,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9637", + Port: 9637, NodeRole: "worker", Service: "kube-rbac-proxy-crio", Namespace: "openshift-machine-config-operator", @@ -24,9 +24,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "kube-rbac-proxy-crio", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10250", + Port: 10250, NodeRole: "worker", Service: "kubelet", Namespace: "", @@ -34,9 +34,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9107", + Port: 9107, NodeRole: "worker", Service: "egressip-node-healthcheck", Namespace: "openshift-ovn-kubernetes", @@ -44,9 +44,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "111", + Port: 111, NodeRole: "worker", Service: "rpcbind", Namespace: "", @@ -54,9 +54,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "UDP", - Port: "111", + Port: 111, NodeRole: "worker", Service: "rpcbind", Namespace: "", @@ -64,9 +64,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10256", + Port: 10256, NodeRole: "worker", Service: "ovnkube", Namespace: "openshift-sdn", @@ -74,9 +74,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ Container: "ovnkube-controller", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9537", + Port: 9537, NodeRole: "worker", Service: "crio-metrics", Namespace: "", @@ -88,9 +88,9 @@ var generalStaticEntriesWorker = []types.ComDetails{ var generalStaticEntriesMaster = []types.ComDetails{ { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9637", + Port: 9637, NodeRole: "master", Service: "kube-rbac-proxy-crio", Namespace: "openshift-machine-config-operator", @@ -98,9 +98,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "kube-rbac-proxy-crio", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10256", + Port: 10256, NodeRole: "master", Service: "openshift-sdn", Namespace: "", @@ -108,9 +108,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9537", + Port: 9537, NodeRole: "master", Service: "crio-metrics", Namespace: "", @@ -118,9 +118,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10250", + Port: 10250, NodeRole: "master", Service: "kubelet", Namespace: "", @@ -128,9 +128,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9107", + Port: 9107, NodeRole: "master", Service: "egressip-node-healthcheck", Namespace: "openshift-ovn-kubernetes", @@ -138,9 +138,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "ovnkube-controller", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "111", + Port: 111, NodeRole: "master", Service: "rpcbind", Namespace: "", @@ -148,9 +148,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "UDP", - Port: "111", + Port: 111, NodeRole: "master", Service: "rpcbind", Namespace: "", @@ -158,9 +158,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "22", + Port: 22, NodeRole: "master", Service: "sshd", Namespace: "", @@ -168,9 +168,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9258", + Port: 9258, NodeRole: "master", Service: "machine-approver", Namespace: "openshift-cloud-controller-manager-operator", @@ -178,9 +178,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "cluster-cloud-controller-manager", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9099", + Port: 9099, NodeRole: "master", Service: "cluster-version-operator", Namespace: "openshift-cluster-version", @@ -188,9 +188,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "cluster-version-operator", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9980", + Port: 9980, NodeRole: "master", Service: "etcd", Namespace: "openshift-etcd", @@ -198,9 +198,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "etcd", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9979", + Port: 9979, NodeRole: "master", Service: "etcd", Namespace: "openshift-etcd", @@ -208,9 +208,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "etcd-metrics", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9978", + Port: 9978, NodeRole: "master", Service: "etcd", Namespace: "openshift-etcd", @@ -218,9 +218,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "etcd-metrics", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10357", + Port: 10357, NodeRole: "master", Service: "openshift-kube-apiserver-healthz", Namespace: "openshift-kube-apiserver", @@ -228,9 +228,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "kube-apiserver-check-endpoints", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "17697", + Port: 17697, NodeRole: "master", Service: "openshift-kube-apiserver-healthz", Namespace: "openshift-kube-apiserver", @@ -238,9 +238,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "kube-apiserver-check-endpoints", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "2380", + Port: 2380, NodeRole: "master", Service: "healthz", Namespace: "openshift-etcd", @@ -248,9 +248,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "etcd", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "2379", + Port: 2379, NodeRole: "master", Service: "etcd", Namespace: "openshift-etcd", @@ -258,9 +258,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "etcdctl", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "6080", + Port: 6080, NodeRole: "master", Service: "", Namespace: "openshift-kube-apiserver-readyz", @@ -268,9 +268,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "kube-apiserver-insecure-readyz", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "22624", + Port: 22624, NodeRole: "master", Service: "machine-config-server", Namespace: "openshift-machine-config-operator", @@ -278,9 +278,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ Container: "machine-config-server", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "22623", + Port: 22623, NodeRole: "master", Service: "machine-config-server", Namespace: "openshift-machine-config-operator", @@ -292,9 +292,9 @@ var generalStaticEntriesMaster = []types.ComDetails{ var baremetalStaticEntriesWorker = []types.ComDetails{ { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "53", + Port: 53, NodeRole: "worker", Service: "dns-default", Namespace: "openshift-dns", @@ -302,9 +302,9 @@ var baremetalStaticEntriesWorker = []types.ComDetails{ Container: "dns", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "UDP", - Port: "53", + Port: 53, NodeRole: "worker", Service: "dns-default", Namespace: "openshift-dns", @@ -312,9 +312,9 @@ var baremetalStaticEntriesWorker = []types.ComDetails{ Container: "dns", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "18080", + Port: 18080, NodeRole: "worker", Service: "openshift-kni-infra-coredns", Namespace: "openshift-kni-infra", @@ -326,9 +326,9 @@ var baremetalStaticEntriesWorker = []types.ComDetails{ var baremetalStaticEntriesMaster = []types.ComDetails{ { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "53", + Port: 53, NodeRole: "master", Service: "dns-default", Namespace: "openshift-dns", @@ -336,9 +336,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "dns", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "UDP", - Port: "53", + Port: 53, NodeRole: "master", Service: "dns-default", Namespace: "openshift-dns", @@ -346,9 +346,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "dns", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "5050", + Port: 5050, NodeRole: "master", Service: "metal3", Namespace: "openshift-machine-api", @@ -356,9 +356,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "ironic-proxy", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9444", + Port: 9444, NodeRole: "master", Service: "openshift-kni-infra-haproxy-haproxy", Namespace: "openshift-kni-infra", @@ -366,9 +366,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "haproxy", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9445", + Port: 9445, NodeRole: "master", Service: "haproxy-openshift-dsn-internal-loadbalancer", Namespace: "", @@ -376,9 +376,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9191", + Port: 9191, NodeRole: "master", Service: "machine-approver", Namespace: "machine-approver", @@ -386,9 +386,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "machine-approver-controller", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "6385", + Port: 6385, NodeRole: "master", Service: "", Namespace: "openshift-machine-api", @@ -396,9 +396,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "ironic-proxy", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "29445", + Port: 29445, NodeRole: "master", Service: "haproxy-openshift-dsn", Namespace: "", @@ -406,9 +406,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: true, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "18080", + Port: 18080, NodeRole: "master", Service: "openshift-kni-infra-coredns", Namespace: "openshift-kni-infra", @@ -416,9 +416,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ Container: "coredns", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "9447", + Port: 9447, NodeRole: "master", Service: "baremetal-operator-webhook-baremetal provisioning", Namespace: "", @@ -430,9 +430,9 @@ var baremetalStaticEntriesMaster = []types.ComDetails{ var awsCloudStaticEntriesWorker = []types.ComDetails{ { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10304", + Port: 10304, NodeRole: "worker", Service: "csi-node-driver", Namespace: "", @@ -440,9 +440,9 @@ var awsCloudStaticEntriesWorker = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10300", + Port: 10300, NodeRole: "worker", Service: "csi-livenessprobe", Namespace: "", @@ -454,9 +454,9 @@ var awsCloudStaticEntriesWorker = []types.ComDetails{ var awsCloudStaticEntriesMaster = []types.ComDetails{ { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "8080", + Port: 8080, NodeRole: "master", Service: "cluster-network", Namespace: "", @@ -464,9 +464,9 @@ var awsCloudStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10260", + Port: 10260, NodeRole: "master", Service: "aws-cloud-controller", Namespace: "", @@ -474,9 +474,9 @@ var awsCloudStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10258", + Port: 10258, NodeRole: "master", Service: "aws-cloud-controller", Namespace: "", @@ -484,9 +484,9 @@ var awsCloudStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10304", + Port: 10304, NodeRole: "master", Service: "csi-node-driver", Namespace: "", @@ -494,9 +494,9 @@ var awsCloudStaticEntriesMaster = []types.ComDetails{ Container: "", Optional: false, }, { - Direction: "ingress", + Direction: "Ingress", Protocol: "TCP", - Port: "10300", + Port: 10300, NodeRole: "master", Service: "csi-livenessprobe", Namespace: "", @@ -510,7 +510,7 @@ var MNOStaticEntries = []types.ComDetails{ { Direction: "ingress", Protocol: "UDP", - Port: "6081", + Port: 6081, NodeRole: "worker", Service: "ovn-kubernetes geneve", Namespace: "openshift-ovn-kubernetes", @@ -520,7 +520,7 @@ var MNOStaticEntries = []types.ComDetails{ }, { Direction: "ingress", Protocol: "UDP", - Port: "6081", + Port: 6081, NodeRole: "master", Service: "ovn-kubernetes geneve", Namespace: "openshift-ovn-kubernetes", diff --git a/consts/consts.go b/consts/consts.go index 4a0155e..d115fa5 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 6f52221..e668dde 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -106,7 +106,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 k8serrors.IsNotFound(getErr) { return false, getErr } diff --git a/endpointslices/endpointslices.go b/endpointslices/endpointslices.go index b7ca07d..274d35d 100644 --- a/endpointslices/endpointslices.go +++ b/endpointslices/endpointslices.go @@ -230,7 +230,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 060fea8..a881c1a 100644 --- a/ss/ss.go +++ b/ss/ss.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "regexp" + "strconv" "strings" "time" @@ -188,7 +189,13 @@ func parseComDetail(ssEntry string) *types.ComDetails { 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 { + log.Debugf(err.Error()) + return nil + } return &types.ComDetails{ Direction: consts.IngressLabel, diff --git a/types/types.go b/types/types.go index cfa46bd..f7d6caf 100644 --- a/types/types.go +++ b/types/types.go @@ -2,9 +2,11 @@ package types import ( "bytes" + "cmp" "encoding/csv" "encoding/json" "fmt" + "slices" "strings" "sigs.k8s.io/yaml" @@ -17,7 +19,7 @@ type ComMatrix struct { type ComDetails struct { Direction string `json:"direction"` Protocol string `json:"protocol"` - Port string `json:"port"` + Port int `json:"port"` Namespace string `json:"namespace"` Service string `json:"service"` Pod string `json:"pod"` @@ -27,7 +29,7 @@ type ComDetails struct { } 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,26 +80,40 @@ 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 { +func CleanComDetails(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) } } + slices.SortFunc(res, func(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) + }) + return res } 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 } From b3e04e6ffae606aebff7b8356c2f0c34c55b3a4a Mon Sep 17 00:00:00 2001 From: Sabina Aledort Date: Thu, 9 May 2024 10:17:00 +0300 Subject: [PATCH 2/5] Clean main, seperate diff to a func --- cmd/main.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index b1a224e..1a746c7 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -171,26 +171,32 @@ func main() { panic(err) } + diff := buildMatrixDiff(*mat, ssComMat) + + err = os.WriteFile(filepath.Join(destDir, "matrix-diff-ss"), + []byte(diff), + 0644) + if err != nil { + panic(err) + } +} + +func buildMatrixDiff(mat1 types.ComMatrix, mat2 types.ComMatrix) string { diff := "" - for _, cd := range mat.Matrix { - if ssComMat.Contains(cd) { + for _, cd := range mat1.Matrix { + if mat2.Contains(cd) { diff += fmt.Sprintf("%s\n", cd) continue } + diff += fmt.Sprintf("+ %s\n", cd) } - for _, cd := range ssComMat.Matrix { - if !mat.Contains(cd) { + for _, cd := range mat2.Matrix { + if !mat1.Contains(cd) { diff += fmt.Sprintf("- %s\n", cd) - continue } } - err = os.WriteFile(filepath.Join(destDir, "matrix-diff-ss"), - []byte(diff), - 0644) - if err != nil { - panic(err) - } + return diff } From 897de9d5f7b4b4ed0c2b3f1e27bbbd4d1475e77c Mon Sep 17 00:00:00 2001 From: Sabina Aledort Date: Thu, 9 May 2024 10:17:24 +0300 Subject: [PATCH 3/5] Update debug pod image to a more generic image --- consts/consts.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/consts/consts.go b/consts/consts.go index d115fa5..61ebb4d 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -7,6 +7,5 @@ const ( OptionalTrue = "true" RoleLabel = "node-role.kubernetes.io/" DefaultDebugNamespace = "openshift-commatrix-debug" - // TODO: change the image. - DefaultDebugPodImage = "quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:535ce24b5f1894d2a07bfa7eed7ad028ffde0659693f2a571ac4712a21cd028c" + DefaultDebugPodImage = "quay.io/openshift-release-dev/ocp-release:4.15.12-multi" ) From f7c7a133ced273fcf4470555e4f56d615fa70c38 Mon Sep 17 00:00:00 2001 From: Sabina Aledort Date: Sun, 12 May 2024 16:21:28 +0300 Subject: [PATCH 4/5] matrix-diff-ss: skip rpc.statd ports, known optional service --- cmd/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index 1a746c7..e0e4181 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -193,6 +193,12 @@ func buildMatrixDiff(mat1 types.ComMatrix, mat2 types.ComMatrix) string { } for _, cd := range mat2.Matrix { + // Skip "rpc.statd" ports, these are randomly open ports on the node, + // no need to mention them in the matrix diff + if cd.Service == "rpc.statd" { + continue + } + if !mat1.Contains(cd) { diff += fmt.Sprintf("- %s\n", cd) } From b3c00993bf676349d6a4432ebd8d81465b88aa10 Mon Sep 17 00:00:00 2001 From: Sabina Aledort Date: Wed, 22 May 2024 15:24:07 +0300 Subject: [PATCH 5/5] Add headers to matrix-diff-ss file --- cmd/main.go | 2 +- consts/consts.go | 1 + types/types.go | 5 ++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index e0e4181..70ea6cf 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -182,7 +182,7 @@ func main() { } func buildMatrixDiff(mat1 types.ComMatrix, mat2 types.ComMatrix) string { - diff := "" + diff := consts.CSVHeaders + "\n" for _, cd := range mat1.Matrix { if mat2.Contains(cd) { diff += fmt.Sprintf("%s\n", cd) diff --git a/consts/consts.go b/consts/consts.go index 61ebb4d..76a6a7f 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -8,4 +8,5 @@ const ( RoleLabel = "node-role.kubernetes.io/" DefaultDebugNamespace = "openshift-commatrix-debug" DefaultDebugPodImage = "quay.io/openshift-release-dev/ocp-release:4.15.12-multi" + CSVHeaders = "Direction,Protocol,Port,Namespace,Service,Pod,Container,Node Role,Optional" ) diff --git a/types/types.go b/types/types.go index f7d6caf..e6ea1a4 100644 --- a/types/types.go +++ b/types/types.go @@ -9,6 +9,7 @@ import ( "slices" "strings" + "github.com/openshift-kni/commatrix/consts" "sigs.k8s.io/yaml" ) @@ -29,13 +30,11 @@ type ComDetails struct { } func ToCSV(m ComMatrix) ([]byte, error) { - var header = "Direction,Protocol,Port,Namespace,Service,Pod,Container,Node Role,Optional" - out := make([]byte, 0) w := bytes.NewBuffer(out) csvwriter := csv.NewWriter(w) - err := csvwriter.Write(strings.Split(header, ",")) + err := csvwriter.Write(strings.Split(consts.CSVHeaders, ",")) if err != nil { return nil, fmt.Errorf("failed to write to CSV: %w", err) }