Skip to content

sync: Main sync develop #6599

New issue

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

Merged
merged 14 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api/k8s/capacity/k8sCapacityRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -60,6 +61,7 @@ type K8sCapacityRestHandlerImpl struct {
environmentService environment.EnvironmentService
clusterRbacService rbac.ClusterRbacService
clusterReadService read.ClusterReadService
validator *validator.Validate
}

func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger,
Expand All @@ -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,
Expand All @@ -78,6 +80,7 @@ func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger,
environmentService: environmentService,
clusterRbacService: clusterRbacService,
clusterReadService: clusterReadService,
validator: validator,
}
}

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion client/telemetry/TelemetryEventClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -690,8 +691,13 @@ 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, 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")
}
flag := response["result"].(bool)
return flag, nil
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 5 additions & 20 deletions pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
47 changes: 23 additions & 24 deletions pkg/argoApplication/helper/deploymentStatusHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/k8s/capacity/bean/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"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:"required"`
}

type NodeCordonHelper struct {
Expand Down
8 changes: 4 additions & 4 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,15 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.