From 0a529f8d066a08565ad88fd3fa48e957e6c388f6 Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Wed, 4 Aug 2021 16:07:05 +0800 Subject: [PATCH] add option 'follow' --- api/controller/service_action.go | 4 +++- api/handler/service.go | 4 ++-- api/handler/service_handler.go | 2 +- api/util/bcode/service.go | 4 +--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/controller/service_action.go b/api/controller/service_action.go index 957faef43..6cda6cb62 100644 --- a/api/controller/service_action.go +++ b/api/controller/service_action.go @@ -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 diff --git a/api/handler/service.go b/api/handler/service.go index 5b7a5b725..519c0c0ea 100644 --- a/api/handler/service.go +++ b/api/handler/service.go @@ -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()) diff --git a/api/handler/service_handler.go b/api/handler/service_handler.go index da904ca32..98a771a51 100644 --- a/api/handler/service_handler.go +++ b/api/handler/service_handler.go @@ -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 } diff --git a/api/util/bcode/service.go b/api/util/bcode/service.go index 25e3ddb8b..4cccee5ed 100644 --- a/api/util/bcode/service.go +++ b/api/util/bcode/service.go @@ -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") )