Skip to content

Commit e3ae3a0

Browse files
committed
first depl fix
1 parent 22cd18a commit e3ae3a0

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type CdWorkflowRepository interface {
7979

8080
MigrateIsArtifactUploaded(wfrId int, isArtifactUploaded bool)
8181
MigrateCdArtifactLocation(wfrId int, cdArtifactLocation string)
82+
FindDeployedCdWorkflowRunnersByPipelineId(pipelineId int) ([]*CdWorkflowRunner, error)
8283
}
8384

8485
type CdWorkflowRepositoryImpl struct {
@@ -761,3 +762,19 @@ func (impl *CdWorkflowRepositoryImpl) MigrateCdArtifactLocation(wfrId int, cdArt
761762
impl.logger.Errorw("error in updating cd artifact location", "wfrId", wfrId, "err", err)
762763
}
763764
}
765+
766+
func (impl *CdWorkflowRepositoryImpl) FindDeployedCdWorkflowRunnersByPipelineId(pipelineId int) ([]*CdWorkflowRunner, error) {
767+
var runners []*CdWorkflowRunner
768+
err := impl.dbConnection.
769+
Model(&runners).
770+
Column("cd_workflow_runner.*", "CdWorkflow").
771+
Where("cd_workflow.pipeline_id = ?", pipelineId).
772+
Where("workflow_type = ? ", apiBean.CD_WORKFLOW_TYPE_DEPLOY).
773+
Order("cd_workflow_runner.id").
774+
Select()
775+
if err != nil {
776+
impl.logger.Errorw("error in finding previous co workflow runners by pipeline id ", "pipelineId", pipelineId, "err", err)
777+
return nil, err
778+
}
779+
return runners, nil
780+
}

pkg/configDiff/DeploymentConfigurationService.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type DeploymentConfigurationServiceImpl struct {
6060
configMapHistoryService configMapAndSecret.ConfigMapHistoryService
6161
deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService
6262
configMapHistoryReadService read2.ConfigMapHistoryReadService
63+
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
6364
}
6465

6566
func NewDeploymentConfigurationServiceImpl(logger *zap.SugaredLogger,
@@ -79,6 +80,7 @@ func NewDeploymentConfigurationServiceImpl(logger *zap.SugaredLogger,
7980
configMapHistoryService configMapAndSecret.ConfigMapHistoryService,
8081
deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService,
8182
configMapHistoryReadService read2.ConfigMapHistoryReadService,
83+
cdWorkflowRepository pipelineConfig.CdWorkflowRepository,
8284
) (*DeploymentConfigurationServiceImpl, error) {
8385
deploymentConfigurationService := &DeploymentConfigurationServiceImpl{
8486
logger: logger,
@@ -98,6 +100,7 @@ func NewDeploymentConfigurationServiceImpl(logger *zap.SugaredLogger,
98100
configMapHistoryService: configMapHistoryService,
99101
deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService,
100102
configMapHistoryReadService: configMapHistoryReadService,
103+
cdWorkflowRepository: cdWorkflowRepository,
101104
}
102105

103106
return deploymentConfigurationService, nil
@@ -264,8 +267,12 @@ func (impl *DeploymentConfigurationServiceImpl) getConfigDataForDeploymentHistor
264267
}
265268
configDataDto.WithConfigMapData(cmConfigData)
266269
// fetching for cm config ends
267-
268-
if userHasAdminAccess {
270+
isWfrFirstDeployment, err := impl.IsFirstDeployment(configDataQueryParams.PipelineId, configDataQueryParams.WfrId)
271+
if err != nil {
272+
impl.logger.Errorw("error in checking if a single deployment history is present for pipelineId or not", "pipelineId", configDataQueryParams.PipelineId, "err", err)
273+
return nil, err
274+
}
275+
if userHasAdminAccess || isWfrFirstDeployment {
269276
// fetching for cs config starts
270277
secretConfigDto, err := impl.getCmCsConfigHistory(ctx, configDataQueryParams, repository3.SECRET_TYPE, userHasAdminAccess)
271278
if err != nil {
@@ -279,6 +286,18 @@ func (impl *DeploymentConfigurationServiceImpl) getConfigDataForDeploymentHistor
279286
return configDataDto, nil
280287
}
281288

289+
func (impl *DeploymentConfigurationServiceImpl) IsFirstDeployment(pipelineId, wfrId int) (bool, error) {
290+
wfrs, err := impl.cdWorkflowRepository.FindDeployedCdWorkflowRunnersByPipelineId(pipelineId)
291+
if err != nil {
292+
impl.logger.Errorw("error in getting all cd workflow runners for a pipeline id", "pipelineId", pipelineId, "err", err)
293+
return false, err
294+
}
295+
if len(wfrs) > 0 && wfrs[0].Id == wfrId {
296+
return true, nil
297+
}
298+
return false, nil
299+
}
300+
282301
func (impl *DeploymentConfigurationServiceImpl) getCmCsConfigHistory(ctx context.Context, configDataQueryParams *bean2.ConfigDataQueryParams, configType repository3.ConfigType, userHasAdminAccess bool) (*bean2.DeploymentAndCmCsConfig, error) {
283302
var resourceType bean.ResourceType
284303
history, err := impl.configMapHistoryRepository.GetHistoryByPipelineIdAndWfrId(configDataQueryParams.PipelineId, configDataQueryParams.WfrId, configType)

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.

0 commit comments

Comments
 (0)