Skip to content

Commit f838a02

Browse files
committed
main sync develop
2 parents 4e0df6d + 9e14fd3 commit f838a02

File tree

9 files changed

+62
-60
lines changed

9 files changed

+62
-60
lines changed

api/k8s/capacity/k8sCapacityRestHandler.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/devtron-labs/devtron/pkg/cluster/rbac"
2727
"github.com/devtron-labs/devtron/pkg/cluster/read"
2828
bean3 "github.com/devtron-labs/devtron/pkg/k8s/bean"
29+
"gopkg.in/go-playground/validator.v9"
2930
"net/http"
3031
"strconv"
3132

@@ -60,6 +61,7 @@ type K8sCapacityRestHandlerImpl struct {
6061
environmentService environment.EnvironmentService
6162
clusterRbacService rbac.ClusterRbacService
6263
clusterReadService read.ClusterReadService
64+
validator *validator.Validate
6365
}
6466

6567
func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger,
@@ -68,7 +70,7 @@ func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger,
6870
clusterService cluster.ClusterService,
6971
environmentService environment.EnvironmentService,
7072
clusterRbacService rbac.ClusterRbacService,
71-
clusterReadService read.ClusterReadService) *K8sCapacityRestHandlerImpl {
73+
clusterReadService read.ClusterReadService, validator *validator.Validate) *K8sCapacityRestHandlerImpl {
7274
return &K8sCapacityRestHandlerImpl{
7375
logger: logger,
7476
k8sCapacityService: k8sCapacityService,
@@ -78,6 +80,7 @@ func NewK8sCapacityRestHandlerImpl(logger *zap.SugaredLogger,
7880
environmentService: environmentService,
7981
clusterRbacService: clusterRbacService,
8082
clusterReadService: clusterReadService,
83+
validator: validator,
8184
}
8285
}
8386

@@ -401,6 +404,15 @@ func (handler *K8sCapacityRestHandlerImpl) DrainNode(w http.ResponseWriter, r *h
401404
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
402405
return
403406
}
407+
408+
// Validate the struct using the validator
409+
err = handler.validator.Struct(nodeDrainReq)
410+
if err != nil {
411+
handler.logger.Errorw("validation error", "err", err, "payload", nodeDrainReq)
412+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
413+
return
414+
}
415+
404416
userId, err := handler.userService.GetLoggedInUser(r)
405417
if userId == 0 || err != nil {
406418
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)

client/telemetry/TelemetryEventClient.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"encoding/json"
23+
"errors"
2324
"fmt"
2425
cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier"
2526
posthogTelemetry "github.com/devtron-labs/common-lib/telemetry"
@@ -690,8 +691,13 @@ func (impl *TelemetryEventClientImpl) checkForOptOut(ctx context.Context, UCID s
690691
if err != nil {
691692
// this should be non-blocking call and should not fail the request for ucid getting
692693
impl.logger.Errorw("check opt-out list failed, rest api error", "ucid", UCID, "err", err)
694+
return false, err
695+
}
696+
flag, ok := response["result"].(bool)
697+
if !ok {
698+
impl.logger.Errorw("check opt-out list failed, type assertion error", "ucid", UCID)
699+
return false, errors.New("type assertion error")
693700
}
694-
flag := response["result"].(bool)
695701
return flag, nil
696702
}
697703

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ require (
307307

308308
replace (
309309
github.com/argoproj/argo-workflows/v3 v3.5.13 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
310-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495
311-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495
310+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d
311+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d
312312
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
313313
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
314314
k8s.io/api => k8s.io/api v0.29.7

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
829829
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
830830
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
831831
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
832-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495 h1:GBe/yfpn5uU3Myv0TV4KBvSLfuwRRjTN7uXAupeUhbk=
833-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495 h1:aEJw3HPicUqpwBIZos5lsiNIuL1c4w5bqadkHyj+dAA=
835-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495/go.mod h1:CXQGEo+kZc7JPX5hn4jJf1msal9q/ExSdAYGkHNPnQw=
832+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d h1:qpuY6DRamKhlou0ODh2hC/JlzUEnb/3ziEWs6wyKpx8=
833+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d h1:q0a5FgU3HowrydPq+BjIMHCF0izHjl1oPc71JDLsv+8=
835+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d/go.mod h1:CXQGEo+kZc7JPX5hn4jJf1msal9q/ExSdAYGkHNPnQw=
836836
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
837837
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
838838
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=

pkg/app/AppService.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
555555
if err != nil {
556556
impl.logger.Errorw("error in save/update pipeline status fetch detail", "err", err, "cdWfrId", runnerHistoryId)
557557
}
558-
syncStartTime, found := helper.GetSyncStartTime(app)
559-
if !found {
560-
impl.logger.Warnw("sync operation not started yet", "app", app)
561-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not started yet")
562-
}
558+
syncStartTime := helper.GetSyncStartTime(app, statusTime)
563559
// creating cd pipeline status timeline
564560
timeline := &pipelineConfig.PipelineStatusTimeline{
565561
CdWorkflowRunnerId: runnerHistoryId,
@@ -596,11 +592,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
596592
timeline.Id = 0
597593
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
598594
timeline.StatusDetail = app.Status.OperationState.Message
599-
syncFinishTime, found := helper.GetSyncFinishTime(app)
600-
if !found {
601-
impl.logger.Warnw("sync operation not found for the deployment", "app", app)
602-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not found for the deployment")
603-
}
595+
syncFinishTime := helper.GetSyncFinishTime(app, statusTime)
604596
timeline.StatusTime = syncFinishTime
605597
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
606598
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
@@ -679,11 +671,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
679671
if err != nil {
680672
impl.logger.Errorw("error in save/update pipeline status fetch detail", "err", err, "installedAppVersionHistoryId", runnerHistoryId)
681673
}
682-
syncStartTime, found := helper.GetSyncStartTime(app)
683-
if !found {
684-
impl.logger.Warnw("sync operation not started yet", "app", app)
685-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not started yet")
686-
}
674+
syncStartTime := helper.GetSyncStartTime(app, statusTime)
687675
// creating installedAppVersionHistory status timeline
688676
timeline := &pipelineConfig.PipelineStatusTimeline{
689677
InstalledAppVersionHistoryId: runnerHistoryId,
@@ -720,11 +708,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
720708
timeline.Id = 0
721709
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
722710
timeline.StatusDetail = app.Status.OperationState.Message
723-
syncFinishTime, found := helper.GetSyncFinishTime(app)
724-
if !found {
725-
impl.logger.Warnw("sync operation not found for the deployment", "app", app)
726-
return isTimelineUpdated, isTimelineTimedOut, kubectlApplySyncedTimeline, fmt.Errorf("sync operation not found for the deployment")
727-
}
711+
syncFinishTime := helper.GetSyncFinishTime(app, statusTime)
728712
timeline.StatusTime = syncFinishTime
729713
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
730714
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
@@ -744,6 +728,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
744728
haveNewTimeline = true
745729
timeline.Status = timelineStatus.TIMELINE_STATUS_APP_HEALTHY
746730
timeline.StatusDetail = "App status is Healthy."
731+
timeline.StatusTime = statusTime
747732
}
748733
if haveNewTimeline {
749734
// not checking if this status is already present or not because already checked for terminal status existence earlier

pkg/argoApplication/helper/deploymentStatusHelper.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,40 @@ package helper
22

33
import (
44
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
"time"
67
)
78

89
// GetSyncStartTime assumes that it is always called for calculating start time of latest git hash
9-
func GetSyncStartTime(app *v1alpha1.Application) (time.Time, bool) {
10+
func GetSyncStartTime(app *v1alpha1.Application, defaultStartTime time.Time) time.Time {
11+
startTime := metav1.NewTime(defaultStartTime)
12+
// FIXME: this should be the git hash of the latest PCO
1013
gitHash := app.Status.Sync.Revision
11-
if app.Status.OperationState != nil &&
12-
app.Status.OperationState.Operation.Sync != nil &&
13-
app.Status.OperationState.Operation.Sync.Revision == gitHash {
14-
return app.Status.OperationState.StartedAt.Time, true
15-
} else if len(app.Status.History) != 0 {
16-
if app.Status.History.LastRevisionHistory().Revision == gitHash &&
17-
app.Status.History.LastRevisionHistory().DeployStartedAt != nil {
18-
startTime := *app.Status.History.LastRevisionHistory().DeployStartedAt
19-
return startTime.Time, true
14+
if app.Status.OperationState != nil {
15+
startTime = app.Status.OperationState.StartedAt
16+
} else if app.Status.History != nil {
17+
for _, history := range app.Status.History {
18+
if history.Revision == gitHash {
19+
startTime = *history.DeployStartedAt
20+
}
2021
}
2122
}
22-
return time.Time{}, false
23+
return startTime.Time
2324
}
2425

2526
// GetSyncFinishTime assumes that it is always called for calculating finish time of latest git hash
26-
func GetSyncFinishTime(app *v1alpha1.Application) (time.Time, bool) {
27+
func GetSyncFinishTime(app *v1alpha1.Application, defaultEndTime time.Time) time.Time {
28+
finishTime := metav1.NewTime(defaultEndTime)
29+
// FIXME: this should be the git hash of the latest PCO
2730
gitHash := app.Status.Sync.Revision
28-
if app.Status.OperationState != nil &&
29-
app.Status.OperationState.Operation.Sync != nil &&
30-
app.Status.OperationState.Operation.Sync.Revision == gitHash &&
31-
app.Status.OperationState.FinishedAt != nil {
32-
finishTime := *app.Status.OperationState.FinishedAt
33-
return finishTime.Time, true
34-
} else if len(app.Status.History) != 0 {
35-
if app.Status.History.LastRevisionHistory().Revision == gitHash &&
36-
app.Status.History.LastRevisionHistory().DeployStartedAt != nil {
37-
finishTime := *app.Status.History.LastRevisionHistory().DeployStartedAt
38-
return finishTime.Time, true
31+
if app.Status.OperationState != nil && app.Status.OperationState.FinishedAt != nil {
32+
finishTime = *app.Status.OperationState.FinishedAt
33+
} else if app.Status.History != nil {
34+
for _, history := range app.Status.History {
35+
if history.Revision == gitHash {
36+
finishTime = history.DeployedAt
37+
}
3938
}
4039
}
41-
return time.Time{}, false
40+
return finishTime.Time
4241
}

pkg/k8s/capacity/bean/bean.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ type NodeConditionObject struct {
168168
}
169169

170170
type NodeUpdateRequestDto struct {
171-
ClusterId int `json:"clusterId"`
172-
Name string `json:"name"`
171+
ClusterId int `json:"clusterId" validate:"number,required"`
172+
Name string `json:"name" validate:"required"`
173173
ManifestPatch string `json:"manifestPatch"`
174174
Version string `json:"version"`
175175
Kind string `json:"kind"`
176176
Taints []corev1.Taint `json:"taints"`
177177
NodeCordonHelper *NodeCordonHelper `json:"nodeCordonOptions"`
178-
NodeDrainHelper *NodeDrainHelper `json:"nodeDrainOptions"`
178+
NodeDrainHelper *NodeDrainHelper `json:"nodeDrainOptions" validate:"required"`
179179
}
180180

181181
type NodeCordonHelper struct {

vendor/modules.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,15 @@ github.com/davecgh/go-spew/spew
472472
# github.com/deckarep/golang-set v1.8.0
473473
## explicit; go 1.17
474474
github.com/deckarep/golang-set
475-
# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495
475+
# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d
476476
## explicit; go 1.21
477477
github.com/devtron-labs/authenticator/apiToken
478478
github.com/devtron-labs/authenticator/client
479479
github.com/devtron-labs/authenticator/jwt
480480
github.com/devtron-labs/authenticator/middleware
481481
github.com/devtron-labs/authenticator/oidc
482482
github.com/devtron-labs/authenticator/password
483-
# 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
483+
# 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
484484
## explicit; go 1.21
485485
github.com/devtron-labs/common-lib/async
486486
github.com/devtron-labs/common-lib/blob-storage
@@ -2358,8 +2358,8 @@ xorm.io/xorm/log
23582358
xorm.io/xorm/names
23592359
xorm.io/xorm/schemas
23602360
xorm.io/xorm/tags
2361-
# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250519113737-b060cea3a495
2362-
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250519113737-b060cea3a495
2361+
# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250521130159-a5d26dc2ab8d
2362+
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250521130159-a5d26dc2ab8d
23632363
# github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
23642364
# github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
23652365
# k8s.io/api => k8s.io/api v0.29.7

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)