Skip to content

Commit

Permalink
Merge pull request #5 from sabinaaledort/sort_commatrix
Browse files Browse the repository at this point in the history
Sort commatrix by node role, protocol and port
  • Loading branch information
sabinaaledort authored May 29, 2024
2 parents fb1b862 + b3c0099 commit d97ed0f
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 127 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
38 changes: 25 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -171,26 +171,38 @@ func main() {
panic(err)
}

diff := ""
for _, cd := range mat.Matrix {
if ssComMat.Contains(cd) {
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 := consts.CSVHeaders + "\n"
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) {
diff += fmt.Sprintf("- %s\n", cd)
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
}
}

err = os.WriteFile(filepath.Join(destDir, "matrix-diff-ss"),
[]byte(diff),
0644)
if err != nil {
panic(err)
if !mat1.Contains(cd) {
diff += fmt.Sprintf("- %s\n", cd)
}
}

return diff
}
2 changes: 1 addition & 1 deletion commatrix/commatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit d97ed0f

Please sign in to comment.