Skip to content

Commit 85710ec

Browse files
feat: added deployment failed message in deployment history (#5845)
* feat: added updated api specs for orchestrator/application/deployment-history api * feat: added deployment failed message in deployment history * updated migration version * FailedStatusUpdateOption signature updated * fixed GetEmailById method * updated migration version * updated migration version * updated migration message formatting * handled rbac for the source changing to external-ci * change in patch source info of cdpipeline config object * resolved the comments after 1st review --------- Co-authored-by: Rajeev <[email protected]>
1 parent 3fa1069 commit 85710ec

File tree

56 files changed

+1533
-1075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1533
-1075
lines changed

api/appStore/deployment/CommonDeploymentRestHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (handler *CommonDeploymentRestHandlerImpl) GetDeploymentHistory(w http.Resp
171171
}
172172
//rbac block ends here
173173

174-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
174+
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
175175
defer cancel()
176176
res, err := handler.appStoreDeploymentService.GetDeploymentHistory(ctx, installedAppDto)
177177
if err != nil {

api/auth/user/UserRestHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ func (handler UserRestHandlerImpl) SyncOrchestratorToCasbin(w http.ResponseWrite
10381038
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
10391039
return
10401040
}
1041-
userEmailId, err := handler.userService.GetEmailById(userId)
1041+
userEmailId, err := handler.userService.GetActiveEmailById(userId)
10421042
if err != nil {
10431043
handler.logger.Errorw("service err, SyncOrchestratorToCasbin", "err", err, "userId", userId)
10441044
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

api/helm-app/gRPC/applist.pb.go

Lines changed: 397 additions & 387 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/helm-app/gRPC/applist.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ message HelmAppDeploymentDetail {
252252
google.protobuf.Timestamp deployedAt = 4;
253253
string deployedBy = 5;
254254
string status = 6;
255+
string message = 7;
255256
}
256257

257258
message HelmAppDeploymentHistory {

api/helm-app/gRPC/applist_grpc.pb.go

Lines changed: 49 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/restHandler/UserAttributesRestHandler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (handler *UserAttributesRestHandlerImpl) AddUserAttributes(w http.ResponseW
7373
// common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
7474
// return
7575
//}
76-
emailId, err := handler.userService.GetEmailById(userId)
76+
emailId, err := handler.userService.GetActiveEmailById(userId)
7777
if err != nil {
7878
handler.logger.Errorw("request err, UpdateUserAttributes", "err", err, "payload", dto)
7979
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
@@ -119,7 +119,7 @@ func (handler *UserAttributesRestHandlerImpl) UpdateUserAttributes(w http.Respon
119119
// return
120120
//}
121121

122-
emailId, err := handler.userService.GetEmailById(userId)
122+
emailId, err := handler.userService.GetActiveEmailById(userId)
123123
if err != nil {
124124
handler.logger.Errorw("request err, UpdateUserAttributes", "err", err, "payload", dto)
125125
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
@@ -165,7 +165,7 @@ func (handler *UserAttributesRestHandlerImpl) GetUserAttribute(w http.ResponseWr
165165

166166
dto := attributes.UserAttributesDto{}
167167

168-
emailId, err := handler.userService.GetEmailById(userId)
168+
emailId, err := handler.userService.GetActiveEmailById(userId)
169169
if err != nil {
170170
handler.logger.Errorw("request err, UpdateUserAttributes", "err", err, "payload", dto)
171171
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)

api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,26 @@ func (handler *PipelineConfigRestHandlerImpl) CreateCdPipeline(w http.ResponseWr
237237
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
238238
return
239239
}
240+
ok := true
240241
for _, deploymentPipeline := range cdPipeline.Pipelines {
241-
if deploymentPipeline.EnvironmentId > 0 {
242-
object := handler.enforcerUtil.GetAppRBACByAppNameAndEnvId(app.AppName, deploymentPipeline.EnvironmentId)
243-
handler.Logger.Debugw("Triggered Request By:", "object", object)
244-
if ok := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionCreate, object); !ok {
245-
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
242+
//handling case of change of source from CI_PIPELINE to external-ci type (other change of type any -> any has been handled in ci-pipeline/patch api)
243+
if deploymentPipeline.IsSwitchCiPipelineRequest() {
244+
cdPipelines, err := handler.getCdPipelinesForCdPatchRbac(deploymentPipeline)
245+
if err != nil && !errors.Is(err, pg.ErrNoRows) {
246+
handler.Logger.Errorw("error in finding cdPipelines by deploymentPipeline", "deploymentPipeline", deploymentPipeline, "err", err)
247+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
246248
return
247249
}
250+
ok = handler.checkCiPatchAccess(token, resourceName, cdPipelines)
251+
252+
} else if deploymentPipeline.EnvironmentId > 0 {
253+
object := handler.enforcerUtil.GetAppRBACByAppNameAndEnvId(app.AppName, deploymentPipeline.EnvironmentId)
254+
handler.Logger.Debugw("Triggered Request By:", "object", object)
255+
ok = handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionCreate, object)
256+
}
257+
if !ok {
258+
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
259+
return
248260
}
249261
}
250262
//RBAC
@@ -2561,3 +2573,28 @@ func (handler *PipelineConfigRestHandlerImpl) GetGitOpsConfiguration(w http.Resp
25612573
}
25622574
common.WriteJsonResp(w, nil, appGitOpsConfig, http.StatusOK)
25632575
}
2576+
2577+
// this is being used for getting all cdPipelines in the case of changing the source from any [except] -> external-ci
2578+
func (handler *PipelineConfigRestHandlerImpl) getCdPipelinesForCdPatchRbac(deploymentPipeline *bean.CDPipelineConfigObject) (cdPipelines []*pipelineConfig.Pipeline, err error) {
2579+
componentId, componentType := deploymentPipeline.PatchSourceInfo()
2580+
// the appWorkflowId can be taken from patchRequest.AppWorkflowId but doing this can make 2 sources of truth to find the workflow
2581+
sourceAppWorkflowMapping, err := handler.appWorkflowService.FindWFMappingByComponent(componentType, componentId)
2582+
if err != nil {
2583+
handler.Logger.Errorw("error in finding the appWorkflowMapping using componentId and componentType", "componentType", componentType, "componentId", componentId, "err", err)
2584+
return nil, err
2585+
}
2586+
cdPipelineWFMappings, err := handler.appWorkflowService.FindWFCDMappingsByWorkflowId(sourceAppWorkflowMapping.AppWorkflowId)
2587+
if err != nil {
2588+
handler.Logger.Errorw("error in finding the appWorkflowMappings of cd pipeline for an appWorkflow", "appWorkflowId", sourceAppWorkflowMapping.AppWorkflowId, "err", err)
2589+
return cdPipelines, err
2590+
}
2591+
if len(cdPipelineWFMappings) == 0 {
2592+
return
2593+
}
2594+
2595+
cdPipelineIds := make([]int, 0, len(cdPipelineWFMappings))
2596+
for _, cdWfMapping := range cdPipelineWFMappings {
2597+
cdPipelineIds = append(cdPipelineIds, cdWfMapping.ComponentId)
2598+
}
2599+
return handler.pipelineRepository.FindByIdsIn(cdPipelineIds)
2600+
}

cmd/external-app/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.

internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go

Lines changed: 33 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"github.com/devtron-labs/common-lib/utils/k8s/health"
2423
apiBean "github.com/devtron-labs/devtron/api/bean"
25-
argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean"
2624
"github.com/devtron-labs/devtron/client/gitSensor"
2725
"github.com/devtron-labs/devtron/internal/sql/repository"
2826
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging"
27+
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/cdWorkflow"
2928
"github.com/devtron-labs/devtron/internal/util"
3029
"github.com/devtron-labs/devtron/pkg/sql"
3130
"github.com/go-pg/pg"
@@ -84,46 +83,12 @@ type CdWorkflowRepositoryImpl struct {
8483
logger *zap.SugaredLogger
8584
}
8685

87-
type WorkflowStatus int
88-
89-
const (
90-
WF_UNKNOWN WorkflowStatus = iota
91-
REQUEST_ACCEPTED
92-
ENQUEUED
93-
QUE_ERROR
94-
WF_STARTED
95-
DROPPED_STALE
96-
DEQUE_ERROR
97-
TRIGGER_ERROR
98-
)
99-
100-
const (
101-
WorkflowStarting = "Starting"
102-
WorkflowInQueue = "Queued"
103-
WorkflowInitiated = "Initiating"
104-
WorkflowInProgress = "Progressing"
105-
WorkflowAborted = "Aborted"
106-
WorkflowFailed = "Failed"
107-
WorkflowSucceeded = "Succeeded"
108-
WorkflowTimedOut = "TimedOut"
109-
WorkflowUnableToFetchState = "UnableToFetch"
110-
WorkflowTypeDeploy = "DEPLOY"
111-
WorkflowTypePre = "PRE"
112-
WorkflowTypePost = "POST"
113-
)
114-
115-
var WfrTerminalStatusList = []string{WorkflowAborted, WorkflowFailed, WorkflowSucceeded, argoApplication.HIBERNATING, string(health.HealthStatusHealthy), string(health.HealthStatusDegraded)}
116-
117-
func (a WorkflowStatus) String() string {
118-
return [...]string{"WF_UNKNOWN", "REQUEST_ACCEPTED", "ENQUEUED", "QUE_ERROR", "WF_STARTED", "DROPPED_STALE", "DEQUE_ERROR", "TRIGGER_ERROR"}[a]
119-
}
120-
12186
type CdWorkflow struct {
122-
tableName struct{} `sql:"cd_workflow" pg:",discard_unknown_columns"`
123-
Id int `sql:"id,pk"`
124-
CiArtifactId int `sql:"ci_artifact_id"`
125-
PipelineId int `sql:"pipeline_id"`
126-
WorkflowStatus WorkflowStatus `sql:"workflow_status,notnull"`
87+
tableName struct{} `sql:"cd_workflow" pg:",discard_unknown_columns"`
88+
Id int `sql:"id,pk"`
89+
CiArtifactId int `sql:"ci_artifact_id"`
90+
PipelineId int `sql:"pipeline_id"`
91+
WorkflowStatus cdWorkflow.WorkflowStatus `sql:"workflow_status,notnull"`
12792
Pipeline *Pipeline
12893
CiArtifact *repository.CiArtifact
12994
CdWorkflowRunner []CdWorkflowRunner
@@ -151,53 +116,40 @@ type CdWorkflowConfig struct {
151116
CdArtifactLocationFormat string `sql:"cd_artifact_location_format"`
152117
}
153118

154-
type WorkflowExecutorType string
155-
156-
var ErrorDeploymentSuperseded = errors.New(NEW_DEPLOYMENT_INITIATED)
157-
158-
const (
159-
WORKFLOW_EXECUTOR_TYPE_AWF = "AWF"
160-
WORKFLOW_EXECUTOR_TYPE_SYSTEM = "SYSTEM"
161-
NEW_DEPLOYMENT_INITIATED = "A new deployment was initiated before this deployment completed!"
162-
PIPELINE_DELETED = "The pipeline has been deleted!"
163-
FOUND_VULNERABILITY = "Found vulnerability on image"
164-
GITOPS_REPO_NOT_CONFIGURED = "GitOps repository is not configured for the app"
165-
)
166-
167119
type CdWorkflowRunnerWithExtraFields struct {
168120
CdWorkflowRunner
169121
TotalCount int
170122
}
171123

172124
type CdWorkflowRunner struct {
173-
tableName struct{} `sql:"cd_workflow_runner" pg:",discard_unknown_columns"`
174-
Id int `sql:"id,pk"`
175-
Name string `sql:"name"`
176-
WorkflowType apiBean.WorkflowType `sql:"workflow_type"` // pre,post,deploy
177-
ExecutorType WorkflowExecutorType `sql:"executor_type"` // awf, system
178-
Status string `sql:"status"`
179-
PodStatus string `sql:"pod_status"`
180-
Message string `sql:"message"`
181-
StartedOn time.Time `sql:"started_on"`
182-
FinishedOn time.Time `sql:"finished_on"`
183-
Namespace string `sql:"namespace"`
184-
LogLocation string `sql:"log_file_path"`
185-
TriggeredBy int32 `sql:"triggered_by"`
186-
CdWorkflowId int `sql:"cd_workflow_id"`
187-
PodName string `sql:"pod_name"`
188-
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
189-
RefCdWorkflowRunnerId int `sql:"ref_cd_workflow_runner_id,notnull"`
190-
ImagePathReservationIds []int `sql:"image_path_reservation_ids" pg:",array,notnull"`
191-
ReferenceId *string `sql:"reference_id"`
125+
tableName struct{} `sql:"cd_workflow_runner" pg:",discard_unknown_columns"`
126+
Id int `sql:"id,pk"`
127+
Name string `sql:"name"`
128+
WorkflowType apiBean.WorkflowType `sql:"workflow_type"` // pre,post,deploy
129+
ExecutorType cdWorkflow.WorkflowExecutorType `sql:"executor_type"` // awf, system
130+
Status string `sql:"status"`
131+
PodStatus string `sql:"pod_status"`
132+
Message string `sql:"message"`
133+
StartedOn time.Time `sql:"started_on"`
134+
FinishedOn time.Time `sql:"finished_on"`
135+
Namespace string `sql:"namespace"`
136+
LogLocation string `sql:"log_file_path"`
137+
TriggeredBy int32 `sql:"triggered_by"`
138+
CdWorkflowId int `sql:"cd_workflow_id"`
139+
PodName string `sql:"pod_name"`
140+
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
141+
RefCdWorkflowRunnerId int `sql:"ref_cd_workflow_runner_id,notnull"`
142+
ImagePathReservationIds []int `sql:"image_path_reservation_ids" pg:",array,notnull"`
143+
ReferenceId *string `sql:"reference_id"`
192144
CdWorkflow *CdWorkflow
193145
sql.AuditLog
194146
}
195147

196148
func (c *CdWorkflowRunner) IsExternalRun() bool {
197149
var isExtCluster bool
198-
if c.WorkflowType == WorkflowTypePre {
150+
if c.WorkflowType == cdWorkflow.WorkflowTypePre {
199151
isExtCluster = c.CdWorkflow.Pipeline.RunPreStageInEnv
200-
} else if c.WorkflowType == WorkflowTypePost {
152+
} else if c.WorkflowType == cdWorkflow.WorkflowTypePost {
201153
isExtCluster = c.CdWorkflow.Pipeline.RunPostStageInEnv
202154
}
203155
return isExtCluster
@@ -492,7 +444,7 @@ func (impl *CdWorkflowRepositoryImpl) FindLastUnFailedProcessedRunner(appId int,
492444
Where("p.environment_id = ?", environmentId).
493445
Where("p.app_id = ?", appId).
494446
Where("cd_workflow_runner.workflow_type = ?", apiBean.CD_WORKFLOW_TYPE_DEPLOY).
495-
Where("cd_workflow_runner.status NOT IN (?)", pg.In([]string{WorkflowInitiated, WorkflowInQueue, WorkflowFailed})).
447+
Where("cd_workflow_runner.status NOT IN (?)", pg.In([]string{cdWorkflow.WorkflowInitiated, cdWorkflow.WorkflowInQueue, cdWorkflow.WorkflowFailed})).
496448
Order("cd_workflow_runner.id DESC").
497449
Join("inner join cd_workflow wf on wf.id = cd_workflow_runner.cd_workflow_id").
498450
Join("inner join pipeline p on p.id = wf.pipeline_id").
@@ -557,7 +509,7 @@ func (impl *CdWorkflowRepositoryImpl) GetPreviousQueuedRunners(cdWfrId, pipeline
557509
Where("workflow_type = ?", apiBean.CD_WORKFLOW_TYPE_DEPLOY).
558510
Where("cd_workflow.pipeline_id = ?", pipelineId).
559511
Where("cd_workflow_runner.id < ?", cdWfrId).
560-
Where("cd_workflow_runner.status = ?", WorkflowInQueue).
512+
Where("cd_workflow_runner.status = ?", cdWorkflow.WorkflowInQueue).
561513
Select()
562514
return cdWfrs, err
563515
}
@@ -567,7 +519,7 @@ func (impl *CdWorkflowRepositoryImpl) UpdateRunnerStatusToFailedForIds(errMsg st
567519
return nil
568520
}
569521
_, err := impl.dbConnection.Model((*CdWorkflowRunner)(nil)).
570-
Set("status = ?", WorkflowFailed).
522+
Set("status = ?", cdWorkflow.WorkflowFailed).
571523
Set("finished_on = ?", time.Now()).
572524
Set("updated_on = ?", time.Now()).
573525
Set("updated_by = ?", triggeredBy).
@@ -763,8 +715,8 @@ func (impl *CdWorkflowRepositoryImpl) FetchArtifactsByCdPipelineIdV2(listingFilt
763715

764716
func (impl *CdWorkflowRepositoryImpl) GetLatestTriggersOfHelmPipelinesStuckInNonTerminalStatuses(getPipelineDeployedWithinHours int) ([]*CdWorkflowRunner, error) {
765717
var wfrList []*CdWorkflowRunner
766-
excludedStatusList := WfrTerminalStatusList
767-
excludedStatusList = append(excludedStatusList, WorkflowInitiated, WorkflowInQueue, WorkflowStarting)
718+
excludedStatusList := cdWorkflow.WfrTerminalStatusList
719+
excludedStatusList = append(excludedStatusList, cdWorkflow.WorkflowInitiated, cdWorkflow.WorkflowInQueue, cdWorkflow.WorkflowStarting)
768720
err := impl.dbConnection.
769721
Model(&wfrList).
770722
Column("cd_workflow_runner.*", "CdWorkflow.id", "CdWorkflow.pipeline_id", "CdWorkflow.Pipeline.id", "CdWorkflow.Pipeline.app_id", "CdWorkflow.Pipeline.environment_id", "CdWorkflow.Pipeline.deployment_app_name", "CdWorkflow.Pipeline.deleted", "CdWorkflow.Pipeline.Environment").
@@ -776,7 +728,7 @@ func (impl *CdWorkflowRepositoryImpl) GetLatestTriggersOfHelmPipelinesStuckInNon
776728
" INNER JOIN cd_workflow_runner on cd_workflow.id = cd_workflow_runner.cd_workflow_id"+
777729
" WHERE cd_workflow_runner.status != ?"+
778730
" GROUP BY cd_workflow.pipeline_id"+
779-
" ORDER BY cd_workflow.pipeline_id desc)", WorkflowInQueue).
731+
" ORDER BY cd_workflow.pipeline_id desc)", cdWorkflow.WorkflowInQueue).
780732
Where("(cd_workflow__pipeline.deployment_app_type=? or dc.deployment_app_type=?)", util.PIPELINE_DEPLOYMENT_TYPE_HELM, util.PIPELINE_DEPLOYMENT_TYPE_HELM).
781733
Where("cd_workflow_runner.started_on > NOW() - INTERVAL '? hours'", getPipelineDeployedWithinHours).
782734
Where("cd_workflow__pipeline.deleted=?", false).

0 commit comments

Comments
 (0)