feat: Add Node File Exchange#8407
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| <-doneCh | ||
|
|
||
| return err | ||
| } |
There was a problem hiding this comment.
The provided code modifications are mostly clean and optimized. Here are some minor points:
- The function
makePrivateKeySignerremains unchanged, so no specific review is needed.
Regarding the RunWithStreamOutput method:
2. It creates an SSH session and pipes its standard input/output/error streams to separate goroutines for reading output.
3. A buffered channel (stdoutCh, stderrCh) is used to collect output data from both streams concurrently.
4. The output callback function is called with any text read from either stream whenever available.
5. The session waits for completion before closing the sessions, ensuring all processes and resources are properly finalized.
6. Error handling has been added around each step of setting up and running the command, providing clear failure messages if something goes wrong.
Overall, this method efficiently handles streaming output from an SSH command, making it suitable for applications that need to process or monitor command outputs.
| for scanner.Scan() { | ||
| callback(scanner.Text()) | ||
| } | ||
| } |
There was a problem hiding this comment.
The provided code snippet includes several improvements over its initial version:
-
Imports: The
importstatements were separated into sections for readability and clarity. -
Functionality Enhancement:
- Added
ExecWithStreamOutputfunction that takes a command string and an output callback function. - Implements streaming of standard output and error using
bufio.Scanner.
- Added
-
Error Handling:
- Used proper error handling techniques across different parts of the functions to ensure robustness.
-
Code Structure:
- Cleaned up comments for better documentation and added spacing between lines for clearer separation of concerns.
Here's a summary of the changes with minor formatting adjustments:
package cmd
import (
" bufio"
"fmt"
"io"
"os/exec"
)
// Which checks if a given program is available in the system path.
func Which(name string) bool {
out, err := exec.LookPath(name)
if err == os.ErrNotExist {
return false
}
return true
}
// ExecWithStreamOutput executes a shell command and streams both standard output and standard error to the specified callback function.
func ExecWithStreamOutput(command string, outputCallback func(string)) error {
cmd := exec.Command("bash", "-c", command)
stdout, err := cmd.StdoutPipe()
if err != nil {
return fmt.Errorf("failed to get stdout: %w", err)
}
stderr, err := cmd.StderrPipe()
if err != nil {
return fmt.Errorf("failed to get stderr: %w", err)
}
if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to start command: %w", err)
}
go streamReader(stdout, outputCallback)
go streamReader(stderr, outputCallback)
if err := cmd.Wait(); err != nil {
return fmt.Errorf("command finished with error: %w", err)
}
return nil
}
func streamReader(reader io.ReadCloser, callback func(string)) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
callback(scanner.Text())
}
}These enhancements improve the functionality, maintainability, and performance of the cmd module while addressing potential issues related to command execution and output processing.
| } | ||
| } | ||
| loading.value = true; | ||
| Promise.all(pros) |
There was a problem hiding this comment.
The code appears to have several improvements that enhance usability and maintainability:
-
Loading Indicator: A
v-loadingdirective is added around the content of the<div>, which can help indicate when data retrieval operations are in progress. -
Dynamic Node Parameter Handling: The
acceptParamsfunction now accepts an additionalnodeparameter, allowing dynamic selection of nodes for deletion. -
Error Handling Cleanup: In the
getStatusmethod, error handling was removed entirely except for setting theloadingback tofalse. This ensures consistent behavior even with errors occur, improving robustness. -
Refactor Deletion Functions: The
onConfirmmethod checks if a node ID (reqNode) is provided before using it during file deletion. If no node is specified, it defaults to callingdeleteFile.
These changes make the component more versatile, responsive, and easier to maintain.
|


Refs #3895