Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f94fda6
retriggering ci-workflow with deleted workflow git triggers
gireesh-naidu Sep 12, 2023
555b2e4
re-triggering cd stages with current configurations
gireesh-naidu Sep 12, 2023
21924e0
sql script added
gireesh-naidu Sep 12, 2023
02d7a8b
added retrigger cancel checks
gireesh-naidu Sep 12, 2023
792905b
Merge branch 'main' into wf-pod-restart
gireesh-naidu Sep 13, 2023
cd07ac0
retry workflow method added in workflowstatus check cron
gireesh-naidu Sep 15, 2023
ec14e31
fixed bug around ci running in external cluster
gireesh-naidu Sep 15, 2023
e31498f
merge main
gireesh-naidu Sep 15, 2023
c1e9d76
get the status from wf itself
gireesh-naidu Sep 18, 2023
cb0d3c5
sending referenceWorkflowId in build history
gireesh-naidu Sep 18, 2023
c4844d9
code refactoring regarding duplicate GitCommit struct definition
gireesh-naidu Sep 18, 2023
449308b
code refactoring around error logging
gireesh-naidu Sep 18, 2023
6750c91
review comments incorporation
gireesh-naidu Sep 18, 2023
e63adeb
wire
gireesh-naidu Sep 18, 2023
71d6b0d
script number update
gireesh-naidu Sep 18, 2023
eb8137b
fix
gireesh-naidu Sep 18, 2023
19c0239
json key change
gireesh-naidu Sep 18, 2023
a062619
sending reference cd workflow runner id in deployment history api
gireesh-naidu Sep 19, 2023
d23278e
phase fix
gireesh-naidu Sep 26, 2023
d452455
merge main
gireesh-naidu Oct 3, 2023
6956b0e
script number update
gireesh-naidu Oct 3, 2023
948a416
fix
gireesh-naidu Oct 4, 2023
efa74dc
added missing reference workflow_runner_id
gireesh-naidu Oct 4, 2023
2a09fa9
query fix
gireesh-naidu Oct 5, 2023
10e67f2
debug logs added
gireesh-naidu Oct 5, 2023
2545a4f
fix
gireesh-naidu Oct 6, 2023
0be4246
log added
gireesh-naidu Oct 6, 2023
8f3ac09
refactor
gireesh-naidu Oct 6, 2023
27758f2
select iid instead of *
gireesh-naidu Oct 9, 2023
91744c3
Merge branch 'main' into wf-pod-restart
gireesh-naidu Oct 9, 2023
a56ae60
Merge branch 'main' into wf-pod-restart
gireesh-naidu Oct 10, 2023
13a0c69
refactoring code review changes
gireesh-naidu Oct 10, 2023
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: 14 additions & 0 deletions api/router/pubsub/WorkflowStatusUpdateHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ func (impl *WorkflowStatusUpdateHandlerImpl) Subscribe() error {
return
}

err = impl.ciHandler.HandleReTriggerCI(wfStatus)
if err != nil {
impl.logger.Errorw("error in HandleReTriggerCI", "err", err)
//don't return as we have to update the workflow status
}

_, err = impl.ciHandler.UpdateWorkflow(wfStatus)
if err != nil {
impl.logger.Errorw("error on update workflow status", "err", err, "msg", string(msg.Data))
return
}

}
err := impl.pubsubClient.Subscribe(pubsub.WORKFLOW_STATUS_UPDATE_TOPIC, callback)

Expand Down Expand Up @@ -125,6 +132,13 @@ func (impl *WorkflowStatusUpdateHandlerImpl) SubscribeCD() error {
} else if wfrStatus == string(v1alpha1.NodeFailed) || wfrStatus == string(v1alpha1.NodeError) {
eventType = util.Fail
}

if wfrStatus == string(v1alpha1.NodeFailed) && wfStatus.Message == pipeline.POD_DELETED_MESSAGE {
err = impl.cdHandler.HandleCdStageReTrigger(wfr)
if err != nil {
impl.logger.Errorw("error in HandleCdStageReTrigger", "error", err)
}
}
if wfr.WorkflowType == bean.CD_WORKFLOW_TYPE_PRE {
event := impl.eventFactory.Build(eventType, &wfr.CdWorkflow.PipelineId, wfr.CdWorkflow.Pipeline.AppId, &wfr.CdWorkflow.Pipeline.EnvironmentId, util.CD)
impl.logger.Debugw("event pre stage", "event", event)
Expand Down
1 change: 0 additions & 1 deletion api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter PipelineTriggerRouter, P
appGroupingRouter: appGroupingRouter,
rbacRoleRouter: rbacRoleRouter,
scopedVariableRouter: scopedVariableRouter,

}
return r
}
Expand Down
95 changes: 54 additions & 41 deletions internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pipelineConfig

