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

Allow setting custom-entries-file in formats #7

Merged

Conversation

liornoy
Copy link
Contributor

@liornoy liornoy commented May 6, 2024

This commit adds the the flag customEntriesFormat that sets the custom entries file format (json/yaml/csv).

We also include 3 example files to help the user to create his own custom file, and they'll be used in the integration test.

@liornoy liornoy force-pushed the allow-setting-different-formats branch from 4e87c4a to 5cabd78 Compare May 6, 2024 10:06
@@ -34,7 +37,7 @@ const (
// Custom entries from a JSON file can be added to the matrix by setting `customEntriesPath`.
// Returns a pointer to ComMatrix and error. Entries include traffic direction, protocol,
// port number, namespace, service name, pod, container, node role, and flow optionality for OpenShift.
func New(kubeconfigPath string, customEntriesPath string, e Env, d Deployment) (*types.ComMatrix, error) {
func New(kubeconfigPath string, customEntriesPath string, customEntriesFormat string, e Env, d Deployment) (*types.ComMatrix, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customEntriesFormat should be an enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, the flag still accepts string, but internally it's validated as an enum

@@ -61,7 +64,10 @@ func New(kubeconfigPath string, customEntriesPath string, e Env, d Deployment) (
res = append(res, staticEntries...)

if customEntriesPath != "" {
customComDetails, err := addFromFile(customEntriesPath)
if customEntriesFormat == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be validated in main

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -51,7 +51,7 @@ func ToCSV(m ComMatrix) ([]byte, error) {
}

func ToJSON(m ComMatrix) ([]byte, error) {
out, err := json.Marshal(m.Matrix)
out, err := json.MarshalIndent(m.Matrix, "", " ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the output more readable with tabs and newlines instead of one long string

@liornoy liornoy force-pushed the allow-setting-different-formats branch from 5cabd78 to cf44110 Compare May 8, 2024 09:20
@liornoy liornoy force-pushed the allow-setting-different-formats branch from cf44110 to 763423e Compare May 22, 2024 06:14
@liornoy liornoy force-pushed the allow-setting-different-formats branch from 763423e to ec1657b Compare June 16, 2024 11:31
This commit adds the the flag customEntriesFormat that sets the custom
entries file format (json/yaml/csv).

We also include 3 example files to help the user to create his own custom
file, and they'll be used in the integration test.

Signed-off-by: Lior Noy <[email protected]>
@liornoy liornoy force-pushed the allow-setting-different-formats branch from ec1657b to fa17b99 Compare June 16, 2024 11:35
@sabinaaledort sabinaaledort merged commit 5d707fe into openshift-kni:main Jun 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants