From b3c00993bf676349d6a4432ebd8d81465b88aa10 Mon Sep 17 00:00:00 2001 From: Sabina Aledort Date: Wed, 22 May 2024 15:24:07 +0300 Subject: [PATCH] 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) }