Skip to content

Commit

Permalink
build(deps): 更新 github.com/weibaohui/kom 依赖至 v0.0.15- 将 github.com/we…
Browse files Browse the repository at this point in the history
…ibaohui/kom 依赖版本从 v0.0.14 升级到 v0.0.15

- 优化 pod 日志获取逻辑,使用新的 GetLogs 方法
- 修复 pod 文件相关操作中的 Poder 方法调用
  • Loading branch information
weibaohui committed Nov 1, 2024
1 parent 2434f0a commit 6c4963b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/sashabaranov/go-openai v1.32.2
github.com/spf13/pflag v1.0.5
github.com/weibaohui/kom v0.0.14
github.com/weibaohui/kom v0.0.15
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/weibaohui/kom v0.0.14 h1:4UwpqKxsMDoAPFvFaWOZCNGhRBE+yz01DN9kriodPQM=
github.com/weibaohui/kom v0.0.14/go.mod h1:OauDGb387+wW44uGraJRVw+MYBWVjYrnAwdAX/5tqkM=
github.com/weibaohui/kom v0.0.15 h1:H0UYK63X1COhb4Vb5naNHhDqIUG9ZhudcYBK4zqPJ6Y=
github.com/weibaohui/kom v0.0.15/go.mod h1:OauDGb387+wW44uGraJRVw+MYBWVjYrnAwdAX/5tqkM=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
20 changes: 10 additions & 10 deletions pkg/controller/pod/pod_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func FileList(c *gin.Context) {
return
}
ctx := c.Request.Context()
poder := kom.DefaultCluster().WithContext(ctx).Poder().
poder := kom.DefaultCluster().WithContext(ctx).
Namespace(info.Namespace).
Name(info.PodName).
ContainerName(info.ContainerName)
ContainerName(info.ContainerName).Poder()

if info.Path == "" {
info.Path = "/"
Expand All @@ -60,10 +60,10 @@ func ShowFile(c *gin.Context) {
}

ctx := c.Request.Context()
poder := kom.DefaultCluster().WithContext(ctx).Poder().
poder := kom.DefaultCluster().WithContext(ctx).
Namespace(info.Namespace).
Name(info.PodName).
ContainerName(info.ContainerName)
ContainerName(info.ContainerName).Poder()
if info.FileType != "" && info.FileType != "file" && info.FileType != "directory" {
amis.WriteJsonError(c, fmt.Errorf("无法查看%s类型文件", info.FileType))
return
Expand Down Expand Up @@ -106,10 +106,10 @@ func SaveFile(c *gin.Context) {
}

ctx := c.Request.Context()
poder := kom.DefaultCluster().WithContext(ctx).Poder().
poder := kom.DefaultCluster().WithContext(ctx).
Namespace(info.Namespace).
Name(info.PodName).
ContainerName(info.ContainerName)
ContainerName(info.ContainerName).Poder()

if info.Path == "" {
amis.WriteJsonOK(c)
Expand Down Expand Up @@ -145,10 +145,10 @@ func DownloadFile(c *gin.Context) {
}

ctx := c.Request.Context()
poder := kom.DefaultCluster().WithContext(ctx).Poder().
poder := kom.DefaultCluster().WithContext(ctx).
Namespace(info.Namespace).
Name(info.PodName).
ContainerName(info.ContainerName)
ContainerName(info.ContainerName).Poder()
// 从容器中下载文件
fileContent, err := poder.DownloadFile(info.Path)
if err != nil {
Expand Down Expand Up @@ -184,10 +184,10 @@ func UploadFile(c *gin.Context) {
info.FileName = utils.SanitizeFileName(info.FileName)

ctx := c.Request.Context()
poder := kom.DefaultCluster().WithContext(ctx).Poder().
poder := kom.DefaultCluster().WithContext(ctx).
Namespace(info.Namespace).
Name(info.PodName).
ContainerName(info.ContainerName)
ContainerName(info.ContainerName).Poder()

// 获取上传的文件
file, _, err := c.Request.FormFile("file")
Expand Down
7 changes: 3 additions & 4 deletions pkg/service/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func (p *PodService) StreamPodLogs(ctx context.Context, ns, name string, logOpti
if logOptions.SinceSeconds != nil && *logOptions.SinceSeconds == 0 {
logOptions.SinceSeconds = nil
}
var stream io.ReadCloser
err := kom.DefaultCluster().WithContext(ctx).Namespace(ns).Name(name).ContainerName(logOptions.Container).GetLogs(&stream, logOptions).Error

podLogs := kom.DefaultCluster().WithContext(ctx).Poder().Namespace(ns).Name(name).GetLogs(name, logOptions)
logStream, err := podLogs.Stream(ctx)

return logStream, err
return stream, err
}

0 comments on commit 6c4963b

Please sign in to comment.