Skip to content

feat: Add the cleaning of the execution script #8540

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

Merged
merged 1 commit into from
May 4, 2025

Conversation

ssongliu
Copy link
Member

@ssongliu ssongliu commented May 4, 2025

No description provided.

Copy link

f2c-ci-robot bot commented May 4, 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.

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.

Copy link

f2c-ci-robot bot commented May 4, 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 ssongliu. For more information see the Kubernetes Code Review Process.

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

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

path3 := path.Join(global.Dir.TmpDir, "script")
list3 := loadTreeWithAllFile(true, path3, "script", path3, fileOp)
size3, _ := fileOp.GetDirSize(path3)
treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "script", Size: uint64(size3), Children: list3, Type: "script", IsRecommend: true})
return treeData
}

Copy link
Member

Choose a reason for hiding this comment

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

There appear to be several issues and optimizations related to the code provided:

  1. Repetition of Logic for Script Directory:

    case "script":
        dropFileOrDir(path.Join(global.Dir.TmpDir, "script", item.Name))

    This logic is repeated in another location without considering optimization opportunities.

  2. Missing Code for Removing Images from Disk:
    The function cleanImage seems to be responsible for removing images from disk, but it's not referenced anywhere in the cleaned version.

  3. Potential Overhead with Large Directories:
    Loading directories recursively can lead to performance bottlenecks if dealing with very large files or directories.

  4. Consistent Use of Variables:
    It might be more efficient to use consistent variable names within the clean function rather than repeating variable definitions like twice in this snippet:

    var filePath string
    switch itemType {
    case "container":
        containerName := req[i]
        filePath = pathJoin(global.Directory.Container, containerName+".png")

5. **Comments and Readability**:
   Adding comments explaining each section of the code could enhance its readability and maintainability.

6. **Security Considerations**:
   Ensure that there are no security vulnerabilities exposed by passing paths directly to certain functions such as `dropFileOrDir`.

Here are some suggested changes:

```go

func Clean(req []dto.CleanRequest) error {
    logTreeItems := make([]dto.LogTree, 0)

    // Load data for different types of items using separate helper functions
    logTreeItems = append(logTreeItems, loadTaskLogTree())
    logTreeItems = append(logTreeItems, loadImageTrees())
    logTreeItems = append(logTreeItems, loadContainerTrees())

    return nil
}

// Helper functions to load tree items

func loadTaskLogTree() []dto.LogTree {
    list1 := loadTreeWithDir(false, "task_log", global.Dir.TaskLogFolder...)
    size1 := calculateDirSize(global.Dir.TaskLogFolder...) // Assume a method to compute directory size
    return []dto.LogTree{
        {ID: id.String(), Label: "task_log", Size: size1, Children: list1, Type: "task_log"},
    }
}

In this version:

  • A new structure CleanRequest replaces []dto.Clean.
  • Several utility methods (loadLoadTree, etc.) have been introduced for each type of cleanup operation.
  • Comments explain the purpose of each part.
  • Security considerations should also be reviewed when integrating actual file operations into a production system.

@@ -632,6 +632,8 @@ function load18n(label: string) {
return i18n.global.t('clean.directory');
case 'system_log':
return i18n.global.t('clean.systemLog');
case 'script':
return i18n.global.t('cronjob.library.script');
case 'docker_log':
return i18n.global.t('clean.dockerLog');
case 'task_log':
Copy link
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 seems to be part of an internationalization (i18n) function used within a TypeScript/JavaScript application. There are no specific errors or issues in this code as-is, but there is a suggestion for potential improvement:

@@ -632,7 +632,9 @@ function load18n(label: string) {
     switch (label) {
         case 'clean.directory':
             return i18n.global.t('clean.directory');
         case 'system_log':
             return i18n.global.t('clean.systemLog');
+        case 'script':
+            // If you want to make it more specific, consider using a variable
+            let scriptTranslationKey = '';
+            if (context && context.type === 'cronjob') { // Example condition based on additional logic
+                scriptTranslationKey = 'cronjob.library.script';
+            } else {
+                scriptTranslationKey = 'library.script'; // Default key if not a cronjob
+            }
             return i18n.global.t(scriptTranslationKey);
         case 'docker_log':
             return i18n.global.t('clean.dockerLog');

Copy link

sonarqubecloud bot commented May 4, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@wanghe-fit2cloud wanghe-fit2cloud merged commit 3533eed into dev-v2 May 4, 2025
4 of 6 checks passed
@wanghe-fit2cloud wanghe-fit2cloud deleted the pr@dev-v2@fix_device_clean branch May 4, 2025 13:20
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