Skip to content

feat: Skipping falg based CMCS for Ci Job #5536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions env_gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
| HELM_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME | 120 | |
| HIDE_IMAGE_TAGGING_HARD_DELETE | false | |
| IGNORE_AUTOCOMPLETE_AUTH_CHECK | false | |
| IGNORE_CM_CS_IN_CI_JOB | false | |
| IMAGE_RETRY_COUNT | 0 | |
| IMAGE_RETRY_INTERVAL | 5 | |
| IMAGE_SCANNER_ENDPOINT | http://image-scanner-new-demo-devtroncd-service.devtroncd:80 | |
Expand Down
7 changes: 7 additions & 0 deletions pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error)
if ciWorkflowConfig.Namespace == "" {
ciWorkflowConfig.Namespace = impl.config.GetDefaultNamespace()
}
if scope.SystemMetadata == nil {
scope.SystemMetadata = &resourceQualifiers.SystemMetadata{
Namespace: ciWorkflowConfig.Namespace,
AppName: pipeline.App.AppName,
}
}

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

workflowRequest.CiPipelineType = trigger.PipelineType
err = impl.executeCiPipeline(workflowRequest)
if err != nil {
impl.Logger.Errorw("workflow error", "err", err)
Expand Down
21 changes: 17 additions & 4 deletions pkg/pipeline/WorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/devtron-labs/devtron/pkg/infraConfig"
k8s2 "github.com/devtron-labs/devtron/pkg/k8s"
bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
"github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline"
"github.com/devtron-labs/devtron/pkg/pipeline/executors"
"github.com/devtron-labs/devtron/pkg/pipeline/infraProviders"
"github.com/devtron-labs/devtron/pkg/pipeline/types"
Expand Down Expand Up @@ -126,10 +127,14 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W
impl.Logger.Errorw("error occurred while appending CmCs", "err", err)
return bean3.WorkflowTemplate{}, err
}
workflowConfigMaps, workflowSecrets, err = impl.addExistingCmCsInWorkflow(workflowRequest, workflowConfigMaps, workflowSecrets)
if err != nil {
impl.Logger.Errorw("error occurred while adding existing CmCs", "err", err)
return bean3.WorkflowTemplate{}, err

shouldAddExistingCmCsInWorkflow := impl.shouldAddExistingCmCsInWorkflow(workflowRequest)
if shouldAddExistingCmCsInWorkflow {
workflowConfigMaps, workflowSecrets, err = impl.addExistingCmCsInWorkflow(workflowRequest, workflowConfigMaps, workflowSecrets)
if err != nil {
impl.Logger.Errorw("error occurred while adding existing CmCs", "err", err)
return bean3.WorkflowTemplate{}, err
}
}

workflowTemplate.ConfigMaps = workflowConfigMaps
Expand Down Expand Up @@ -176,6 +181,14 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W
return workflowTemplate, nil
}

func (impl *WorkflowServiceImpl) shouldAddExistingCmCsInWorkflow(workflowRequest *types.WorkflowRequest) bool {
// CmCs are not added for CI_JOB if IgnoreCmCsInCiJob is true
if workflowRequest.CiPipelineType == string(CiPipeline.CI_JOB) && impl.ciCdConfig.IgnoreCmCsInCiJob {
return false
}
return true
}

func (impl *WorkflowServiceImpl) getClusterConfig(workflowRequest *types.WorkflowRequest) (*rest.Config, error) {
env := workflowRequest.Env
if workflowRequest.IsExtRun {
Expand Down
1 change: 1 addition & 0 deletions pkg/pipeline/types/CiCdConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type CiCdConfig struct {
ImageScanMaxRetries int `env:"IMAGE_SCAN_MAX_RETRIES" envDefault:"3"`
ImageScanRetryDelay int `env:"IMAGE_SCAN_RETRY_DELAY" envDefault:"5"`
ShowDockerBuildCmdInLogs bool `env:"SHOW_DOCKER_BUILD_ARGS" envDefault:"true"`
IgnoreCmCsInCiJob bool `env:"IGNORE_CM_CS_IN_CI_JOB" envDefault:"false"`
// from CdConfig
CdLimitCpu string `env:"CD_LIMIT_CI_CPU" envDefault:"0.5"`
CdLimitMem string `env:"CD_LIMIT_CI_MEM" envDefault:"3G"`
Expand Down
Loading