From 0e51243cd26bb93dbd794143baddcc318b4b603a Mon Sep 17 00:00:00 2001 From: prakhar katiyar Date: Tue, 20 May 2025 16:26:00 +0530 Subject: [PATCH 1/6] reverted telemetry connection error --- client/telemetry/TelemetryEventClient.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/telemetry/TelemetryEventClient.go b/client/telemetry/TelemetryEventClient.go index bfa4bf15c2..d9bc89067c 100644 --- a/client/telemetry/TelemetryEventClient.go +++ b/client/telemetry/TelemetryEventClient.go @@ -690,6 +690,7 @@ func (impl *TelemetryEventClientImpl) checkForOptOut(ctx context.Context, UCID s if err != nil { // this should be non-blocking call and should not fail the request for ucid getting impl.logger.Errorw("check opt-out list failed, rest api error", "ucid", UCID, "err", err) + return false, err } flag := response["result"].(bool) return flag, nil From 25b7912a0a87e9b03e4ece90d04b4616741ac972 Mon Sep 17 00:00:00 2001 From: prakhar katiyar Date: Tue, 20 May 2025 16:34:10 +0530 Subject: [PATCH 2/6] reverted telemetry connection error --- client/telemetry/TelemetryEventClient.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/telemetry/TelemetryEventClient.go b/client/telemetry/TelemetryEventClient.go index d9bc89067c..df44eb6130 100644 --- a/client/telemetry/TelemetryEventClient.go +++ b/client/telemetry/TelemetryEventClient.go @@ -20,6 +20,7 @@ import ( "context" "encoding/base64" "encoding/json" + "errors" "fmt" cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier" posthogTelemetry "github.com/devtron-labs/common-lib/telemetry" @@ -692,7 +693,11 @@ func (impl *TelemetryEventClientImpl) checkForOptOut(ctx context.Context, UCID s impl.logger.Errorw("check opt-out list failed, rest api error", "ucid", UCID, "err", err) return false, err } - flag := response["result"].(bool) + flag, ok := response["result"].(bool) + if !ok { + impl.logger.Errorw("check opt-out list failed, type assertion error", "ucid", UCID) + return false, errors.New("type assertion error") + } return flag, nil } From 3872082423e1d19e48c5deb390d6fdb1713f217e Mon Sep 17 00:00:00 2001 From: Asutosh Das Date: Wed, 21 May 2025 16:03:32 +0530 Subject: [PATCH 3/6] fix: deployment status is stuck is progressing for parallel deployments in devtron application (#6591) * fix: deployment status is stuck is progressing for parallel deployments in devtron application * fix: reverted old implementation for GetSyncStartTime/ GetSyncFinishTime func * fix: added comment for fixme --- pkg/app/AppService.go | 25 ++-------- .../helper/deploymentStatusHelper.go | 47 +++++++++---------- 2 files changed, 28 insertions(+), 44 deletions(-) diff --git a/pkg/app/AppService.go b/pkg/app/AppService.go index 589f272bb3..c6df69e9a4 100644 --- a/pkg/app/AppService.go +++ b/pkg/app/AppService.go @@ -555,11 +555,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap if err != nil { impl.logger.Errorw("error in save/update pipeline status fetch detail", "err", err, "cdWfrId", runnerHistoryId) } - syncStartTime, found := helper.GetSyncStartTime(app) - if !found { - impl.logger.Warnw("sync operation not started yet", "app", app) - return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not started yet") - } + syncStartTime := helper.GetSyncStartTime(app, statusTime) // creating cd pipeline status timeline timeline := &pipelineConfig.PipelineStatusTimeline{ CdWorkflowRunnerId: runnerHistoryId, @@ -596,11 +592,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap timeline.Id = 0 timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED timeline.StatusDetail = app.Status.OperationState.Message - syncFinishTime, found := helper.GetSyncFinishTime(app) - if !found { - impl.logger.Warnw("sync operation not found for the deployment", "app", app) - return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not found for the deployment") - } + syncFinishTime := helper.GetSyncFinishTime(app, statusTime) timeline.StatusTime = syncFinishTime // checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil) @@ -679,11 +671,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap if err != nil { impl.logger.Errorw("error in save/update pipeline status fetch detail", "err", err, "installedAppVersionHistoryId", runnerHistoryId) } - syncStartTime, found := helper.GetSyncStartTime(app) - if !found { - impl.logger.Warnw("sync operation not started yet", "app", app) - return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not started yet") - } + syncStartTime := helper.GetSyncStartTime(app, statusTime) // creating installedAppVersionHistory status timeline timeline := &pipelineConfig.PipelineStatusTimeline{ InstalledAppVersionHistoryId: runnerHistoryId, @@ -720,11 +708,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap timeline.Id = 0 timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED timeline.StatusDetail = app.Status.OperationState.Message - syncFinishTime, found := helper.GetSyncFinishTime(app) - if !found { - impl.logger.Warnw("sync operation not found for the deployment", "app", app) - return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not found for the deployment") - } + syncFinishTime := helper.GetSyncFinishTime(app, statusTime) timeline.StatusTime = syncFinishTime // checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil) @@ -744,6 +728,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap haveNewTimeline = true timeline.Status = timelineStatus.TIMELINE_STATUS_APP_HEALTHY timeline.StatusDetail = "App status is Healthy." + timeline.StatusTime = statusTime } if haveNewTimeline { // not checking if this status is already present or not because already checked for terminal status existence earlier diff --git a/pkg/argoApplication/helper/deploymentStatusHelper.go b/pkg/argoApplication/helper/deploymentStatusHelper.go index ec9f7fc6ca..994e567a79 100644 --- a/pkg/argoApplication/helper/deploymentStatusHelper.go +++ b/pkg/argoApplication/helper/deploymentStatusHelper.go @@ -2,41 +2,40 @@ package helper import ( "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "time" ) // GetSyncStartTime assumes that it is always called for calculating start time of latest git hash -func GetSyncStartTime(app *v1alpha1.Application) (time.Time, bool) { +func GetSyncStartTime(app *v1alpha1.Application, defaultStartTime time.Time) time.Time { + startTime := metav1.NewTime(defaultStartTime) + // FIXME: this should be the git hash of the latest PCO gitHash := app.Status.Sync.Revision - if app.Status.OperationState != nil && - app.Status.OperationState.Operation.Sync != nil && - app.Status.OperationState.Operation.Sync.Revision == gitHash { - return app.Status.OperationState.StartedAt.Time, true - } else if len(app.Status.History) != 0 { - if app.Status.History.LastRevisionHistory().Revision == gitHash && - app.Status.History.LastRevisionHistory().DeployStartedAt != nil { - startTime := *app.Status.History.LastRevisionHistory().DeployStartedAt - return startTime.Time, true + if app.Status.OperationState != nil { + startTime = app.Status.OperationState.StartedAt + } else if app.Status.History != nil { + for _, history := range app.Status.History { + if history.Revision == gitHash { + startTime = *history.DeployStartedAt + } } } - return time.Time{}, false + return startTime.Time } // GetSyncFinishTime assumes that it is always called for calculating finish time of latest git hash -func GetSyncFinishTime(app *v1alpha1.Application) (time.Time, bool) { +func GetSyncFinishTime(app *v1alpha1.Application, defaultEndTime time.Time) time.Time { + finishTime := metav1.NewTime(defaultEndTime) + // FIXME: this should be the git hash of the latest PCO gitHash := app.Status.Sync.Revision - if app.Status.OperationState != nil && - app.Status.OperationState.Operation.Sync != nil && - app.Status.OperationState.Operation.Sync.Revision == gitHash && - app.Status.OperationState.FinishedAt != nil { - finishTime := *app.Status.OperationState.FinishedAt - return finishTime.Time, true - } else if len(app.Status.History) != 0 { - if app.Status.History.LastRevisionHistory().Revision == gitHash && - app.Status.History.LastRevisionHistory().DeployStartedAt != nil { - finishTime := *app.Status.History.LastRevisionHistory().DeployStartedAt - return finishTime.Time, true + if app.Status.OperationState != nil && app.Status.OperationState.FinishedAt != nil { + finishTime = *app.Status.OperationState.FinishedAt + } else if app.Status.History != nil { + for _, history := range app.Status.History { + if history.Revision == gitHash { + finishTime = history.DeployedAt + } } } - return time.Time{}, false + return finishTime.Time } From 2adc2f01ca9d5d3ce15359c0d8fae713592e9ef8 Mon Sep 17 00:00:00 2001 From: prakhar katiyar Date: Wed, 21 May 2025 18:06:46 +0530 Subject: [PATCH 4/6] validation in node drain --- api/k8s/capacity/k8sCapacityRestHandler.go | 14 +++++++++++++- pkg/k8s/capacity/bean/bean.go | 6 +++--- wire_gen.go | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/api/k8s/capacity/k8sCapacityRestHandler.go b/api/k8s/capacity/k8sCapacityRestHandler.go index a33edd1f7f..2dee3457f9 100644 --- a/api/k8s/capacity/k8sCapacityRestHandler.go +++ b/api/k8s/capacity/k8sCapacityRestHandler.go @@ -26,6 +26,7 @@ import ( "github.com/devtron-labs/devtron/pkg/cluster/rbac" "github.com/devtron-labs/devtron/pkg/cluster/read" bean3 "github.com/devtron-labs/devtron/pkg/k8s/bean" + "gopkg.in/go-playground/validator.v9" "net/http" "strconv" @@ -60,6 +61,7 @@ type K8sCapacityRestHandlerImpl struct { environmentService environment.EnvironmentService clusterRbacService rbac.ClusterRbacService clusterReadService read.ClusterReadService + validator *validator.Validate } func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger, @@ -68,7 +70,7 @@ func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger, clusterService cluster.ClusterService, environmentService environment.EnvironmentService, clusterRbacService rbac.ClusterRbacService, - clusterReadService read.ClusterReadService) *K8sCapacityRestHandlerImpl { + clusterReadService read.ClusterReadService, validator *validator.Validate) *K8sCapacityRestHandlerImpl { return &K8sCapacityRestHandlerImpl{ logger: logger, k8sCapacityService: k8sCapacityService, @@ -78,6 +80,7 @@ func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger, environmentService: environmentService, clusterRbacService: clusterRbacService, clusterReadService: clusterReadService, + validator: validator, } } @@ -401,6 +404,15 @@ func (handler *K8sCapacityRestHandlerImpl) DrainNode(w http.ResponseWriter, r *h common.WriteJsonResp(w, err, nil, http.StatusBadRequest) return } + + // Validate the struct using the validator + err = handler.validator.Struct(nodeDrainReq) + if err != nil { + handler.logger.Errorw("validation error", "err", err, "payload", nodeDrainReq) + common.WriteJsonResp(w, err, nil, http.StatusBadRequest) + return + } + userId, err := handler.userService.GetLoggedInUser(r) if userId == 0 || err != nil { common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) diff --git a/pkg/k8s/capacity/bean/bean.go b/pkg/k8s/capacity/bean/bean.go index a159857f02..8de6cbd409 100644 --- a/pkg/k8s/capacity/bean/bean.go +++ b/pkg/k8s/capacity/bean/bean.go @@ -168,14 +168,14 @@ type NodeConditionObject struct { } type NodeUpdateRequestDto struct { - ClusterId int `json:"clusterId"` - Name string `json:"name"` + ClusterId int `json:"clusterId" validate:"number,required"` + Name string `json:"name" validate:"number,required"` ManifestPatch string `json:"manifestPatch"` Version string `json:"version"` Kind string `json:"kind"` Taints []corev1.Taint `json:"taints"` NodeCordonHelper *NodeCordonHelper `json:"nodeCordonOptions"` - NodeDrainHelper *NodeDrainHelper `json:"nodeDrainOptions"` + NodeDrainHelper *NodeDrainHelper `json:"nodeDrainOptions" validate:"number,required"` } type NodeCordonHelper struct { diff --git a/wire_gen.go b/wire_gen.go index c8b8946d92..453c630603 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -1017,7 +1017,7 @@ func InitializeApp() (*App, error) { apiTokenRestHandlerImpl := apiToken2.NewApiTokenRestHandlerImpl(sugaredLogger, apiTokenServiceImpl, userServiceImpl, enforcerImpl, validate) apiTokenRouterImpl := apiToken2.NewApiTokenRouterImpl(apiTokenRestHandlerImpl) k8sCapacityServiceImpl := capacity.NewK8sCapacityServiceImpl(sugaredLogger, k8sApplicationServiceImpl, k8sServiceImpl, k8sCommonServiceImpl) - k8sCapacityRestHandlerImpl := capacity2.NewK8sCapacityRestHandlerImpl(sugaredLogger, k8sCapacityServiceImpl, userServiceImpl, enforcerImpl, clusterServiceImplExtended, environmentServiceImpl, clusterRbacServiceImpl, clusterReadServiceImpl) + k8sCapacityRestHandlerImpl := capacity2.NewK8sCapacityRestHandlerImpl(sugaredLogger, k8sCapacityServiceImpl, userServiceImpl, enforcerImpl, clusterServiceImplExtended, environmentServiceImpl, clusterRbacServiceImpl, clusterReadServiceImpl, validate) k8sCapacityRouterImpl := capacity2.NewK8sCapacityRouterImpl(k8sCapacityRestHandlerImpl) webhookHelmServiceImpl := webhookHelm.NewWebhookHelmServiceImpl(sugaredLogger, helmAppServiceImpl, clusterServiceImplExtended, chartRepositoryServiceImpl, attributesServiceImpl) webhookHelmRestHandlerImpl := webhookHelm2.NewWebhookHelmRestHandlerImpl(sugaredLogger, webhookHelmServiceImpl, userServiceImpl, enforcerImpl, validate) From aa128aeededc78efb8210203ebadd7c021592063 Mon Sep 17 00:00:00 2001 From: prakhar katiyar Date: Wed, 21 May 2025 18:11:08 +0530 Subject: [PATCH 5/6] validation in node drain --- pkg/k8s/capacity/bean/bean.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/k8s/capacity/bean/bean.go b/pkg/k8s/capacity/bean/bean.go index 8de6cbd409..5059b60986 100644 --- a/pkg/k8s/capacity/bean/bean.go +++ b/pkg/k8s/capacity/bean/bean.go @@ -169,13 +169,13 @@ type NodeConditionObject struct { type NodeUpdateRequestDto struct { ClusterId int `json:"clusterId" validate:"number,required"` - Name string `json:"name" validate:"number,required"` + Name string `json:"name" validate:"required"` ManifestPatch string `json:"manifestPatch"` Version string `json:"version"` Kind string `json:"kind"` Taints []corev1.Taint `json:"taints"` NodeCordonHelper *NodeCordonHelper `json:"nodeCordonOptions"` - NodeDrainHelper *NodeDrainHelper `json:"nodeDrainOptions" validate:"number,required"` + NodeDrainHelper *NodeDrainHelper `json:"nodeDrainOptions" validate:"required"` } type NodeCordonHelper struct { From e2ebb54076f9e273ec378b0987f2b4a8f1f6e037 Mon Sep 17 00:00:00 2001 From: Vikram Singh Date: Wed, 21 May 2025 18:39:38 +0530 Subject: [PATCH 6/6] vendor update in main --- go.mod | 4 ++-- go.sum | 8 ++++---- vendor/modules.txt | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index aad9a8cba5..1c981b9ffe 100644 --- a/go.mod +++ b/go.mod @@ -307,8 +307,8 @@ require ( replace ( github.com/argoproj/argo-workflows/v3 v3.5.13 => github.com/devtron-labs/argo-workflows/v3 v3.5.13 - github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495 - github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495 + github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d + github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 k8s.io/api => k8s.io/api v0.29.7 diff --git a/go.sum b/go.sum index 00f2869e2e..8cc7ac1d40 100644 --- a/go.sum +++ b/go.sum @@ -829,10 +829,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU= github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA= -github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495 h1:GBe/yfpn5uU3Myv0TV4KBvSLfuwRRjTN7uXAupeUhbk= -github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495 h1:aEJw3HPicUqpwBIZos5lsiNIuL1c4w5bqadkHyj+dAA= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495/go.mod h1:CXQGEo+kZc7JPX5hn4jJf1msal9q/ExSdAYGkHNPnQw= +github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d h1:qpuY6DRamKhlou0ODh2hC/JlzUEnb/3ziEWs6wyKpx8= +github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d h1:q0a5FgU3HowrydPq+BjIMHCF0izHjl1oPc71JDLsv+8= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d/go.mod h1:CXQGEo+kZc7JPX5hn4jJf1msal9q/ExSdAYGkHNPnQw= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs= diff --git a/vendor/modules.txt b/vendor/modules.txt index d45b2218f0..a13d2e8ad3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -472,7 +472,7 @@ github.com/davecgh/go-spew/spew # github.com/deckarep/golang-set v1.8.0 ## explicit; go 1.17 github.com/deckarep/golang-set -# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495 +# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d ## explicit; go 1.21 github.com/devtron-labs/authenticator/apiToken github.com/devtron-labs/authenticator/client @@ -480,7 +480,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.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495 +# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage @@ -2358,8 +2358,8 @@ xorm.io/xorm/log xorm.io/xorm/names xorm.io/xorm/schemas xorm.io/xorm/tags -# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495 -# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495 +# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d +# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d # github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 # github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 # k8s.io/api => k8s.io/api v0.29.7