import (
"context"
"fmt"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/client/argocdServer/application"
Expand Down Expand Up @@ -49,6 +50,7 @@ type CdWorkflowRepository interface {
FindPreviousCdWfRunnerByStatus(pipelineId int, currentWFRunnerId int, status []string) ([]*CdWorkflowRunner, error)
FindConfigByPipelineId(pipelineId int) (*CdWorkflowConfig, error)
FindWorkflowRunnerById(wfrId int) (*CdWorkflowRunner, error)
FindRetriedWorkflowCountByReferenceId(wfrId int) (int, error)
FindLatestWfrByAppIdAndEnvironmentId(appId int, environmentId int) (*CdWorkflowRunner, error)
FindLatestCdWorkflowRunnerByEnvironmentIdAndRunnerType(appId int, environmentId int, runnerType bean.WorkflowType) (CdWorkflowRunner, error)

Expand Down Expand Up @@ -143,23 +145,24 @@ const WORKFLOW_EXECUTOR_TYPE_AWF = "AWF"
const WORKFLOW_EXECUTOR_TYPE_SYSTEM = "SYSTEM"

type CdWorkflowRunner struct {
tableName struct{} `sql:"cd_workflow_runner" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
WorkflowType bean.WorkflowType `sql:"workflow_type"` //pre,post,deploy
ExecutorType WorkflowExecutorType `sql:"executor_type"` //awf, system
Status string `sql:"status"`
PodStatus string `sql:"pod_status"`
Message string `sql:"message"`
StartedOn time.Time `sql:"started_on"`
FinishedOn time.Time `sql:"finished_on"`
Namespace string `sql:"namespace"`
LogLocation string `sql:"log_file_path"`
TriggeredBy int32 `sql:"triggered_by"`
CdWorkflowId int `sql:"cd_workflow_id"`
PodName string `sql:"pod_name"`
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
CdWorkflow *CdWorkflow
tableName struct{} `sql:"cd_workflow_runner" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
WorkflowType bean.WorkflowType `sql:"workflow_type"` //pre,post,deploy
ExecutorType WorkflowExecutorType `sql:"executor_type"` //awf, system
Status string `sql:"status"`
PodStatus string `sql:"pod_status"`
Message string `sql:"message"`
StartedOn time.Time `sql:"started_on"`
FinishedOn time.Time `sql:"finished_on"`
Namespace string `sql:"namespace"`
LogLocation string `sql:"log_file_path"`
TriggeredBy int32 `sql:"triggered_by"`
CdWorkflowId int `sql:"cd_workflow_id"`
PodName string `sql:"pod_name"`
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
RefCdWorkflowRunnerId int `sql:"ref_cd_workflow_runner_id"`
CdWorkflow *CdWorkflow
sql.AuditLog
}

Expand All @@ -182,30 +185,31 @@ type CiPipelineMaterialResponse struct {
}

type CdWorkflowWithArtifact struct {
Id int `json:"id"`
CdWorkflowId int `json:"cd_workflow_id"`
Name string `json:"name"`
Status string `json:"status"`
PodStatus string `json:"pod_status"`
Message string `json:"message"`
StartedOn time.Time `json:"started_on"`
FinishedOn time.Time `json:"finished_on"`
PipelineId int `json:"pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
MaterialInfo string `json:"material_info,omitempty"`
DataSource string `json:"data_source,omitempty"`
CiArtifactId int `json:"ci_artifact_id,omitempty"`
WorkflowType string `json:"workflow_type,omitempty"`
ExecutorType string `json:"executor_type,omitempty"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
GitTriggers map[int]GitCommit `json:"gitTriggers"`
CiMaterials []CiPipelineMaterialResponse `json:"ciMaterials"`
ImageReleaseTags []*repository2.ImageTag `json:"imageReleaseTags"`
ImageComment *repository2.ImageComment `json:"imageComment"`
Id int `json:"id"`
CdWorkflowId int `json:"cd_workflow_id"`
Name string `json:"name"`
Status string `json:"status"`
PodStatus string `json:"pod_status"`
Message string `json:"message"`
StartedOn time.Time `json:"started_on"`
FinishedOn time.Time `json:"finished_on"`
PipelineId int `json:"pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
MaterialInfo string `json:"material_info,omitempty"`
DataSource string `json:"data_source,omitempty"`
CiArtifactId int `json:"ci_artifact_id,omitempty"`
WorkflowType string `json:"workflow_type,omitempty"`
ExecutorType string `json:"executor_type,omitempty"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
GitTriggers map[int]GitCommit `json:"gitTriggers"`
CiMaterials []CiPipelineMaterialResponse `json:"ciMaterials"`
ImageReleaseTags []*repository2.ImageTag `json:"imageReleaseTags"`
ImageComment *repository2.ImageComment `json:"imageComment"`
RefCdWorkflowRunnerId int `json:"referenceCdWorkflowRunnerId"`
}

type TriggerWorkflowStatus struct {
Expand Down Expand Up @@ -486,6 +490,15 @@ func (impl *CdWorkflowRepositoryImpl) FindWorkflowRunnerById(wfrId int) (*CdWork
return wfr, err
}

func (impl *CdWorkflowRepositoryImpl) FindRetriedWorkflowCountByReferenceId(wfrId int) (int, error) {
retryCount := 0
query := fmt.Sprintf("select count(*) "+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use id instead of * here

"from cd_workflow_runner where ref_cd_workflow_runner_id = %v", wfrId)

_, err := impl.dbConnection.Query(&retryCount, query)
return retryCount, err
}

func (impl *CdWorkflowRepositoryImpl) FindByWorkflowIdAndRunnerType(ctx context.Context, wfId int, runnerType bean.WorkflowType) (CdWorkflowRunner, error) {
var wfr CdWorkflowRunner
_, span := otel.Tracer("orchestrator").Start(ctx, "cdWorkflowRepository.FindByWorkflowIdAndRunnerType")
Expand Down
57 changes: 35 additions & 22 deletions internal/sql/repository/pipelineConfig/CiWorkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package pipelineConfig

import (
"fmt"
"github.com/go-pg/pg"
"go.uber.org/zap"
"time"
Expand All @@ -33,6 +34,7 @@ type CiWorkflowRepository interface {
FindByStatusesIn(activeStatuses []string) ([]*CiWorkflow, error)
FindByPipelineId(pipelineId int, offset int, size int) ([]WorkflowWithArtifact, error)
FindById(id int) (*CiWorkflow, error)
FindRetriedWorkflowCountByReferenceId(id int) (int, error)
FindCiWorkflowGitTriggersById(id int) (workflow *CiWorkflow, err error)
FindByName(name string) (*CiWorkflow, error)

Expand All @@ -51,25 +53,26 @@ type CiWorkflowRepositoryImpl struct {
}

type CiWorkflow struct {
tableName struct{} `sql:"ci_workflow" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
Status string `sql:"status"`
PodStatus string `sql:"pod_status"`
Message string `sql:"message"`
StartedOn time.Time `sql:"started_on"`
FinishedOn time.Time `sql:"finished_on"`
CiPipelineId int `sql:"ci_pipeline_id"`
Namespace string `sql:"namespace"`
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
LogLocation string `sql:"log_file_path"`
GitTriggers map[int]GitCommit `sql:"git_triggers"`
TriggeredBy int32 `sql:"triggered_by"`
CiArtifactLocation string `sql:"ci_artifact_location"`
PodName string `sql:"pod_name"`
CiBuildType string `sql:"ci_build_type"`
EnvironmentId int `sql:"environment_id"`
CiPipeline *CiPipeline
tableName struct{} `sql:"ci_workflow" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
Status string `sql:"status"`
PodStatus string `sql:"pod_status"`
Message string `sql:"message"`
StartedOn time.Time `sql:"started_on"`
FinishedOn time.Time `sql:"finished_on"`
CiPipelineId int `sql:"ci_pipeline_id"`
Namespace string `sql:"namespace"`
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
LogLocation string `sql:"log_file_path"`
GitTriggers map[int]GitCommit `sql:"git_triggers"`
TriggeredBy int32 `sql:"triggered_by"`
CiArtifactLocation string `sql:"ci_artifact_location"`
PodName string `sql:"pod_name"`
CiBuildType string `sql:"ci_build_type"`
EnvironmentId int `sql:"environment_id"`
ReferenceCiWorkflowId int `sql:"ref_ci_workflow_id"`
CiPipeline *CiPipeline
}

type WorkflowWithArtifact struct {
Expand All @@ -95,6 +98,7 @@ type WorkflowWithArtifact struct {
IsArtifactUploaded bool `json:"is_artifact_uploaded"`
EnvironmentId int `json:"environmentId"`
EnvironmentName string `json:"environmentName"`
RefCiWorkflowId int `json:"referenceCiWorkflowId"`
}

type GitCommit struct {
Expand All @@ -111,9 +115,9 @@ type GitCommit struct {
}

type WebhookData struct {
Id int
EventActionType string
Data map[string]string
Id int `json:"id"`
EventActionType string `json:"eventActionType"`
Data map[string]string `json:"data"`
}

type CiWorkflowConfig struct {
Expand Down Expand Up @@ -192,6 +196,15 @@ func (impl *CiWorkflowRepositoryImpl) FindById(id int) (*CiWorkflow, error) {
return workflow, err
}

func (impl *CiWorkflowRepositoryImpl) FindRetriedWorkflowCountByReferenceId(id int) (int, error) {
retryCount := 0
query := fmt.Sprintf("select count(*) "+
"from ci_workflow where ref_ci_workflow_id = %v", id)

_, err := impl.dbConnection.Query(&retryCount, query)
return retryCount, err
}

func (impl *CiWorkflowRepositoryImpl) FindCiWorkflowGitTriggersById(id int) (ciWorkflow *CiWorkflow, err error) {
workflow := &CiWorkflow{}
err = impl.dbConnection.Model(workflow).
Expand Down
33 changes: 7 additions & 26 deletions pkg/bean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,35 +242,16 @@ type GitCiTriggerRequest struct {
ExtraEnvironmentVariables map[string]string `json:"extraEnvironmentVariables"` // extra env variables which will be used for CI
}

type GitCommit struct {
Commit string //git hash
Author string
Date time.Time
Message string
Changes []string
WebhookData *WebhookData
GitRepoUrl string
GitRepoName string
CiConfigureSourceType pipelineConfig.SourceType
CiConfigureSourceValue string
}

type WebhookData struct {
Id int `json:"id"`
EventActionType string `json:"eventActionType"`
Data map[string]string `json:"data"`
}

type SourceType string

type CiPipelineMaterial struct {
Id int `json:"Id"`
GitMaterialId int `json:"GitMaterialId"`
Type string `json:"Type"`
Value string `json:"Value"`
Active bool `json:"Active"`
GitCommit GitCommit `json:"GitCommit"`
GitTag string `json:"GitTag"`
Id int `json:"Id"`
GitMaterialId int `json:"GitMaterialId"`
Type string `json:"Type"`
Value string `json:"Value"`
Active bool `json:"Active"`
GitCommit pipelineConfig.GitCommit `json:"GitCommit"`
GitTag string `json:"GitTag"`
}

type CiTriggerRequest struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bulkAction/BulkUpdateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ func (impl BulkUpdateServiceImpl) BulkBuildTrigger(request *BulkApplicationForEn
var ciMaterials []bean2.CiPipelineMaterial
ciMaterials = append(ciMaterials, bean2.CiPipelineMaterial{
Id: materialId,
GitCommit: bean2.GitCommit{Commit: commitHash},
GitCommit: pipelineConfig.GitCommit{Commit: commitHash},
})
ciTriggerRequest := bean2.CiTriggerRequest{
PipelineId: ciPipelineId,
Expand Down
4 changes: 2 additions & 2 deletions pkg/git/GitWebhookService.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (impl *GitWebhookServiceImpl) HandleGitWebhook(gitWebhookRequest gitSensor.
Type: string(gitWebhookRequest.Type),
Value: gitWebhookRequest.Value,
Active: gitWebhookRequest.Active,
GitCommit: bean.GitCommit{
GitCommit: pipelineConfig.GitCommit{
Commit: gitWebhookRequest.GitCommit.Commit,
Author: gitWebhookRequest.GitCommit.Author,
Date: gitWebhookRequest.GitCommit.Date,
Expand All @@ -62,7 +62,7 @@ func (impl *GitWebhookServiceImpl) HandleGitWebhook(gitWebhookRequest gitSensor.

if string(gitWebhookRequest.Type) == string(pipelineConfig.SOURCE_TYPE_WEBHOOK) {
webhookData := gitWebhookRequest.GitCommit.WebhookData
ciPipelineMaterial.GitCommit.WebhookData = &bean.WebhookData{
ciPipelineMaterial.GitCommit.WebhookData = pipelineConfig.WebhookData{
Id: webhookData.Id,
EventActionType: webhookData.EventActionType,
Data: webhookData.Data,
Expand Down
1 change: 1 addition & 0 deletions pkg/pipeline/CdConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type CdConfig struct {
BaseLogLocationPath string `env:"BASE_LOG_LOCATION_PATH" envDefault:"/home/devtron/"`
CdWorkflowExecutorType pipelineConfig.WorkflowExecutorType `env:"CD_WORKFLOW_EXECUTOR_TYPE" envDefault:"AWF"`
InAppLoggingEnabled bool `env:"IN_APP_LOGGING_ENABLED" envDefault:"false"`
MaxCdWorkflowRunnerRetries int `env:"MAX_CD_WORKFLOW_RUNNER_RETRIES" envDefault:"0"`
}

func GetCdConfig() (*CdConfig, error) {
Expand Down
Loading