We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
修改成下面这也才可以获取到 `package controllers
import ( "bytes" "encoding/json" "fmt" "io"
"github.com/astaxie/beego" core_v1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest"
)
type GetPodLog struct { beego.Controller }
type PodInfo struct { Podns string json:"podns" Podapp string json:"podapp" //ContainerName string json:"containername" }
json:"podns"
json:"podapp"
json:"containername"
func (c *GetPodLog) PodLog() { var ( clientset *kubernetes.Clientset //tailLines int64 req *rest.Request //res rest.Result //logs []byte err error )
podinfo := PodInfo{} data := c.Ctx.Input.RequestBody //json数据封装到user对象中 err = json.Unmarshal(data, &podinfo) if err != nil { fmt.Println("传入正确的JSON格式, err:", err.Error()) } podns := podinfo.Podns podapp := podinfo.Podapp //containername := podinfo.ContainerName // 初始化k8s客户端 if clientset, err = InitClient(); err != nil { fmt.Println(err.Error()) } // 生成获取POD日志请求 req = clientset.CoreV1().Pods(podns).GetLogs(podapp, &core_v1.PodLogOptions{}) // req.Stream()也可以实现Do的效果 podLogs, err := req.Stream() if err != nil { fmt.Println("error in opening stream") return } defer podLogs.Close() // 发送请求 buf := new(bytes.Buffer) _, err = io.Copy(buf, podLogs) if err != nil { fmt.Println("error in copy information from podLogs to buf") return } str := buf.String() fmt.Printf("容器-%s\tstdout日志:\n%s", podapp, str) c.Data["Email"] = str c.TplName = "test.html" c.Ctx.WriteString(str)
} `
The text was updated successfully, but these errors were encountered:
No branches or pull requests
修改成下面这也才可以获取到
`package controllers
import (
"bytes"
"encoding/json"
"fmt"
"io"
)
type GetPodLog struct {
beego.Controller
}
type PodInfo struct {
Podns string
json:"podns"
Podapp string
json:"podapp"
//ContainerName string
json:"containername"
}
func (c *GetPodLog) PodLog() {
var (
clientset *kubernetes.Clientset
//tailLines int64
req *rest.Request
//res rest.Result
//logs []byte
err error
)
}
`
The text was updated successfully, but these errors were encountered: