Skip to content

Commit

Permalink
remove createSSOutputFiles function and add new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
aabughosh committed Jul 22, 2024
1 parent a3a9c70 commit 81608ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
// write the endpoint slice matrix to file
err = commatrix.WriteMatrixToFileByType(*mat, "communication-matrix", format, deployment, destDir)
if err != nil {
panic(fmt.Sprintf("Error while the endpoint slice matrix to file :%v", err))
panic(fmt.Sprintf("Error while writing the endpoint slice matrix to file :%v", err))
}
// generate the ss matrix and ss raws
ssMat, ssOutTCP, ssOutUDP, err := commatrix.GenerateSS(kubeconfig, customEntriesPath, customEntriesFormat, format, env, deployment, destDir)
Expand Down
19 changes: 8 additions & 11 deletions commatrix/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func GenerateSS(kubeconfig, customEntriesPath, customEntriesFormat, format strin
if err != nil {
return nil, nil, nil, err
}

cleanedComDetails := types.CleanComDetails(nodesComDetails)
ssComMat := types.ComMatrix{Matrix: cleanedComDetails}
return &ssComMat, ssOutTCP, ssOutUDP, nil
Expand All @@ -97,32 +98,26 @@ func getPrintFunction(format string) (func(m types.ComMatrix) ([]byte, error), e
}
}

func createSSOutputFiles(destDir string) (*os.File, *os.File, error) {
func WriteSSRawFiles(destDir string, ssOutTCP, ssOutUDP []byte) error {
tcpFile, err := os.OpenFile(path.Join(destDir, "raw-ss-tcp"), os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, nil, err
return err
}

udpFile, err := os.OpenFile(path.Join(destDir, "raw-ss-udp"), os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
tcpFile.Close()
return nil, nil, err
}

return tcpFile, udpFile, nil
}

func WriteSSRawFiles(destDir string, ssOutTCP, ssOutUDP []byte) error {
tcpFile, udpFile, err := createSSOutputFiles(destDir)
if err != nil {
return err
}

defer tcpFile.Close()
defer udpFile.Close()

_, err = tcpFile.Write([]byte(string(ssOutTCP)))
if err != nil {
return fmt.Errorf("failed writing to file: %s", err)
}

_, err = udpFile.Write([]byte(string(ssOutUDP)))
if err != nil {
return fmt.Errorf("failed writing to file: %s", err)
Expand All @@ -136,6 +131,7 @@ func WriteMatrixToFileByType(mat types.ComMatrix, fileNamePrefix, format string,
if err != nil {
return err
}

if format == types.FormatNFT {
masterMatrix, workerMatrix := separateMatrixByRole(mat)
err := writeMatrixToFile(masterMatrix, fileNamePrefix+"-master", format, printFn, destDir)
Expand All @@ -154,6 +150,7 @@ func WriteMatrixToFileByType(mat types.ComMatrix, fileNamePrefix, format string,
return err
}
}

return nil
}

Expand Down

0 comments on commit 81608ae

Please sign in to comment.