diff --git a/go.mod b/go.mod index d647742..80d74a9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a3eef28..f84180c 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/controller/pod/pod_file.go b/pkg/controller/pod/pod_file.go index 0ec8f9e..113884e 100644 --- a/pkg/controller/pod/pod_file.go +++ b/pkg/controller/pod/pod_file.go @@ -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 = "/" @@ -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 @@ -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) @@ -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 { @@ -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") diff --git a/pkg/service/pod.go b/pkg/service/pod.go index 7e4b1db..64584a6 100644 --- a/pkg/service/pod.go +++ b/pkg/service/pod.go @@ -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 }