@@ -20,12 +20,11 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
- "github.com/devtron-labs/common-lib/utils/k8s/health"
24
23
apiBean "github.com/devtron-labs/devtron/api/bean"
25
- argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean"
26
24
"github.com/devtron-labs/devtron/client/gitSensor"
27
25
"github.com/devtron-labs/devtron/internal/sql/repository"
28
26
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging"
27
+ "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/cdWorkflow"
29
28
"github.com/devtron-labs/devtron/internal/util"
30
29
"github.com/devtron-labs/devtron/pkg/sql"
31
30
"github.com/go-pg/pg"
@@ -84,46 +83,12 @@ type CdWorkflowRepositoryImpl struct {
84
83
logger * zap.SugaredLogger
85
84
}
86
85
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
-
121
86
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"`
127
92
Pipeline * Pipeline
128
93
CiArtifact * repository.CiArtifact
129
94
CdWorkflowRunner []CdWorkflowRunner
@@ -151,53 +116,40 @@ type CdWorkflowConfig struct {
151
116
CdArtifactLocationFormat string `sql:"cd_artifact_location_format"`
152
117
}
153
118
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
-
167
119
type CdWorkflowRunnerWithExtraFields struct {
168
120
CdWorkflowRunner
169
121
TotalCount int
170
122
}
171
123
172
124
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"`
192
144
CdWorkflow * CdWorkflow
193
145
sql.AuditLog
194
146
}
195
147
196
148
func (c * CdWorkflowRunner ) IsExternalRun () bool {
197
149
var isExtCluster bool
198
- if c .WorkflowType == WorkflowTypePre {
150
+ if c .WorkflowType == cdWorkflow . WorkflowTypePre {
199
151
isExtCluster = c .CdWorkflow .Pipeline .RunPreStageInEnv
200
- } else if c .WorkflowType == WorkflowTypePost {
152
+ } else if c .WorkflowType == cdWorkflow . WorkflowTypePost {
201
153
isExtCluster = c .CdWorkflow .Pipeline .RunPostStageInEnv
202
154
}
203
155
return isExtCluster
@@ -492,7 +444,7 @@ func (impl *CdWorkflowRepositoryImpl) FindLastUnFailedProcessedRunner(appId int,
492
444
Where ("p.environment_id = ?" , environmentId ).
493
445
Where ("p.app_id = ?" , appId ).
494
446
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 })).
496
448
Order ("cd_workflow_runner.id DESC" ).
497
449
Join ("inner join cd_workflow wf on wf.id = cd_workflow_runner.cd_workflow_id" ).
498
450
Join ("inner join pipeline p on p.id = wf.pipeline_id" ).
@@ -557,7 +509,7 @@ func (impl *CdWorkflowRepositoryImpl) GetPreviousQueuedRunners(cdWfrId, pipeline
557
509
Where ("workflow_type = ?" , apiBean .CD_WORKFLOW_TYPE_DEPLOY ).
558
510
Where ("cd_workflow.pipeline_id = ?" , pipelineId ).
559
511
Where ("cd_workflow_runner.id < ?" , cdWfrId ).
560
- Where ("cd_workflow_runner.status = ?" , WorkflowInQueue ).
512
+ Where ("cd_workflow_runner.status = ?" , cdWorkflow . WorkflowInQueue ).
561
513
Select ()
562
514
return cdWfrs , err
563
515
}
@@ -567,7 +519,7 @@ func (impl *CdWorkflowRepositoryImpl) UpdateRunnerStatusToFailedForIds(errMsg st
567
519
return nil
568
520
}
569
521
_ , err := impl .dbConnection .Model ((* CdWorkflowRunner )(nil )).
570
- Set ("status = ?" , WorkflowFailed ).
522
+ Set ("status = ?" , cdWorkflow . WorkflowFailed ).
571
523
Set ("finished_on = ?" , time .Now ()).
572
524
Set ("updated_on = ?" , time .Now ()).
573
525
Set ("updated_by = ?" , triggeredBy ).
@@ -763,8 +715,8 @@ func (impl *CdWorkflowRepositoryImpl) FetchArtifactsByCdPipelineIdV2(listingFilt
763
715
764
716
func (impl * CdWorkflowRepositoryImpl ) GetLatestTriggersOfHelmPipelinesStuckInNonTerminalStatuses (getPipelineDeployedWithinHours int ) ([]* CdWorkflowRunner , error ) {
765
717
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 )
768
720
err := impl .dbConnection .
769
721
Model (& wfrList ).
770
722
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
776
728
" INNER JOIN cd_workflow_runner on cd_workflow.id = cd_workflow_runner.cd_workflow_id" +
777
729
" WHERE cd_workflow_runner.status != ?" +
778
730
" 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 ).
780
732
Where ("(cd_workflow__pipeline.deployment_app_type=? or dc.deployment_app_type=?)" , util .PIPELINE_DEPLOYMENT_TYPE_HELM , util .PIPELINE_DEPLOYMENT_TYPE_HELM ).
781
733
Where ("cd_workflow_runner.started_on > NOW() - INTERVAL '? hours'" , getPipelineDeployedWithinHours ).
782
734
Where ("cd_workflow__pipeline.deleted=?" , false ).
0 commit comments