Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort commatrix by node role, protocol and port #5

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading