add option 'follow'

This commit is contained in:
GLYASAI 2021-08-04 16:07:05 +08:00
parent 91328771d6
commit 0a529f8d06
4 changed files with 7 additions and 7 deletions

View File

@ -23,6 +23,7 @@ import (
"io/ioutil"
"net/http"
"os"
"strconv"
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/handler"
@ -778,8 +779,9 @@ func (t *TenantStruct) Log(w http.ResponseWriter, r *http.Request) {
component := r.Context().Value(ctxutil.ContextKey("service")).(*dbmodel.TenantServices)
podName := r.URL.Query().Get("podName")
containerName := r.URL.Query().Get("containerName")
follow, _ := strconv.ParseBool(r.URL.Query().Get("follow"))
err := handler.GetServiceManager().Log(w, r, component, podName, containerName)
err := handler.GetServiceManager().Log(w, r, component, podName, containerName, follow)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return

View File

@ -2910,7 +2910,7 @@ func (s *ServiceAction) SyncComponentEndpoints(tx *gorm.DB, components []*api_mo
}
// Log returns the logs reader for a container in a pod, a pod or a component.
func (s *ServiceAction) Log(w http.ResponseWriter, r *http.Request, component *dbmodel.TenantServices, podName, containerName string) error {
func (s *ServiceAction) Log(w http.ResponseWriter, r *http.Request, component *dbmodel.TenantServices, podName, containerName string, follow bool) error {
// If podName and containerName is missing, return the logs reader for the component
// If containerName is missing, return the logs reader for the pod.
if podName == "" || containerName == "" {
@ -2920,7 +2920,7 @@ func (s *ServiceAction) Log(w http.ResponseWriter, r *http.Request, component *d
request := s.kubeClient.CoreV1().Pods(component.TenantID).GetLogs(podName, &corev1.PodLogOptions{
Container: containerName,
Follow: true,
Follow: follow,
})
out, err := request.Stream(context.TODO())

View File

@ -104,5 +104,5 @@ type ServiceHandler interface {
SyncComponentScaleRules(tx *gorm.DB, components []*api_model.Component) error
SyncComponentEndpoints(tx *gorm.DB, components []*api_model.Component) error
Log(w http.ResponseWriter, r *http.Request, component *dbmodel.TenantServices, podName, containerName string) error
Log(w http.ResponseWriter, r *http.Request, component *dbmodel.TenantServices, podName, containerName string, follow bool) error
}

View File

@ -12,7 +12,5 @@ var (
ErrSyncOperation = newByMessage(409, 10103, "The asynchronous operation is executing")
// ErrHorizontalDueToNoChange
ErrHorizontalDueToNoChange = newByMessage(400, 10104, "The number of components has not changed, no need to scale")
ErrReadComponentLogs = newByMessage(400, 10105, "Failed to read the component log from reader")
ErrWriteComponentLogs = newByMessage(400, 10106, "Failed to write the component log to the streaming response")
ErrPodNotFound = newByMessage(404, 10107, "pod not found")
ErrPodNotFound = newByMessage(404, 10105, "pod not found")
)