Repository navigation
fix: fix container list #13988
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
Closed
+1,144
−374
Closed
fix: fix container list #13988
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9319f18
fix: fix container list
xiaomeinvG 0bfde3d
fix: fix operation log (#13989)
xiaomeinvG 6e44a98
fix: fix log text (#13990)
xiaomeinvG 3c52829
fix(ssh): validate imported key pairs and cancel stale file reads (#1…
ssongliu 9352b39
refactor: search bind (#13992)
xiaomeinvG 3e7d36e
fix: fix clean network
xiaomeinvG c328242
fix: fix clean network
xiaomeinvG 12d311d
fix: fix container list
xiaomeinvG 1ebe71c
fix: fix clean network
xiaomeinvG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package dto | ||
|
|
||
| type NetworkCleanupReport struct { | ||
| Deleted []NetworkCleanupItem `json:"deleted"` | ||
| Skipped []NetworkCleanupItem `json:"skipped"` | ||
| Failed []NetworkCleanupItem `json:"failed"` | ||
| } | ||
|
|
||
| type NetworkCleanupItem struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Reason string `json:"reason,omitempty"` | ||
| } | ||
|
|
||
| type NetworkCleanupTask struct { | ||
| TaskID string `json:"taskID"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sync" | ||
|
|
||
| "github.com/1Panel-dev/1Panel/agent/app/dto" | ||
| "github.com/1Panel-dev/1Panel/agent/app/task" | ||
| "github.com/1Panel-dev/1Panel/agent/global" | ||
| "github.com/1Panel-dev/1Panel/agent/i18n" | ||
| "github.com/1Panel-dev/1Panel/agent/utils/docker" | ||
| ) | ||
|
|
||
| var networkCleanupMu sync.Mutex | ||
|
|
||
| func (u *ContainerService) CleanNetworks() (*dto.NetworkCleanupTask, error) { | ||
| taskItem, err := task.NewTaskWithOps(i18n.GetMsgByKey("Network"), task.TaskClean, task.TaskScopeContainer, "", 0) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| taskItem.AddSubTask(i18n.GetMsgByKey("TaskClean"), func(t *task.Task) error { | ||
| networkCleanupMu.Lock() | ||
| defer networkCleanupMu.Unlock() | ||
| if err := t.TaskCtx.Err(); err != nil { | ||
| return err | ||
| } | ||
| cli, err := docker.NewDockerClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer cli.Close() | ||
| return executeNetworkCleanup(t, cli) | ||
| }, nil) | ||
| go func() { | ||
| if err := taskItem.Execute(); err != nil { | ||
| global.LOG.Errorf("network cleanup task %s failed: %v", taskItem.TaskID, err) | ||
| } | ||
| }() | ||
| return &dto.NetworkCleanupTask{TaskID: taskItem.TaskID}, nil | ||
| } | ||
|
|
||
| func executeNetworkCleanup(t *task.Task, cli docker.NetworkCleanupClient) error { | ||
| t.Log(i18n.GetMsgByKey("PruneStart")) | ||
| report, err := docker.CleanUnusedNetworks(t.TaskCtx, cli, func(status string, item dto.NetworkCleanupItem) { | ||
| key := "NetworkCleanupDeleted" | ||
| if status == "skipped" || status == "failed" { | ||
| key = map[string]string{ | ||
| "protected": "NetworkCleanupProtected", | ||
| "container_connected": "NetworkCleanupConnected", | ||
| "network_in_use": "NetworkCleanupConnected", | ||
| "unsupported_network": "NetworkCleanupUnsupported", | ||
| "already_removed": "NetworkCleanupGone", | ||
| "inspect_failed": "NetworkCleanupInspectFailed", | ||
| "remove_failed": "NetworkCleanupRemoveFailed", | ||
| }[item.Reason] | ||
| } | ||
| t.Log(i18n.GetMsgWithMap(key, map[string]interface{}{"name": item.Name, "id": item.ID})) | ||
| }) | ||
| if report != nil { | ||
| t.Log(i18n.GetMsgWithMap("NetworkCleanupSummary", map[string]interface{}{ | ||
| "deleted": len(report.Deleted), "skipped": len(report.Skipped), "failed": len(report.Failed), | ||
| })) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if len(report.Failed) > 0 { | ||
| return fmt.Errorf("%s", i18n.GetMsgByKey("NetworkCleanupPartialFailure")) | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是多余的,应该干掉