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

Use os.open function for reading files. #95

Closed

Conversation

Tatsinnit
Copy link
Member

@Tatsinnit Tatsinnit commented Aug 6, 2021

This PR kind of closes all the discussion where it was recommended not to use RunCommandOnHost for things like cat for file because that can be easily done at via os.Open which open files. Much better and reduces over-use of RunCommandonHost.

  • Test with this image: docker.io/tatsat/redundant-runcommand-use

Thanks.

@Tatsinnit Tatsinnit self-assigned this Aug 6, 2021
@@ -24,7 +24,7 @@ func (collector *DNSCollector) GetName() string {
func (collector *DNSCollector) Collect() error {
result := make(map[string]string)

output, err := utils.RunCommandOnHost("cat", "/etc/resolv.conf")
output, err := utils.ReadFileContent("/etc/resolv.conf")
Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous command was running on the host, this one will run on the container. Is it working as expected or should we have a mount to do that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, so they are already there: docker.io/tatsat/redundant-runcommand-use image shows the correct log.

@@ -29,13 +29,12 @@ func (collector *NodeLogsCollector) Collect() error {

for _, nodeLog := range nodeLogs {

output, err := utils.RunCommandOnHost("cat", nodeLog)
output, err := utils.ReadFileContent(nodeLog)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@Tatsinnit
Copy link
Member Author

💡 FYI: closing this in favour for this PR: #109 - it makes sense to do this individually at the each collector level when adding tests. Which will lead to better progress. Thanks heaps.

@Tatsinnit Tatsinnit closed this Sep 2, 2021
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