Skip to content

feat: Add Node File Exchange#8407

Merged
wanghe-fit2cloud merged 1 commit intodev-v2from
pr@dev-v2@common
Apr 16, 2025
Merged

feat: Add Node File Exchange#8407
wanghe-fit2cloud merged 1 commit intodev-v2from
pr@dev-v2@common

Conversation

@zhengkunwang223
Copy link
Copy Markdown
Member

@zhengkunwang223 zhengkunwang223 commented Apr 16, 2025

Refs #3895

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 16, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 16, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from zhengkunwang223. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment thread core/utils/ssh/ssh.go
<-doneCh

return err
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The provided code modifications are mostly clean and optimized. Here are some minor points:

  1. The function makePrivateKeySigner remains 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.

Comment thread core/utils/cmd/cmd.go
for scanner.Scan() {
callback(scanner.Text())
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The provided code snippet includes several improvements over its initial version:

  1. Imports: The import statements were separated into sections for readability and clarity.

  2. Functionality Enhancement:

    • Added ExecWithStreamOutput function that takes a command string and an output callback function.
    • Implements streaming of standard output and error using bufio.Scanner.
  3. Error Handling:

    • Used proper error handling techniques across different parts of the functions to ensure robustness.
  4. 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code appears to have several improvements that enhance usability and maintainability:

  1. Loading Indicator: A v-loading directive is added around the content of the <div>, which can help indicate when data retrieval operations are in progress.

  2. Dynamic Node Parameter Handling: The acceptParams function now accepts an additional node parameter, allowing dynamic selection of nodes for deletion.

  3. Error Handling Cleanup: In the getStatus method, error handling was removed entirely except for setting the loading back to false. This ensures consistent behavior even with errors occur, improving robustness.

  4. Refactor Deletion Functions: The onConfirm method checks if a node ID (reqNode) is provided before using it during file deletion. If no node is specified, it defaults to calling deleteFile.

These changes make the component more versatile, responsive, and easier to maintain.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@wanghe-fit2cloud wanghe-fit2cloud merged commit dafeab8 into dev-v2 Apr 16, 2025
4 of 6 checks passed
@wanghe-fit2cloud wanghe-fit2cloud deleted the pr@dev-v2@common branch April 16, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants