From a1e9989543e96a40bb49421df1208d2263de47a3 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Fri, 12 Jan 2024 13:29:18 +0530 Subject: [PATCH 01/24] wip --- .../application/k8sApplicationRestHandler.go | 115 +++++++++++++----- api/k8s/application/k8sApplicationRouter.go | 11 +- pkg/k8s/application/k8sApplicationService.go | 15 ++- 3 files changed, 107 insertions(+), 34 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 6edadf8fc48..a1a54be8a75 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -1,6 +1,8 @@ package application import ( + "bufio" + "bytes" "context" "encoding/json" "errors" @@ -26,6 +28,7 @@ import ( errors2 "github.com/juju/errors" "go.uber.org/zap" "gopkg.in/go-playground/validator.v9" + "io" errors3 "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "net/http" @@ -40,6 +43,7 @@ type K8sApplicationRestHandler interface { DeleteResource(w http.ResponseWriter, r *http.Request) ListEvents(w http.ResponseWriter, r *http.Request) GetPodLogs(w http.ResponseWriter, r *http.Request) + DownloadPodLogs(w http.ResponseWriter, r *http.Request) GetTerminalSession(w http.ResponseWriter, r *http.Request) GetResourceInfo(w http.ResponseWriter, r *http.Request) GetHostUrlsByBatch(w http.ResponseWriter, r *http.Request) @@ -607,6 +611,89 @@ func (handler *K8sApplicationRestHandlerImpl) GetPodLogs(w http.ResponseWriter, common.WriteJsonResp(w, err, nil, http.StatusBadRequest) return } + handler.requestValidationAndRBAC(w, r, token, request) + lastEventId := r.Header.Get("Last-Event-ID") + isReconnect := false + if len(lastEventId) > 0 { + lastSeenMsgId, err := strconv.ParseInt(lastEventId, 10, 64) + if err != nil { + common.WriteJsonResp(w, err, nil, http.StatusBadRequest) + return + } + lastSeenMsgId = lastSeenMsgId + 1 //increased by one ns to avoid duplicate + t := v1.Unix(0, lastSeenMsgId) + request.K8sRequest.PodLogsRequest.SinceTime = &t + isReconnect = true + } + stream, err := handler.k8sApplicationService.GetPodLogs(r.Context(), request) + //err is handled inside StartK8sStreamWithHeartBeat method + ctx, cancel := context.WithCancel(r.Context()) + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { + select { + case <-done: + case <-closed: + cancel() + } + }(ctx.Done(), cn.CloseNotify()) + } + defer cancel() + defer util.Close(stream, handler.logger) + handler.pump.StartK8sStreamWithHeartBeat(w, isReconnect, stream, err) +} + +func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWriter, r *http.Request) { + token := r.Header.Get("token") + request, err := handler.k8sApplicationService.ValidatePodLogsRequestQuery(r) + if err != nil { + common.WriteJsonResp(w, err, nil, http.StatusBadRequest) + return + } + handler.requestValidationAndRBAC(w, r, token, request) + + stream, err := handler.k8sApplicationService.GetPodLogs(r.Context(), request) + if err != nil { + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) + return + } + ctx, cancel := context.WithCancel(r.Context()) + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { + select { + case <-done: + case <-closed: + cancel() + } + }(ctx.Done(), cn.CloseNotify()) + } + defer cancel() + defer util.Close(stream, handler.logger) + + var dataBuffer bytes.Buffer + bufReader := bufio.NewReader(stream) + eof := false + for !eof { + log, err := bufReader.ReadString('\n') + if err == io.EOF { + eof = true + // stop if we reached end of stream and the next line is empty + if log == "" { + break + } + } else if err != nil && err != io.EOF { + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) + return + } + _, err = dataBuffer.Write([]byte(log)) + if err != nil { + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) + return + } + } + common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), "podlogs.txt") +} + +func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.ResponseWriter, r *http.Request, token string, request *k8s.ResourceRequestBean) { if request.AppIdentifier != nil { if request.DeploymentType == bean2.HelmInstalledType { valid, err := handler.k8sApplicationService.ValidateResourceRequest(r.Context(), request.AppIdentifier, request.K8sRequest) @@ -658,34 +745,6 @@ func (handler *K8sApplicationRestHandlerImpl) GetPodLogs(w http.ResponseWriter, common.WriteJsonResp(w, errors.New("can not get pod logs as target cluster is not provided"), nil, http.StatusBadRequest) return } - lastEventId := r.Header.Get("Last-Event-ID") - isReconnect := false - if len(lastEventId) > 0 { - lastSeenMsgId, err := strconv.ParseInt(lastEventId, 10, 64) - if err != nil { - common.WriteJsonResp(w, err, nil, http.StatusBadRequest) - return - } - lastSeenMsgId = lastSeenMsgId + 1 //increased by one ns to avoid duplicate - t := v1.Unix(0, lastSeenMsgId) - request.K8sRequest.PodLogsRequest.SinceTime = &t - isReconnect = true - } - stream, err := handler.k8sApplicationService.GetPodLogs(r.Context(), request) - //err is handled inside StartK8sStreamWithHeartBeat method - ctx, cancel := context.WithCancel(r.Context()) - if cn, ok := w.(http.CloseNotifier); ok { - go func(done <-chan struct{}, closed <-chan bool) { - select { - case <-done: - case <-closed: - cancel() - } - }(ctx.Done(), cn.CloseNotify()) - } - defer cancel() - defer util.Close(stream, handler.logger) - handler.pump.StartK8sStreamWithHeartBeat(w, isReconnect, stream, err) } func (handler *K8sApplicationRestHandlerImpl) GetTerminalSession(w http.ResponseWriter, r *http.Request) { diff --git a/api/k8s/application/k8sApplicationRouter.go b/api/k8s/application/k8sApplicationRouter.go index ae5e4dd1e29..730afd9925a 100644 --- a/api/k8s/application/k8sApplicationRouter.go +++ b/api/k8s/application/k8sApplicationRouter.go @@ -46,9 +46,18 @@ func (impl *K8sApplicationRouterImpl) InitK8sApplicationRouter(k8sAppRouter *mux //Queries("clusterId", "{clusterId}", "namespace", "${namespace}"). //Queries("sinceSeconds", "{sinceSeconds}"). Queries("follow", "{follow}"). - Queries("tailLines", "{tailLines}"). + //Queries("tailLines", "{tailLines}"). HandlerFunc(impl.k8sApplicationRestHandler.GetPodLogs).Methods("GET") + k8sAppRouter.Path("/pods/logs/download/{podName}"). + Queries("containerName", "{containerName}"). + //Queries("containerName", "{containerName}", "appId", "{appId}"). + //Queries("clusterId", "{clusterId}", "namespace", "${namespace}"). + //Queries("sinceSeconds", "{sinceSeconds}"). + //Queries("follow", "{follow}"). + //Queries("tailLines", "{tailLines}"). + HandlerFunc(impl.k8sApplicationRestHandler.DownloadPodLogs).Methods("GET") + k8sAppRouter.Path("/pod/exec/session/{identifier}/{namespace}/{pod}/{shell}/{container}"). HandlerFunc(impl.k8sApplicationRestHandler.GetTerminalSession).Methods("GET") k8sAppRouter.PathPrefix("/pod/exec/sockjs/ws").Handler(terminal.CreateAttachHandler("/pod/exec/sockjs/ws")) diff --git a/pkg/k8s/application/k8sApplicationService.go b/pkg/k8s/application/k8sApplicationService.go index b49c26ca597..42115928fdd 100644 --- a/pkg/k8s/application/k8sApplicationService.go +++ b/pkg/k8s/application/k8sApplicationService.go @@ -9,7 +9,6 @@ import ( k8s2 "github.com/devtron-labs/common-lib/utils/k8s" k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean" k8sObjectUtils "github.com/devtron-labs/common-lib/utils/k8sObjectsUtil" - yamlUtil "github.com/devtron-labs/common-lib/utils/yaml" "github.com/devtron-labs/devtron/api/connector" client "github.com/devtron-labs/devtron/api/helm-app" @@ -113,10 +112,15 @@ func (impl *K8sApplicationServiceImpl) ValidatePodLogsRequestQuery(r *http.Reque v, vars := r.URL.Query(), mux.Vars(r) request := &k8s.ResourceRequestBean{} podName := vars["podName"] - /*sinceSeconds, err := strconv.Atoi(v.Get("sinceSeconds")) + sinceSeconds, err := strconv.Atoi(v.Get("sinceSeconds")) if err != nil { sinceSeconds = 0 - }*/ + } + sinceTimeVar, err := strconv.ParseInt(v.Get("sinceTime"), 10, 64) + if err != nil { + sinceTimeVar = 0 + } + sinceTime := metav1.Unix(sinceTimeVar, 0) containerName, clusterIdString := v.Get("containerName"), v.Get("clusterId") prevContainerLogs := v.Get("previous") isPrevLogs, err := strconv.ParseBool(prevContainerLogs) @@ -138,7 +142,8 @@ func (impl *K8sApplicationServiceImpl) ValidatePodLogsRequestQuery(r *http.Reque GroupVersionKind: schema.GroupVersionKind{}, }, PodLogsRequest: k8s2.PodLogsRequest{ - //SinceTime: sinceSeconds, + SinceSeconds: sinceSeconds, + SinceTime: &sinceTime, TailLines: tailLines, Follow: follow, ContainerName: containerName, @@ -313,7 +318,7 @@ func (impl *K8sApplicationServiceImpl) GetPodLogs(ctx context.Context, request * resourceIdentifier := request.K8sRequest.ResourceIdentifier podLogsRequest := request.K8sRequest.PodLogsRequest - resp, err := impl.K8sUtil.GetPodLogs(ctx, restConfig, resourceIdentifier.Name, resourceIdentifier.Namespace, podLogsRequest.SinceTime, podLogsRequest.TailLines, podLogsRequest.Follow, podLogsRequest.ContainerName, podLogsRequest.IsPrevContainerLogsEnabled) + resp, err := impl.K8sUtil.GetPodLogs(ctx, restConfig, resourceIdentifier.Name, resourceIdentifier.Namespace, podLogsRequest.SinceTime, podLogsRequest.TailLines, podLogsRequest.SinceSeconds, podLogsRequest.Follow, podLogsRequest.ContainerName, podLogsRequest.IsPrevContainerLogsEnabled) if err != nil { impl.logger.Errorw("error in getting pod logs", "err", err, "clusterId", clusterId) return nil, err From f74fe91e43ce3e599df7b1952f6eddf2a68f34f0 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Fri, 12 Jan 2024 15:37:30 +0530 Subject: [PATCH 02/24] added support for download pod logs --- .../application/k8sApplicationRestHandler.go | 7 +++++-- go.mod | 2 +- go.sum | 4 ++-- .../pubsub-lib/PubSubClientService.go | 18 +++++++++--------- .../common-lib/utils/k8s/K8sUtil.go | 10 ++++++++-- .../devtron-labs/common-lib/utils/k8s/bean.go | 1 + vendor/modules.txt | 2 +- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index a1a54be8a75..5c48d5afce6 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -24,6 +24,7 @@ import ( "github.com/devtron-labs/devtron/pkg/user/casbin" "github.com/devtron-labs/devtron/util" "github.com/devtron-labs/devtron/util/rbac" + "github.com/google/uuid" "github.com/gorilla/mux" errors2 "github.com/juju/errors" "go.uber.org/zap" @@ -690,7 +691,9 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri return } } - common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), "podlogs.txt") + podLogsFilename := fmt.Sprintf("podlogs-%s-%s.txt", request.K8sRequest.ResourceIdentifier.Name, uuid.New().String()) + common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) + return } func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.ResponseWriter, r *http.Request, token string, request *k8s.ResourceRequestBean) { @@ -698,7 +701,7 @@ func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.Re if request.DeploymentType == bean2.HelmInstalledType { valid, err := handler.k8sApplicationService.ValidateResourceRequest(r.Context(), request.AppIdentifier, request.K8sRequest) if err != nil || !valid { - handler.logger.Errorw("error in validating resource request", "err", err) + handler.logger.Errorw("error in validating resource request", "err", err, "request.AppIdentifier", request.AppIdentifier, "request.K8sRequest", request.K8sRequest) apiError := util2.ApiError{ InternalMessage: "failed to validate the resource with error " + err.Error(), UserMessage: "Failed to validate resource", diff --git a/go.mod b/go.mod index f81542d6e4a..30223d7a646 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.32 - github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5 + github.com/devtron-labs/common-lib v0.0.9-beta1 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index 2c2cfe96660..72998a4bba7 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/devtron-labs/authenticator v0.4.32 h1:JAIJ0WqTXWj2nW7b8so9wunNICQn7O1Qpkk8INpatcs= github.com/devtron-labs/authenticator v0.4.32/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= -github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5 h1:+Nh2SMzAdgBr1tgdKAlF5cN0CvTPUj1V/sI5aRUrZnE= -github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5/go.mod h1:pBThgympEjsza6GShqNNGCPBFXNDx0DGMc7ID/VHTAw= +github.com/devtron-labs/common-lib v0.0.9-beta1 h1:6aVdzLISCeckSYCBWTLlojZtxbloJs+hk5WGK/nw6BU= +github.com/devtron-labs/common-lib v0.0.9-beta1/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go index dec37692bc0..8d8e80d0f10 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go @@ -132,37 +132,37 @@ func (impl PubSubClientServiceImpl) Subscribe(topic string, callback func(msg *m impl.Logger.Fatalw("error while subscribing to nats ", "stream", streamName, "topic", topic, "error", err) return err } - go impl.startListeningForEvents(processingBatchSize, channel, callback, topic) + go impl.startListeningForEvents(processingBatchSize, channel, callback) impl.Logger.Infow("Successfully subscribed with Nats", "stream", streamName, "topic", topic, "queue", queueName, "consumer", consumerName) return nil } -func (impl PubSubClientServiceImpl) startListeningForEvents(processingBatchSize int, channel chan *nats.Msg, callback func(msg *model.PubSubMsg), topic string) { +func (impl PubSubClientServiceImpl) startListeningForEvents(processingBatchSize int, channel chan *nats.Msg, callback func(msg *model.PubSubMsg)) { wg := new(sync.WaitGroup) for index := 0; index < processingBatchSize; index++ { wg.Add(1) - go impl.processMessages(wg, channel, callback, topic) + go impl.processMessages(wg, channel, callback) } wg.Wait() impl.Logger.Warn("msgs received Done from Nats side, going to end listening!!") } -func (impl PubSubClientServiceImpl) processMessages(wg *sync.WaitGroup, channel chan *nats.Msg, callback func(msg *model.PubSubMsg), topic string) { +func (impl PubSubClientServiceImpl) processMessages(wg *sync.WaitGroup, channel chan *nats.Msg, callback func(msg *model.PubSubMsg)) { defer wg.Done() for msg := range channel { - impl.processMsg(msg, callback, topic) + impl.processMsg(msg, callback) } } // TODO need to extend msg ack depending upon response from callback like error scenario -func (impl PubSubClientServiceImpl) processMsg(msg *nats.Msg, callback func(msg *model.PubSubMsg), topic string) { +func (impl PubSubClientServiceImpl) processMsg(msg *nats.Msg, callback func(msg *model.PubSubMsg)) { t1 := time.Now() - metrics.IncConsumingCount(topic) - defer metrics.IncConsumptionCount(topic) + metrics.IncConsumingCount(msg.Subject) + defer metrics.IncConsumptionCount(msg.Subject) defer func() { // wrapping this function in defer as directly calling Observe() will run immediately - metrics.NatsEventConsumptionTime.WithLabelValues(topic).Observe(float64(time.Since(t1).Milliseconds())) + metrics.NatsEventConsumptionTime.WithLabelValues(msg.Subject).Observe(float64(time.Since(t1).Milliseconds())) }() impl.TryCatchCallBack(msg, callback) } diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index b074fd87818..c2237a03b9a 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -1150,7 +1150,7 @@ func (impl K8sUtil) ListEvents(restConfig *rest.Config, namespace string, groupV } -func (impl K8sUtil) GetPodLogs(ctx context.Context, restConfig *rest.Config, name string, namespace string, sinceTime *metav1.Time, tailLines int, follow bool, containerName string, isPrevContainerLogsEnabled bool) (io.ReadCloser, error) { +func (impl K8sUtil) GetPodLogs(ctx context.Context, restConfig *rest.Config, name string, namespace string, sinceTime *metav1.Time, tailLines int, sinceSeconds int, follow bool, containerName string, isPrevContainerLogsEnabled bool) (io.ReadCloser, error) { httpClient, err := OverrideK8sHttpClientWithTracer(restConfig) if err != nil { impl.logger.Errorw("error in getting pod logs", "err", err) @@ -1162,13 +1162,19 @@ func (impl K8sUtil) GetPodLogs(ctx context.Context, restConfig *rest.Config, nam return nil, err } TailLines := int64(tailLines) + SinceSeconds := int64(sinceSeconds) podLogOptions := &v1.PodLogOptions{ Follow: follow, - TailLines: &TailLines, Container: containerName, Timestamps: true, Previous: isPrevContainerLogsEnabled, } + if TailLines > 0 { + podLogOptions.TailLines = &TailLines + } + if SinceSeconds > 0 { + podLogOptions.SinceSeconds = &SinceSeconds + } if sinceTime != nil { podLogOptions.SinceTime = sinceTime } diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go index 0bcd729a91c..4f8b2ebe7d3 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go @@ -42,6 +42,7 @@ type ResourceListResponse struct { type PodLogsRequest struct { SinceTime *v12.Time `json:"sinceTime,omitempty"` + SinceSeconds int `json:"sinceSeconds,omitempty"` TailLines int `json:"tailLines"` Follow bool `json:"follow"` ContainerName string `json:"containerName"` diff --git a/vendor/modules.txt b/vendor/modules.txt index 39cad08c315..accc1da7c78 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5 +# github.com/devtron-labs/common-lib v0.0.9-beta1 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/pubsub-lib From f3808ec48eadb2801c580d533c3fa8ccd5d8b2c6 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Fri, 19 Jan 2024 16:35:42 +0530 Subject: [PATCH 03/24] set follow flag to false on backend as well --- api/k8s/application/k8sApplicationRestHandler.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 11bffc05314..5654d7db0bc 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -67,9 +67,9 @@ type K8sApplicationRestHandlerImpl struct { validator *validator.Validate enforcerUtil rbac.EnforcerUtil enforcerUtilHelm rbac.EnforcerUtilHelm - helmAppService client.HelmAppService - userService user.UserService - k8sCommonService k8s.K8sCommonService + helmAppService client.HelmAppService + userService user.UserService + k8sCommonService k8s.K8sCommonService } func NewK8sApplicationRestHandlerImpl(logger *zap.SugaredLogger, k8sApplicationService application2.K8sApplicationService, pump connector.Pump, terminalSessionHandler terminal.TerminalSessionHandler, enforcer casbin.Enforcer, enforcerUtilHelm rbac.EnforcerUtilHelm, enforcerUtil rbac.EnforcerUtil, helmAppService client.HelmAppService, userService user.UserService, k8sCommonService k8s.K8sCommonService, validator *validator.Validate) *K8sApplicationRestHandlerImpl { @@ -653,6 +653,9 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } handler.requestValidationAndRBAC(w, r, token, request) + // just to make sure follow flag is set to false when downloading logs + request.K8sRequest.PodLogsRequest.Follow = false + stream, err := handler.k8sApplicationService.GetPodLogs(r.Context(), request) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) From 4a3795ab3a7278e9acedb1988cdeff2854b9efed Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Wed, 24 Jan 2024 12:11:38 +0530 Subject: [PATCH 04/24] updated common lib vrsion --- go.mod | 2 +- go.sum | 4 ++-- .../github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go | 2 +- vendor/modules.txt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index ff2ffeb5dec..5f1f9f4d312 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.33 - github.com/devtron-labs/common-lib v0.0.9-beta1 + github.com/devtron-labs/common-lib v0.0.9-beta3 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index 5c0ffda1547..e29cfd9645e 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/devtron-labs/authenticator v0.4.33 h1:FpAV3ZgFluaRFcMwPpwxr/mwSipJ16XRvgABq3BzP5Y= github.com/devtron-labs/authenticator v0.4.33/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= -github.com/devtron-labs/common-lib v0.0.9-beta1 h1:6aVdzLISCeckSYCBWTLlojZtxbloJs+hk5WGK/nw6BU= -github.com/devtron-labs/common-lib v0.0.9-beta1/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= +github.com/devtron-labs/common-lib v0.0.9-beta3 h1:uLAx/z341oEoKiJoiwS8+qfHoRoA41gnOBEEPU+r0aI= +github.com/devtron-labs/common-lib v0.0.9-beta3/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index c2237a03b9a..a48cf9615ea 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -1175,7 +1175,7 @@ func (impl K8sUtil) GetPodLogs(ctx context.Context, restConfig *rest.Config, nam if SinceSeconds > 0 { podLogOptions.SinceSeconds = &SinceSeconds } - if sinceTime != nil { + if sinceTime != nil && SinceSeconds == 0 { podLogOptions.SinceTime = sinceTime } podIf := podClient.Pods(namespace) diff --git a/vendor/modules.txt b/vendor/modules.txt index 5170b41a8e9..ea68f9dd26d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.9-beta1 +# github.com/devtron-labs/common-lib v0.0.9-beta3 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/pubsub-lib From b96f7411b4246d26c3481681d3f231479919fc38 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Wed, 24 Jan 2024 14:07:03 +0530 Subject: [PATCH 05/24] changed response type from octet stream to json --- api/k8s/application/k8sApplicationRestHandler.go | 4 ++-- pkg/k8s/bean.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 5654d7db0bc..a9839aee8f9 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -696,8 +696,8 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } podLogsFilename := fmt.Sprintf("podlogs-%s-%s.txt", request.K8sRequest.ResourceIdentifier.Name, uuid.New().String()) - common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) - return + logsBody := k8s.LogsDownloadBean{FileName: podLogsFilename, LogsData: dataBuffer.String()} + common.WriteJsonResp(w, nil, logsBody, http.StatusOK) } func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.ResponseWriter, r *http.Request, token string, request *k8s.ResourceRequestBean) { diff --git a/pkg/k8s/bean.go b/pkg/k8s/bean.go index 23229ceaf44..e0626036c66 100644 --- a/pkg/k8s/bean.go +++ b/pkg/k8s/bean.go @@ -16,6 +16,11 @@ type ResourceRequestBean struct { ClusterId int `json:"clusterId"` // clusterId is used when request is for direct cluster (not for helm release) } +type LogsDownloadBean struct { + FileName string `json:"fileName"` + LogsData string `json:"data"` +} + type BatchResourceResponse struct { ManifestResponse *k8s.ManifestResponse Err error From 7a072c2046e0667b0c6578332f81d0c9385c1b46 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Wed, 24 Jan 2024 16:54:02 +0530 Subject: [PATCH 06/24] changed the ordering of headers and writes in octet stream --- api/k8s/application/k8sApplicationRestHandler.go | 3 +-- api/restHandler/common/ApiResponseWriter.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index a9839aee8f9..99d70708d04 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -696,8 +696,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } podLogsFilename := fmt.Sprintf("podlogs-%s-%s.txt", request.K8sRequest.ResourceIdentifier.Name, uuid.New().String()) - logsBody := k8s.LogsDownloadBean{FileName: podLogsFilename, LogsData: dataBuffer.String()} - common.WriteJsonResp(w, nil, logsBody, http.StatusOK) + common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) } func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.ResponseWriter, r *http.Request, token string, request *k8s.ResourceRequestBean) { diff --git a/api/restHandler/common/ApiResponseWriter.go b/api/restHandler/common/ApiResponseWriter.go index 4725c933eda..ac64a863772 100644 --- a/api/restHandler/common/ApiResponseWriter.go +++ b/api/restHandler/common/ApiResponseWriter.go @@ -52,11 +52,11 @@ func WriteApiJsonResponseStructured(w http.ResponseWriter, apiResponse *ApiRespo } func WriteOctetStreamResp(w http.ResponseWriter, r *http.Request, byteArr []byte, defaultFilename string) { - w.WriteHeader(http.StatusOK) + w.Header().Set(CONTENT_TYPE, "application/octet-stream") if defaultFilename != "" { w.Header().Set(CONTENT_DISPOSITION, "attachment; filename="+defaultFilename) } - w.Header().Set(CONTENT_TYPE, "application/octet-stream") w.Header().Set(CONTENT_LENGTH, r.Header.Get(CONTENT_LENGTH)) + w.WriteHeader(http.StatusOK) w.Write(byteArr) } From 6b362ab4f7ef274f4fe0b64ae04ea3beb3845ed8 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Wed, 24 Jan 2024 17:16:22 +0530 Subject: [PATCH 07/24] changed file extension --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 99d70708d04..170dad9bad5 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -695,7 +695,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri return } } - podLogsFilename := fmt.Sprintf("podlogs-%s-%s.txt", request.K8sRequest.ResourceIdentifier.Name, uuid.New().String()) + podLogsFilename := fmt.Sprintf("podlogs-%s-%s.log", request.K8sRequest.ResourceIdentifier.Name, uuid.New().String()) common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) } From b34ca6bd3dbaa67fcf161b633662172ebd16fa90 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 25 Jan 2024 13:55:41 +0530 Subject: [PATCH 08/24] refactoring --- api/k8s/application/k8sApplicationRestHandler.go | 12 ++++++++---- api/k8s/application/k8sApplicationRouter.go | 9 --------- pkg/k8s/application/bean/bean.go | 7 +++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 2033ff939a5..0984e9de06d 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -626,15 +626,15 @@ func (handler *K8sApplicationRestHandlerImpl) GetPodLogs(w http.ResponseWriter, return } handler.requestValidationAndRBAC(w, r, token, request) - lastEventId := r.Header.Get("Last-Event-ID") + lastEventId := r.Header.Get(bean2.LastEventID) isReconnect := false if len(lastEventId) > 0 { - lastSeenMsgId, err := strconv.ParseInt(lastEventId, 10, 64) + lastSeenMsgId, err := strconv.ParseInt(lastEventId, bean2.IntegerBase, bean2.IntegerBitSize) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusBadRequest) return } - lastSeenMsgId = lastSeenMsgId + 1 //increased by one ns to avoid duplicate + lastSeenMsgId = lastSeenMsgId + bean2.TimestampOffsetToAvoidDuplicateLogs //increased by one ns to avoid duplicate t := v1.Unix(0, lastSeenMsgId) request.K8sRequest.PodLogsRequest.SinceTime = &t isReconnect = true @@ -707,10 +707,14 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri return } } - podLogsFilename := fmt.Sprintf("podlogs-%s-%s.log", request.K8sRequest.ResourceIdentifier.Name, uuid.New().String()) + podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) } +func generatePodLogsFilename(filename string) string { + return fmt.Sprintf("podlogs-%s-%s.log", filename, uuid.New().String()) +} + func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.ResponseWriter, r *http.Request, token string, request *k8s.ResourceRequestBean) { if request.AppIdentifier != nil { if request.DeploymentType == bean2.HelmInstalledType { diff --git a/api/k8s/application/k8sApplicationRouter.go b/api/k8s/application/k8sApplicationRouter.go index 730afd9925a..857a131d6b5 100644 --- a/api/k8s/application/k8sApplicationRouter.go +++ b/api/k8s/application/k8sApplicationRouter.go @@ -42,20 +42,11 @@ func (impl *K8sApplicationRouterImpl) InitK8sApplicationRouter(k8sAppRouter *mux k8sAppRouter.Path("/pods/logs/{podName}"). Queries("containerName", "{containerName}"). - //Queries("containerName", "{containerName}", "appId", "{appId}"). - //Queries("clusterId", "{clusterId}", "namespace", "${namespace}"). - //Queries("sinceSeconds", "{sinceSeconds}"). Queries("follow", "{follow}"). - //Queries("tailLines", "{tailLines}"). HandlerFunc(impl.k8sApplicationRestHandler.GetPodLogs).Methods("GET") k8sAppRouter.Path("/pods/logs/download/{podName}"). Queries("containerName", "{containerName}"). - //Queries("containerName", "{containerName}", "appId", "{appId}"). - //Queries("clusterId", "{clusterId}", "namespace", "${namespace}"). - //Queries("sinceSeconds", "{sinceSeconds}"). - //Queries("follow", "{follow}"). - //Queries("tailLines", "{tailLines}"). HandlerFunc(impl.k8sApplicationRestHandler.DownloadPodLogs).Methods("GET") k8sAppRouter.Path("/pod/exec/session/{identifier}/{namespace}/{pod}/{shell}/{container}"). diff --git a/pkg/k8s/application/bean/bean.go b/pkg/k8s/application/bean/bean.go index ed18919aa13..3348c6ad8f8 100644 --- a/pkg/k8s/application/bean/bean.go +++ b/pkg/k8s/application/bean/bean.go @@ -21,6 +21,13 @@ const ( ArgoInstalledType = 1 // Identifier for ArgoCD deployment ) +const ( + LastEventID = "Last-Event-ID" + TimestampOffsetToAvoidDuplicateLogs = 1 + IntegerBase = 10 + IntegerBitSize = 64 +) + type ResourceInfo struct { PodName string `json:"podName"` } From fc4167103499840677baf95756601afa2488e641 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Mon, 29 Jan 2024 19:13:32 +0530 Subject: [PATCH 09/24] fix --- api/k8s/application/k8sApplicationRestHandler.go | 3 +++ go.mod | 2 +- go.sum | 4 ++-- .../github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go | 1 + vendor/modules.txt | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 0984e9de06d..eb6c92b297f 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -707,6 +707,9 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri return } } + if len(dataBuffer.Bytes()) == 0 { + common.WriteJsonResp(w, errors.New("no logs found"), nil, http.StatusNotFound) + } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) } diff --git a/go.mod b/go.mod index c2ed601a7a3..982966d4a60 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.33 - github.com/devtron-labs/common-lib v0.0.11-beta1 + github.com/devtron-labs/common-lib v0.0.11-beta2 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index e74b84692f3..d233136d8ee 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/devtron-labs/authenticator v0.4.33 h1:FpAV3ZgFluaRFcMwPpwxr/mwSipJ16XRvgABq3BzP5Y= github.com/devtron-labs/authenticator v0.4.33/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= -github.com/devtron-labs/common-lib v0.0.11-beta1 h1:WITILl7l8nw5XruciGZf/3Vn0QoPVUlYVlfQonLa7I0= -github.com/devtron-labs/common-lib v0.0.11-beta1/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= +github.com/devtron-labs/common-lib v0.0.11-beta2 h1:3JBLEacAMspawqJF5QeoEByNPT26ykLtRA9HLfsATy8= +github.com/devtron-labs/common-lib v0.0.11-beta2/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index 5e4de683015..6ccdde63603 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -1232,6 +1232,7 @@ func (impl K8sServiceImpl) GetPodLogs(ctx context.Context, restConfig *rest.Conf } if sinceTime != nil && SinceSeconds == 0 { podLogOptions.SinceTime = sinceTime + podLogOptions.TailLines = &TailLines } podIf := podClient.Pods(namespace) logsRequest := podIf.GetLogs(name, podLogOptions) diff --git a/vendor/modules.txt b/vendor/modules.txt index 551353a3ed6..6ace4484da7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.11-beta1 +# github.com/devtron-labs/common-lib v0.0.11-beta2 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/cloud-provider-identifier From 50468a1b23a02ee5244d067841d3883b77be6288 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Tue, 30 Jan 2024 10:48:13 +0530 Subject: [PATCH 10/24] time format converted --- .../application/k8sApplicationRestHandler.go | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index eb6c92b297f..a70324d0b93 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -8,10 +8,6 @@ import ( "errors" "fmt" "github.com/devtron-labs/common-lib/utils" - "net/http" - "strconv" - "strings" - util3 "github.com/devtron-labs/common-lib/utils/k8s" k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean" "github.com/devtron-labs/common-lib/utils/k8sObjectsUtil" @@ -37,6 +33,11 @@ import ( "io" errors3 "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "net/http" + "regexp" + "strconv" + "strings" + "time" ) type K8sApplicationRestHandler interface { @@ -691,6 +692,25 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri eof := false for !eof { log, err := bufReader.ReadString('\n') + log = strings.TrimSpace(log) // Remove trailing line ending + a := regexp.MustCompile(" ") + var res []byte + splitLog := a.Split(log, 2) + if len(splitLog[0]) > 0 { + parsedTime, err := time.Parse(time.RFC3339, splitLog[0]) + if err != nil { + handler.logger.Errorw("error in writing data", "err", err) + return + } + humanReadableTime := parsedTime.UTC().Format(http.TimeFormat) + res = append(res, humanReadableTime...) + } + + if len(splitLog) == 2 { + res = append(res, " "...) + res = append(res, splitLog[1]...) + } + res = append(res, "\n"...) if err == io.EOF { eof = true // stop if we reached end of stream and the next line is empty @@ -701,7 +721,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } - _, err = dataBuffer.Write([]byte(log)) + _, err = dataBuffer.Write(res) if err != nil { common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return From 071fee438e187b9787fe666a00cbc45c0587a9ef Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Tue, 30 Jan 2024 13:09:03 +0530 Subject: [PATCH 11/24] validation fix --- go.mod | 2 +- go.sum | 4 +- pkg/k8s/application/k8sApplicationService.go | 45 ++++++++++++++----- .../common-lib/utils/k8s/K8sUtil.go | 4 +- vendor/modules.txt | 2 +- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 982966d4a60..0faea94e0af 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.33 - github.com/devtron-labs/common-lib v0.0.11-beta2 + github.com/devtron-labs/common-lib v0.0.11-beta3 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index d233136d8ee..40707a9e617 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/devtron-labs/authenticator v0.4.33 h1:FpAV3ZgFluaRFcMwPpwxr/mwSipJ16XRvgABq3BzP5Y= github.com/devtron-labs/authenticator v0.4.33/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= -github.com/devtron-labs/common-lib v0.0.11-beta2 h1:3JBLEacAMspawqJF5QeoEByNPT26ykLtRA9HLfsATy8= -github.com/devtron-labs/common-lib v0.0.11-beta2/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= +github.com/devtron-labs/common-lib v0.0.11-beta3 h1:o44QgEwFqNOR9fWaJwEL3lZmEWSfLC+cRSVryXfurRc= +github.com/devtron-labs/common-lib v0.0.11-beta3/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/pkg/k8s/application/k8sApplicationService.go b/pkg/k8s/application/k8sApplicationService.go index 3383374ee5b..90bd9643954 100644 --- a/pkg/k8s/application/k8sApplicationService.go +++ b/pkg/k8s/application/k8sApplicationService.go @@ -115,15 +115,32 @@ func (impl *K8sApplicationServiceImpl) ValidatePodLogsRequestQuery(r *http.Reque v, vars := r.URL.Query(), mux.Vars(r) request := &k8s.ResourceRequestBean{} podName := vars["podName"] - sinceSeconds, err := strconv.Atoi(v.Get("sinceSeconds")) - if err != nil { - sinceSeconds = 0 + sinceSecondsParam := v.Get("sinceSeconds") + var sinceSeconds int + var err error + if len(sinceSecondsParam) > 0 { + sinceSeconds, err = strconv.Atoi(sinceSecondsParam) + if err != nil || sinceSeconds <= 0 { + return nil, &util.ApiError{ + Code: "400", + HttpStatusCode: 400, + UserMessage: "invalid value provided for sinceSeconds", + InternalMessage: "invalid value provided for sinceSeconds"} + } } - sinceTimeVar, err := strconv.ParseInt(v.Get("sinceTime"), 10, 64) - if err != nil { - sinceTimeVar = 0 + sinceTimeParam := v.Get("sinceTime") + sinceTime := metav1.Unix(0, 0) + if len(sinceTimeParam) > 0 { + sinceTimeVar, err := strconv.ParseInt(sinceTimeParam, 10, 64) + if err != nil || sinceTimeVar <= 0 { + return nil, &util.ApiError{ + Code: "400", + HttpStatusCode: 400, + UserMessage: "invalid value provided for sinceTime", + InternalMessage: "invalid value provided for sinceTime"} + } + sinceTime = metav1.Unix(sinceTimeVar, 0) } - sinceTime := metav1.Unix(sinceTimeVar, 0) containerName, clusterIdString := v.Get("containerName"), v.Get("clusterId") prevContainerLogs := v.Get("previous") isPrevLogs, err := strconv.ParseBool(prevContainerLogs) @@ -135,9 +152,17 @@ func (impl *K8sApplicationServiceImpl) ValidatePodLogsRequestQuery(r *http.Reque if err != nil { follow = false } - tailLines, err := strconv.Atoi(v.Get("tailLines")) - if err != nil { - tailLines = 0 + tailLinesParam := v.Get("tailLines") + var tailLines int + if len(tailLinesParam) > 0 { + tailLines, err = strconv.Atoi(tailLinesParam) + if err != nil || tailLines <= 0 { + return nil, &util.ApiError{ + Code: "400", + HttpStatusCode: 400, + UserMessage: "invalid value provided for tailLines", + InternalMessage: "invalid value provided for tailLines"} + } } k8sRequest := &k8s2.K8sRequestBean{ ResourceIdentifier: k8s2.ResourceIdentifier{ diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index 6ccdde63603..d17385dfb0d 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -1224,15 +1224,15 @@ func (impl K8sServiceImpl) GetPodLogs(ctx context.Context, restConfig *rest.Conf Timestamps: true, Previous: isPrevContainerLogsEnabled, } + startTime := metav1.Unix(0, 0) if TailLines > 0 { podLogOptions.TailLines = &TailLines } if SinceSeconds > 0 { podLogOptions.SinceSeconds = &SinceSeconds } - if sinceTime != nil && SinceSeconds == 0 { + if *sinceTime != metav1.Time(startTime) { podLogOptions.SinceTime = sinceTime - podLogOptions.TailLines = &TailLines } podIf := podClient.Pods(namespace) logsRequest := podIf.GetLogs(name, podLogOptions) diff --git a/vendor/modules.txt b/vendor/modules.txt index 6ace4484da7..b459c7dada3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.11-beta2 +# github.com/devtron-labs/common-lib v0.0.11-beta3 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/cloud-provider-identifier From 33dc4f58ad0ec97e99b8e10883841f5ed6a1f7fe Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Tue, 30 Jan 2024 15:17:43 +0530 Subject: [PATCH 12/24] fix --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index a70324d0b93..8c65e5f5a0d 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -699,7 +699,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri if len(splitLog[0]) > 0 { parsedTime, err := time.Parse(time.RFC3339, splitLog[0]) if err != nil { - handler.logger.Errorw("error in writing data", "err", err) + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } humanReadableTime := parsedTime.UTC().Format(http.TimeFormat) From ab6d8426c8113384d36aebb96605f6f78f8d3079 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Wed, 31 Jan 2024 11:32:23 +0530 Subject: [PATCH 13/24] added return statement --- api/k8s/application/k8sApplicationRestHandler.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 8c65e5f5a0d..d26219d942e 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -729,9 +729,11 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } if len(dataBuffer.Bytes()) == 0 { common.WriteJsonResp(w, errors.New("no logs found"), nil, http.StatusNotFound) + return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) common.WriteOctetStreamResp(w, r, dataBuffer.Bytes(), podLogsFilename) + return } func generatePodLogsFilename(filename string) string { From 4af23c0dc9d0d5ed46eb120cd5f5a8cdbd0db348 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 12:34:21 +0530 Subject: [PATCH 14/24] time format and http status code fixed --- api/k8s/application/k8sApplicationRestHandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index d26219d942e..86e0e3fdb39 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -702,7 +702,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } - humanReadableTime := parsedTime.UTC().Format(http.TimeFormat) + humanReadableTime := parsedTime.UTC().Local().Format(time.RFC1123) res = append(res, humanReadableTime...) } @@ -728,7 +728,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } if len(dataBuffer.Bytes()) == 0 { - common.WriteJsonResp(w, errors.New("no logs found"), nil, http.StatusNotFound) + common.WriteJsonResp(w, fmt.Errorf("logs not found"), nil, http.StatusOK) return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) From 5a156d6bd202b1447e239014a1a34880de214e61 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 12:52:46 +0530 Subject: [PATCH 15/24] fix --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 86e0e3fdb39..a48472e08c2 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -728,7 +728,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } if len(dataBuffer.Bytes()) == 0 { - common.WriteJsonResp(w, fmt.Errorf("logs not found"), nil, http.StatusOK) + common.WriteJsonResp(w, errors.New("logs not found"), nil, http.StatusOK) return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) From 72687841667084db34c4c2c29fd62d78716df13e Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 13:09:13 +0530 Subject: [PATCH 16/24] fix --- api/k8s/application/k8sApplicationRestHandler.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index a48472e08c2..46ef9512e7b 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -702,7 +702,12 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } - humanReadableTime := parsedTime.UTC().Local().Format(time.RFC1123) + loc, err := time.LoadLocation("Asia/Kolkata") + if err != nil { + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) + return + } + humanReadableTime := parsedTime.In(loc).Format(time.RFC1123) res = append(res, humanReadableTime...) } From 77c1354d4cc9eb6c45a17a0ac868c9ca6647340d Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 13:26:35 +0530 Subject: [PATCH 17/24] time format fixed --- api/k8s/application/k8sApplicationRestHandler.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 46ef9512e7b..11222d57d98 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -702,12 +702,8 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } - loc, err := time.LoadLocation("Asia/Kolkata") - if err != nil { - common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) - return - } - humanReadableTime := parsedTime.In(loc).Format(time.RFC1123) + gmtTimeLoc := time.FixedZone("GMT+0530", int((5*time.Hour).Seconds()+(30*time.Minute).Seconds())) + humanReadableTime := parsedTime.In(gmtTimeLoc).Format(http.TimeFormat) res = append(res, humanReadableTime...) } From 09a6473740ffce37f23edf414fb9a911aed5f6a8 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 13:27:44 +0530 Subject: [PATCH 18/24] fix --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 11222d57d98..5719d40ea8c 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -703,7 +703,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri return } gmtTimeLoc := time.FixedZone("GMT+0530", int((5*time.Hour).Seconds()+(30*time.Minute).Seconds())) - humanReadableTime := parsedTime.In(gmtTimeLoc).Format(http.TimeFormat) + humanReadableTime := parsedTime.In(gmtTimeLoc).Format(time.RFC1123) res = append(res, humanReadableTime...) } From 811652207d848e105f3541700a1c57698b7e2ffb Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 13:38:55 +0530 Subject: [PATCH 19/24] const updated --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- pkg/k8s/application/bean/bean.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 5719d40ea8c..d5da3988fd2 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -702,7 +702,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) return } - gmtTimeLoc := time.FixedZone("GMT+0530", int((5*time.Hour).Seconds()+(30*time.Minute).Seconds())) + gmtTimeLoc := time.FixedZone(bean2.LocalTimezoneInGMT, bean2.LocalTimeOffset) humanReadableTime := parsedTime.In(gmtTimeLoc).Format(time.RFC1123) res = append(res, humanReadableTime...) } diff --git a/pkg/k8s/application/bean/bean.go b/pkg/k8s/application/bean/bean.go index 3348c6ad8f8..9793d96c38a 100644 --- a/pkg/k8s/application/bean/bean.go +++ b/pkg/k8s/application/bean/bean.go @@ -28,6 +28,11 @@ const ( IntegerBitSize = 64 ) +const ( + LocalTimezoneInGMT = "GMT+0530" + LocalTimeOffset = 5*60*60 + 30*60 +) + type ResourceInfo struct { PodName string `json:"podName"` } From 9b02a98924faca49d62e61c32dce5f879d742299 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 13:56:55 +0530 Subject: [PATCH 20/24] status code fix --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index d5da3988fd2..6ed4f898d57 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -729,7 +729,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } if len(dataBuffer.Bytes()) == 0 { - common.WriteJsonResp(w, errors.New("logs not found"), nil, http.StatusOK) + common.WriteJsonResp(w, errors.New("logs not found"), nil, http.StatusNoContent) return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) From c0251637a87e36a58b457c9077fa54ca0ec44d33 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 14:07:05 +0530 Subject: [PATCH 21/24] fix --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 6ed4f898d57..faf85ab0bd4 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -729,7 +729,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } if len(dataBuffer.Bytes()) == 0 { - common.WriteJsonResp(w, errors.New("logs not found"), nil, http.StatusNoContent) + common.WriteJsonResp(w, nil, fmt.Sprintf("logs not found"), http.StatusNoContent) return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) From fddac7122bdbc6b7f57438a2e9ed4f752bf01509 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 14:53:29 +0530 Subject: [PATCH 22/24] fix2 --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index faf85ab0bd4..6ed4f898d57 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -729,7 +729,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } if len(dataBuffer.Bytes()) == 0 { - common.WriteJsonResp(w, nil, fmt.Sprintf("logs not found"), http.StatusNoContent) + common.WriteJsonResp(w, errors.New("logs not found"), nil, http.StatusNoContent) return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) From d9562f73b6fba1ab637449084393aab3b8367f78 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Thu, 1 Feb 2024 15:09:20 +0530 Subject: [PATCH 23/24] fix3 --- api/k8s/application/k8sApplicationRestHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/k8s/application/k8sApplicationRestHandler.go b/api/k8s/application/k8sApplicationRestHandler.go index 6ed4f898d57..de39e3641a7 100644 --- a/api/k8s/application/k8sApplicationRestHandler.go +++ b/api/k8s/application/k8sApplicationRestHandler.go @@ -729,7 +729,7 @@ func (handler *K8sApplicationRestHandlerImpl) DownloadPodLogs(w http.ResponseWri } } if len(dataBuffer.Bytes()) == 0 { - common.WriteJsonResp(w, errors.New("logs not found"), nil, http.StatusNoContent) + common.WriteJsonResp(w, nil, nil, http.StatusNoContent) return } podLogsFilename := generatePodLogsFilename(request.K8sRequest.ResourceIdentifier.Name) From fa71261c51a0ae901470d454b5ab62365b36f9c6 Mon Sep 17 00:00:00 2001 From: ashish sonam Date: Mon, 5 Feb 2024 19:43:46 +0530 Subject: [PATCH 24/24] common lib version upgrade --- go.mod | 2 +- go.sum | 4 ++-- .../github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go | 2 +- vendor/modules.txt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 0faea94e0af..23e24864430 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.33 - github.com/devtron-labs/common-lib v0.0.11-beta3 + github.com/devtron-labs/common-lib v0.0.12 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index 40707a9e617..8524ccbc183 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/devtron-labs/authenticator v0.4.33 h1:FpAV3ZgFluaRFcMwPpwxr/mwSipJ16XRvgABq3BzP5Y= github.com/devtron-labs/authenticator v0.4.33/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= -github.com/devtron-labs/common-lib v0.0.11-beta3 h1:o44QgEwFqNOR9fWaJwEL3lZmEWSfLC+cRSVryXfurRc= -github.com/devtron-labs/common-lib v0.0.11-beta3/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= +github.com/devtron-labs/common-lib v0.0.12 h1:HirqTWtaXWPbfGeqQurjtn26b2Az7sMFZ1JAAz2koNM= +github.com/devtron-labs/common-lib v0.0.12/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index d17385dfb0d..cb183b6608a 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -1231,7 +1231,7 @@ func (impl K8sServiceImpl) GetPodLogs(ctx context.Context, restConfig *rest.Conf if SinceSeconds > 0 { podLogOptions.SinceSeconds = &SinceSeconds } - if *sinceTime != metav1.Time(startTime) { + if *sinceTime != startTime { podLogOptions.SinceTime = sinceTime } podIf := podClient.Pods(namespace) diff --git a/vendor/modules.txt b/vendor/modules.txt index b459c7dada3..305736d44ff 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.11-beta3 +# github.com/devtron-labs/common-lib v0.0.12 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/cloud-provider-identifier