Skip to content

Commit a4a910f

Browse files
authored
feat: Skipping falg based CMCS for Ci Job (#5536)
* sync with enterprise External Ci with Job giving run time param externalCiArtifact * sync with enterprise
1 parent 656ea0b commit a4a910f

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

env_gen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
| HELM_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME | 120 | |
155155
| HIDE_IMAGE_TAGGING_HARD_DELETE | false | |
156156
| IGNORE_AUTOCOMPLETE_AUTH_CHECK | false | |
157+
| IGNORE_CM_CS_IN_CI_JOB | false | |
157158
| IMAGE_RETRY_COUNT | 0 | |
158159
| IMAGE_RETRY_INTERVAL | 5 | |
159160
| IMAGE_SCANNER_ENDPOINT | http://image-scanner-new-demo-devtroncd-service.devtroncd:80 | |

pkg/pipeline/CiService.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error)
195195
if ciWorkflowConfig.Namespace == "" {
196196
ciWorkflowConfig.Namespace = impl.config.GetDefaultNamespace()
197197
}
198+
if scope.SystemMetadata == nil {
199+
scope.SystemMetadata = &resourceQualifiers.SystemMetadata{
200+
Namespace: ciWorkflowConfig.Namespace,
201+
AppName: pipeline.App.AppName,
202+
}
203+
}
198204

199205
// preCiSteps, postCiSteps, refPluginsData, err := impl.pipelineStageService.BuildPrePostAndRefPluginStepsDataForWfRequest(pipeline.Id, ciEvent)
200206
prePostAndRefPluginResponse, err := impl.pipelineStageService.BuildPrePostAndRefPluginStepsDataForWfRequest(pipeline.Id, pipelineConfigBean.CiStage, scope)
@@ -248,6 +254,7 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error)
248254
workflowRequest.Type = pipelineConfigBean.CI_WORKFLOW_PIPELINE_TYPE
249255
}
250256

257+
workflowRequest.CiPipelineType = trigger.PipelineType
251258
err = impl.executeCiPipeline(workflowRequest)
252259
if err != nil {
253260
impl.Logger.Errorw("workflow error", "err", err)

pkg/pipeline/WorkflowService.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/devtron-labs/devtron/pkg/infraConfig"
3131
k8s2 "github.com/devtron-labs/devtron/pkg/k8s"
3232
bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
33+
"github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline"
3334
"github.com/devtron-labs/devtron/pkg/pipeline/executors"
3435
"github.com/devtron-labs/devtron/pkg/pipeline/infraProviders"
3536
"github.com/devtron-labs/devtron/pkg/pipeline/types"
@@ -126,10 +127,14 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W
126127
impl.Logger.Errorw("error occurred while appending CmCs", "err", err)
127128
return bean3.WorkflowTemplate{}, err
128129
}
129-
workflowConfigMaps, workflowSecrets, err = impl.addExistingCmCsInWorkflow(workflowRequest, workflowConfigMaps, workflowSecrets)
130-
if err != nil {
131-
impl.Logger.Errorw("error occurred while adding existing CmCs", "err", err)
132-
return bean3.WorkflowTemplate{}, err
130+
131+
shouldAddExistingCmCsInWorkflow := impl.shouldAddExistingCmCsInWorkflow(workflowRequest)
132+
if shouldAddExistingCmCsInWorkflow {
133+
workflowConfigMaps, workflowSecrets, err = impl.addExistingCmCsInWorkflow(workflowRequest, workflowConfigMaps, workflowSecrets)
134+
if err != nil {
135+
impl.Logger.Errorw("error occurred while adding existing CmCs", "err", err)
136+
return bean3.WorkflowTemplate{}, err
137+
}
133138
}
134139

135140
workflowTemplate.ConfigMaps = workflowConfigMaps
@@ -176,6 +181,14 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W
176181
return workflowTemplate, nil
177182
}
178183

184+
func (impl *WorkflowServiceImpl) shouldAddExistingCmCsInWorkflow(workflowRequest *types.WorkflowRequest) bool {
185+
// CmCs are not added for CI_JOB if IgnoreCmCsInCiJob is true
186+
if workflowRequest.CiPipelineType == string(CiPipeline.CI_JOB) && impl.ciCdConfig.IgnoreCmCsInCiJob {
187+
return false
188+
}
189+
return true
190+
}
191+
179192
func (impl *WorkflowServiceImpl) getClusterConfig(workflowRequest *types.WorkflowRequest) (*rest.Config, error) {
180193
env := workflowRequest.Env
181194
if workflowRequest.IsExtRun {

pkg/pipeline/types/CiCdConfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type CiCdConfig struct {
8181
ImageScanMaxRetries int `env:"IMAGE_SCAN_MAX_RETRIES" envDefault:"3"`
8282
ImageScanRetryDelay int `env:"IMAGE_SCAN_RETRY_DELAY" envDefault:"5"`
8383
ShowDockerBuildCmdInLogs bool `env:"SHOW_DOCKER_BUILD_ARGS" envDefault:"true"`
84+
IgnoreCmCsInCiJob bool `env:"IGNORE_CM_CS_IN_CI_JOB" envDefault:"false"`
8485
// from CdConfig
8586
CdLimitCpu string `env:"CD_LIMIT_CI_CPU" envDefault:"0.5"`
8687
CdLimitMem string `env:"CD_LIMIT_CI_MEM" envDefault:"3G"`

0 commit comments

Comments
 (0)