diff --git a/Wire.go b/Wire.go index 8d6b8d5a98..8b2c713396 100644 --- a/Wire.go +++ b/Wire.go @@ -769,8 +769,6 @@ func InitializeApp() (*App, error) { history3.NewGitMaterialHistoryServiceImpl, wire.Bind(new(history3.GitMaterialHistoryService), new(*history3.GitMaterialHistoryServiceImpl)), - history3.NewDeployedConfigurationHistoryServiceImpl, - wire.Bind(new(history3.DeployedConfigurationHistoryService), new(*history3.DeployedConfigurationHistoryServiceImpl)), // history ends // plugin starts diff --git a/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go b/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go index 7a759af09c..c855a0b585 100644 --- a/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go +++ b/api/restHandler/app/pipeline/history/PipelineHistoryRestHandler.go @@ -19,7 +19,7 @@ package history import ( "fmt" "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" - "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "net/http" "strconv" @@ -42,37 +42,35 @@ type PipelineHistoryRestHandler interface { } type PipelineHistoryRestHandlerImpl struct { - logger *zap.SugaredLogger - userAuthService user.UserService - enforcer casbin.Enforcer - strategyHistoryService history2.PipelineStrategyHistoryService - deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService - configMapHistoryService configMapAndSecret.ConfigMapHistoryService - prePostCiScriptHistoryService history2.PrePostCiScriptHistoryService - prePostCdScriptHistoryService history2.PrePostCdScriptHistoryService - enforcerUtil rbac.EnforcerUtil - deployedConfigurationHistoryService history2.DeployedConfigurationHistoryService + logger *zap.SugaredLogger + userAuthService user.UserService + enforcer casbin.Enforcer + strategyHistoryService history2.PipelineStrategyHistoryService + configMapHistoryService configMapAndSecret.ConfigMapHistoryService + prePostCiScriptHistoryService history2.PrePostCiScriptHistoryService + prePostCdScriptHistoryService history2.PrePostCdScriptHistoryService + enforcerUtil rbac.EnforcerUtil + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService } func NewPipelineHistoryRestHandlerImpl(logger *zap.SugaredLogger, userAuthService user.UserService, enforcer casbin.Enforcer, strategyHistoryService history2.PipelineStrategyHistoryService, - deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, configMapHistoryService configMapAndSecret.ConfigMapHistoryService, prePostCiScriptHistoryService history2.PrePostCiScriptHistoryService, prePostCdScriptHistoryService history2.PrePostCdScriptHistoryService, enforcerUtil rbac.EnforcerUtil, - deployedConfigurationHistoryService history2.DeployedConfigurationHistoryService) *PipelineHistoryRestHandlerImpl { + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService, +) *PipelineHistoryRestHandlerImpl { return &PipelineHistoryRestHandlerImpl{ - logger: logger, - userAuthService: userAuthService, - enforcer: enforcer, - strategyHistoryService: strategyHistoryService, - deploymentTemplateHistoryService: deploymentTemplateHistoryService, - configMapHistoryService: configMapHistoryService, - prePostCdScriptHistoryService: prePostCdScriptHistoryService, - prePostCiScriptHistoryService: prePostCiScriptHistoryService, - enforcerUtil: enforcerUtil, - deployedConfigurationHistoryService: deployedConfigurationHistoryService, + logger: logger, + userAuthService: userAuthService, + enforcer: enforcer, + strategyHistoryService: strategyHistoryService, + configMapHistoryService: configMapHistoryService, + prePostCdScriptHistoryService: prePostCdScriptHistoryService, + prePostCiScriptHistoryService: prePostCiScriptHistoryService, + enforcerUtil: enforcerUtil, + deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, } } @@ -112,7 +110,7 @@ func (handler *PipelineHistoryRestHandlerImpl) FetchDeployedConfigurationsForWor } //RBAC END - res, err := handler.deployedConfigurationHistoryService.GetDeployedConfigurationByWfrId(r.Context(), pipelineId, wfrId) + res, err := handler.deploymentTemplateHistoryReadService.GetDeployedConfigurationByWfrId(r.Context(), pipelineId, wfrId) if err != nil { handler.logger.Errorw("service err, GetDeployedConfigurationByWfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) @@ -171,7 +169,7 @@ func (handler *PipelineHistoryRestHandlerImpl) FetchDeployedHistoryComponentList } //RBAC END - res, err := handler.deployedConfigurationHistoryService.GetDeployedHistoryComponentList(pipelineId, baseConfigurationId, historyComponent, historyComponentName) + res, err := handler.deploymentTemplateHistoryReadService.GetDeployedHistoryComponentList(pipelineId, baseConfigurationId, historyComponent, historyComponentName) if err != nil { handler.logger.Errorw("service err, GetDeployedHistoryComponentList", "err", err, "pipelineId", pipelineId) common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) @@ -234,7 +232,7 @@ func (handler *PipelineHistoryRestHandlerImpl) FetchDeployedHistoryComponentDeta ctx := r.Context() ctx = util.SetSuperAdminInContext(ctx, isSuperAdmin) - res, err := handler.deployedConfigurationHistoryService.GetDeployedHistoryComponentDetail(ctx, pipelineId, id, historyComponent, historyComponentName, userHasAdminAccess) + res, err := handler.deploymentTemplateHistoryReadService.GetDeployedHistoryComponentDetail(ctx, pipelineId, id, historyComponent, historyComponentName, userHasAdminAccess) if err != nil { handler.logger.Errorw("service err, GetDeployedHistoryComponentDetail", "err", err, "pipelineId", pipelineId, "id", id) common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) @@ -277,7 +275,7 @@ func (handler *PipelineHistoryRestHandlerImpl) GetAllDeployedConfigurationHistor isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*") ctx := r.Context() ctx = util.SetSuperAdminInContext(ctx, isSuperAdmin) - res, err := handler.deployedConfigurationHistoryService.GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx, pipelineId, userHasAdminAccess) + res, err := handler.deploymentTemplateHistoryReadService.GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx, pipelineId, userHasAdminAccess) if err != nil { handler.logger.Errorw("service err, GetAllDeployedConfigurationByPipelineIdAndLatestWfrId", "err", err, "pipelineId", pipelineId) common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) @@ -327,7 +325,7 @@ func (handler *PipelineHistoryRestHandlerImpl) GetAllDeployedConfigurationHistor ctx = util.SetSuperAdminInContext(ctx, isSuperAdmin) //checking if user has admin access userHasAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, resourceName) - res, err := handler.deployedConfigurationHistoryService.GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx, pipelineId, wfrId, userHasAdminAccess) + res, err := handler.deploymentTemplateHistoryReadService.GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx, pipelineId, wfrId, userHasAdminAccess) if err != nil { handler.logger.Errorw("service err, GetAllDeployedConfigurationByPipelineIdAndWfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) diff --git a/cmd/external-app/wire_gen.go b/cmd/external-app/wire_gen.go index b0fb03b956..3bb17b1415 100644 --- a/cmd/external-app/wire_gen.go +++ b/cmd/external-app/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject diff --git a/pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go b/pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go index d1eafd8bc2..29c96d7267 100644 --- a/pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go +++ b/pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go @@ -17,9 +17,18 @@ package deploymentTemplate import ( + "context" + "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" + read2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/bean" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" + "github.com/devtron-labs/devtron/pkg/pipeline/history" + repository5 "github.com/devtron-labs/devtron/pkg/variables/repository" + "github.com/devtron-labs/devtron/util/sliceUtil" + "go.opentelemetry.io/otel" "time" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" @@ -36,6 +45,7 @@ type DeploymentTemplateHistoryService interface { CreateDeploymentTemplateHistoryFromGlobalTemplate(chart *chartRepoRepository.Chart, tx *pg.Tx, IsAppMetricsEnabled bool) error CreateDeploymentTemplateHistoryFromEnvOverrideTemplate(envOverride *bean.EnvConfigOverride, tx *pg.Tx, IsAppMetricsEnabled bool, pipelineId int) error CreateDeploymentTemplateHistoryForDeploymentTrigger(pipeline *pipelineConfig.Pipeline, envOverride *bean.EnvConfigOverride, renderedImageTemplate string, deployedOn time.Time, deployedBy int32) (*repository.DeploymentTemplateHistory, error) + CreateHistoriesForDeploymentTrigger(ctx context.Context, pipeline *pipelineConfig.Pipeline, strategy *chartConfig.PipelineStrategy, envOverride *bean.EnvConfigOverride, deployedOn time.Time, deployedBy int32) error } type DeploymentTemplateHistoryServiceImpl struct { @@ -48,23 +58,37 @@ type DeploymentTemplateHistoryServiceImpl struct { scopedVariableManager variables.ScopedVariableManager deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService chartRefService chartRef.ChartRefService + + strategyHistoryService history.PipelineStrategyHistoryService + configMapHistoryService configMapAndSecret.ConfigMapHistoryService + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService + configMapHistoryReadService read2.ConfigMapHistoryReadService } func NewDeploymentTemplateHistoryServiceImpl(logger *zap.SugaredLogger, deploymentTemplateHistoryRepository repository.DeploymentTemplateHistoryRepository, pipelineRepository pipelineConfig.PipelineRepository, chartRepository chartRepoRepository.ChartRepository, userService user.UserService, cdWorkflowRepository pipelineConfig.CdWorkflowRepository, scopedVariableManager variables.ScopedVariableManager, deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService, - chartRefService chartRef.ChartRefService) *DeploymentTemplateHistoryServiceImpl { + chartRefService chartRef.ChartRefService, + strategyHistoryService history.PipelineStrategyHistoryService, + configMapHistoryService configMapAndSecret.ConfigMapHistoryService, + deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService, + configMapHistoryReadService read2.ConfigMapHistoryReadService, +) *DeploymentTemplateHistoryServiceImpl { return &DeploymentTemplateHistoryServiceImpl{ - logger: logger, - deploymentTemplateHistoryRepository: deploymentTemplateHistoryRepository, - pipelineRepository: pipelineRepository, - chartRepository: chartRepository, - userService: userService, - cdWorkflowRepository: cdWorkflowRepository, - scopedVariableManager: scopedVariableManager, - deployedAppMetricsService: deployedAppMetricsService, - chartRefService: chartRefService, + logger: logger, + deploymentTemplateHistoryRepository: deploymentTemplateHistoryRepository, + pipelineRepository: pipelineRepository, + chartRepository: chartRepository, + userService: userService, + cdWorkflowRepository: cdWorkflowRepository, + scopedVariableManager: scopedVariableManager, + deployedAppMetricsService: deployedAppMetricsService, + chartRefService: chartRefService, + strategyHistoryService: strategyHistoryService, + configMapHistoryService: configMapHistoryService, + deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, + configMapHistoryReadService: configMapHistoryReadService, } } @@ -234,3 +258,62 @@ func (impl DeploymentTemplateHistoryServiceImpl) CreateDeploymentTemplateHistory } return history, nil } + +func (impl DeploymentTemplateHistoryServiceImpl) CreateHistoriesForDeploymentTrigger(ctx context.Context, pipeline *pipelineConfig.Pipeline, strategy *chartConfig.PipelineStrategy, envOverride *bean.EnvConfigOverride, deployedOn time.Time, deployedBy int32) error { + _, span := otel.Tracer("orchestrator").Start(ctx, "DeployedConfigurationHistoryServiceImpl.CreateHistoriesForDeploymentTrigger") + defer span.End() + deploymentTemplateHistoryId, templateHistoryExists, err := impl.deploymentTemplateHistoryReadService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) + if err != nil { + impl.logger.Errorw("error in checking if deployment template history exists for deployment trigger", "err", err) + return err + } + if !templateHistoryExists { + // creating history for deployment template + deploymentTemplateHistory, err := impl.CreateDeploymentTemplateHistoryForDeploymentTrigger(pipeline, envOverride, envOverride.Chart.ImageDescriptorTemplate, deployedOn, deployedBy) + if err != nil { + impl.logger.Errorw("error in creating deployment template history for deployment trigger", "err", err) + return err + } + deploymentTemplateHistoryId = deploymentTemplateHistory.Id + } + cmId, csId, cmCsHistoryExists, err := impl.configMapHistoryReadService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) + if err != nil { + impl.logger.Errorw("error in checking if config map/ secrete history exists for deployment trigger", "err", err) + return err + } + if !cmCsHistoryExists { + cmId, csId, err = impl.configMapHistoryService.CreateCMCSHistoryForDeploymentTrigger(pipeline, deployedOn, deployedBy) + if err != nil { + impl.logger.Errorw("error in creating CM/CS history for deployment trigger", "err", err) + return err + } + } + if strategy != nil { + // checking if pipeline strategy configuration for this pipelineId and with deployedOn time exists or not + strategyHistoryExists, err := impl.strategyHistoryService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) + if err != nil { + impl.logger.Errorw("error in checking if deployment template history exists for deployment trigger", "err", err) + return err + } + if !strategyHistoryExists { + err = impl.strategyHistoryService.CreateStrategyHistoryForDeploymentTrigger(strategy, deployedOn, deployedBy, pipeline.TriggerType) + if err != nil { + impl.logger.Errorw("error in creating strategy history for deployment trigger", "err", err) + return err + } + } + } + + var variableSnapshotHistories = sliceUtil.GetBeansPtr( + repository5.GetSnapshotBean(deploymentTemplateHistoryId, repository5.HistoryReferenceTypeDeploymentTemplate, envOverride.VariableSnapshot), + repository5.GetSnapshotBean(cmId, repository5.HistoryReferenceTypeConfigMap, envOverride.VariableSnapshotForCM), + repository5.GetSnapshotBean(csId, repository5.HistoryReferenceTypeSecret, envOverride.VariableSnapshotForCS), + ) + if len(variableSnapshotHistories) > 0 { + err = impl.scopedVariableManager.SaveVariableHistoriesForTrigger(variableSnapshotHistories, deployedBy) + if err != nil { + return err + } + } + return nil +} diff --git a/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go b/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go index bc4953e339..96ee677d98 100644 --- a/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go +++ b/pkg/deployment/manifest/deploymentTemplate/read/DeploymentTemplateHistoryReadService.go @@ -3,6 +3,12 @@ package read import ( "context" "errors" + "fmt" + bean2 "github.com/devtron-labs/devtron/api/bean" + repository3 "github.com/devtron-labs/devtron/internal/sql/repository" + "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + read2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" + "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/pipeline/history/adaptors" "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" repository2 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" @@ -11,6 +17,7 @@ import ( "github.com/devtron-labs/devtron/pkg/variables/repository" "github.com/devtron-labs/devtron/util" "github.com/go-pg/pg" + "go.opentelemetry.io/otel" "go.uber.org/zap" "time" ) @@ -25,23 +32,39 @@ type DeploymentTemplateHistoryReadService interface { GetTemplateHistoryModelForDeployedTemplateById(deploymentTemplateHistoryId, pipelineId int) (*repository2.DeploymentTemplateHistory, error) GetDeployedOnByDeploymentTemplateAndPipelineId(deploymentTemplateHistoryId, pipelineId int) (time.Time, error) + + GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*bean.DeploymentConfigurationDto, error) + GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*bean.DeployedHistoryComponentMetadataDto, error) + GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*bean.HistoryDetailDto, error) + GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean.AllDeploymentConfigurationDetail, error) + GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*bean.AllDeploymentConfigurationDetail, error) + GetLatestDeployedArtifactByPipelineId(pipelineId int) (*repository3.CiArtifact, error) } type DeploymentTemplateHistoryReadServiceImpl struct { logger *zap.SugaredLogger deploymentTemplateHistoryRepository repository2.DeploymentTemplateHistoryRepository scopedVariableManager variables.ScopedVariableManager + strategyHistoryService history.PipelineStrategyHistoryService + cdWorkflowRepository pipelineConfig.CdWorkflowRepository + configMapHistoryReadService read2.ConfigMapHistoryReadService } func NewDeploymentTemplateHistoryReadServiceImpl( logger *zap.SugaredLogger, deploymentTemplateHistoryRepository repository2.DeploymentTemplateHistoryRepository, scopedVariableManager variables.ScopedVariableManager, + strategyHistoryService history.PipelineStrategyHistoryService, + cdWorkflowRepository pipelineConfig.CdWorkflowRepository, + configMapHistoryReadService read2.ConfigMapHistoryReadService, ) *DeploymentTemplateHistoryReadServiceImpl { return &DeploymentTemplateHistoryReadServiceImpl{ logger: logger, deploymentTemplateHistoryRepository: deploymentTemplateHistoryRepository, scopedVariableManager: scopedVariableManager, + strategyHistoryService: strategyHistoryService, + cdWorkflowRepository: cdWorkflowRepository, + configMapHistoryReadService: configMapHistoryReadService, } } @@ -158,3 +181,169 @@ func (impl *DeploymentTemplateHistoryReadServiceImpl) GetDeployedOnByDeploymentT } return deployedOn, nil } + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetLatestDeployedArtifactByPipelineId(pipelineId int) (*repository3.CiArtifact, error) { + wfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean2.CD_WORKFLOW_TYPE_DEPLOY) + if err != nil { + impl.logger.Infow("error in getting latest deploy stage wfr by pipelineId", "err", err, "pipelineId", pipelineId) + return nil, err + } + return wfr.CdWorkflow.CiArtifact, nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*bean.DeploymentConfigurationDto, error) { + newCtx, span := otel.Tracer("orchestrator").Start(ctx, "DeploymentTemplateHistoryReadServiceImpl.GetDeployedConfigurationByWfrId") + defer span.End() + var deployedConfigurations []*bean.DeploymentConfigurationDto + //checking if deployment template configuration for this pipelineId and wfrId exists or not + templateHistoryId, exists, err := impl.CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId) + if err != nil { + impl.logger.Errorw("error in checking if history exists for deployment template", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + + deploymentTemplateConfiguration := &bean.DeploymentConfigurationDto{ + Name: bean.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT, + } + if exists { + deploymentTemplateConfiguration.Id = templateHistoryId + } + deployedConfigurations = append(deployedConfigurations, deploymentTemplateConfiguration) + + //checking if pipeline strategy configuration for this pipelineId and wfrId exists or not + + strategyHistoryId, exists, err := impl.strategyHistoryService.CheckIfHistoryExistsForPipelineIdAndWfrId(newCtx, pipelineId, wfrId) + if err != nil { + impl.logger.Errorw("error in checking if history exists for pipeline strategy", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + pipelineStrategyConfiguration := &bean.DeploymentConfigurationDto{ + Name: bean.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT, + } + if exists { + pipelineStrategyConfiguration.Id = strategyHistoryId + deployedConfigurations = append(deployedConfigurations, pipelineStrategyConfiguration) + } + + //checking if configmap history data exists and get its details + configmapHistory, exists, names, err := impl.configMapHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository2.CONFIGMAP_TYPE) + if err != nil { + impl.logger.Errorw("error in checking if history exists for configmap", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + if exists { + configmapConfiguration := &bean.DeploymentConfigurationDto{ + Id: configmapHistory.Id, + Name: bean.CONFIGMAP_TYPE_HISTORY_COMPONENT, + ChildComponentNames: names, + } + deployedConfigurations = append(deployedConfigurations, configmapConfiguration) + } + + //checking if secret history data exists and get its details + secretHistory, exists, names, err := impl.configMapHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository2.SECRET_TYPE) + if err != nil { + impl.logger.Errorw("error in checking if history exists for secret", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + if exists { + secretConfiguration := &bean.DeploymentConfigurationDto{ + Id: secretHistory.Id, + Name: bean.SECRET_TYPE_HISTORY_COMPONENT, + ChildComponentNames: names, + } + deployedConfigurations = append(deployedConfigurations, secretConfiguration) + } + return deployedConfigurations, nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*bean.DeployedHistoryComponentMetadataDto, error) { + var historyList []*bean.DeployedHistoryComponentMetadataDto + var err error + if historyComponent == string(bean.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.GetDeployedHistoryList(pipelineId, baseConfigId) + } else if historyComponent == string(bean.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.strategyHistoryService.GetDeployedHistoryList(pipelineId, baseConfigId) + } else if historyComponent == string(bean.CONFIGMAP_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.configMapHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId, repository2.CONFIGMAP_TYPE, historyComponentName) + } else if historyComponent == string(bean.SECRET_TYPE_HISTORY_COMPONENT) { + historyList, err = impl.configMapHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId, repository2.SECRET_TYPE, historyComponentName) + } else { + return nil, errors.New(fmt.Sprintf("history of %s not supported", historyComponent)) + } + if err != nil { + impl.logger.Errorw("error in getting deployed history component list", "err", err, "pipelineId", pipelineId, "historyComponent", historyComponent, "componentName", historyComponentName) + return nil, err + } + return historyList, nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*bean.HistoryDetailDto, error) { + history := &bean.HistoryDetailDto{} + var err error + if historyComponent == string(bean.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { + history, err = impl.GetHistoryForDeployedTemplateById(ctx, id, pipelineId) + } else if historyComponent == string(bean.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { + history, err = impl.strategyHistoryService.GetHistoryForDeployedStrategyById(id, pipelineId) + } else if historyComponent == string(bean.CONFIGMAP_TYPE_HISTORY_COMPONENT) { + history, err = impl.configMapHistoryReadService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository2.CONFIGMAP_TYPE, historyComponentName, userHasAdminAccess) + } else if historyComponent == string(bean.SECRET_TYPE_HISTORY_COMPONENT) { + history, err = impl.configMapHistoryReadService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository2.SECRET_TYPE, historyComponentName, userHasAdminAccess) + } else { + return nil, errors.New(fmt.Sprintf("history of %s not supported", historyComponent)) + } + if err != nil { + impl.logger.Errorw("error in getting deployed history component detail", "err", err, "pipelineId", pipelineId, "id", id, "historyComponent", historyComponent, "componentName", historyComponentName) + return nil, err + } + return history, nil +} + +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean.AllDeploymentConfigurationDetail, error) { + //getting latest wfr from pipelineId + wfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean2.CD_WORKFLOW_TYPE_DEPLOY) + if err != nil { + impl.logger.Errorw("error in getting latest deploy stage wfr by pipelineId", "err", err, "pipelineId", pipelineId) + return nil, err + } + deployedConfig, err := impl.GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx, pipelineId, wfr.Id, userHasAdminAccess) + if err != nil { + impl.logger.Errorw("error in getting GetAllDeployedConfigurationByPipelineIdAndWfrId", "err", err, "pipelineID", pipelineId, "wfrId", wfr.Id) + return nil, err + } + deployedConfig.WfrId = wfr.Id + return deployedConfig, nil +} +func (impl *DeploymentTemplateHistoryReadServiceImpl) GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*bean.AllDeploymentConfigurationDetail, error) { + //getting history of deployment template for latest deployment + deploymentTemplateHistory, err := impl.GetDeployedHistoryByPipelineIdAndWfrId(ctx, pipelineId, wfrId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in getting deployment template history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + //getting history of config map for latest deployment + configMapHistory, err := impl.configMapHistoryReadService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository2.CONFIGMAP_TYPE, userHasAdminAccess) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in getting config map history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + //getting history of secret for latest deployment + secretHistory, err := impl.configMapHistoryReadService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository2.SECRET_TYPE, userHasAdminAccess) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in getting secret history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + //getting history of pipeline strategy for latest deployment + strategyHistory, err := impl.strategyHistoryService.GetLatestDeployedHistoryByPipelineIdAndWfrId(ctx, pipelineId, wfrId) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in getting strategy history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) + return nil, err + } + allDeploymentConfigurationHistoryDetail := &bean.AllDeploymentConfigurationDetail{ + DeploymentTemplateConfig: deploymentTemplateHistory, + ConfigMapConfig: configMapHistory, + SecretConfig: secretHistory, + StrategyConfig: strategyHistory, + } + return allDeploymentConfigurationHistoryDetail, nil +} diff --git a/pkg/deployment/trigger/devtronApps/TriggerService.go b/pkg/deployment/trigger/devtronApps/TriggerService.go index faf30adb53..dfdfaf04f2 100644 --- a/pkg/deployment/trigger/devtronApps/TriggerService.go +++ b/pkg/deployment/trigger/devtronApps/TriggerService.go @@ -58,6 +58,7 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git" "github.com/devtron-labs/devtron/pkg/deployment/manifest" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" bean10 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/bean" bean5 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean" "github.com/devtron-labs/devtron/pkg/deployment/manifest/publish" @@ -114,64 +115,64 @@ type TriggerService interface { } type TriggerServiceImpl struct { - logger *zap.SugaredLogger - cdWorkflowCommonService cd.CdWorkflowCommonService - gitOpsManifestPushService publish.GitOpsPushService - gitOpsConfigReadService config.GitOpsConfigReadService - argoK8sClient argocdServer.ArgoK8sClient - ACDConfig *argocdServer.ACDConfig - argoClientWrapperService argocdServer.ArgoClientWrapperService - pipelineStatusTimelineService status.PipelineStatusTimelineService - chartTemplateService util.ChartTemplateService - eventFactory client.EventFactory - eventClient client.EventClient - globalEnvVariables *globalUtil.GlobalEnvVariables - workflowEventPublishService out.WorkflowEventPublishService - manifestCreationService manifest.ManifestCreationService - deployedConfigurationHistoryService history.DeployedConfigurationHistoryService - pipelineStageService pipeline.PipelineStageService - globalPluginService plugin.GlobalPluginService - customTagService pipeline.CustomTagService - pluginInputVariableParser pipeline.PluginInputVariableParser - prePostCdScriptHistoryService history.PrePostCdScriptHistoryService - scopedVariableManager variables.ScopedVariableCMCSManager - cdWorkflowService pipeline.WorkflowService - imageDigestPolicyService imageDigestPolicy.ImageDigestPolicyService - userService user.UserService - gitSensorClient gitSensorClient.Client - config *types.CdConfig - helmAppService client2.HelmAppService - imageScanService security2.ImageScanService - enforcerUtil rbac.EnforcerUtil - userDeploymentRequestService service.UserDeploymentRequestService - helmAppClient gRPC.HelmAppClient //TODO refactoring: use helm app service instead - appRepository appRepository.AppRepository - ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository - imageScanHistoryReadService read2.ImageScanHistoryReadService - imageScanDeployInfoService security2.ImageScanDeployInfoService - imageScanDeployInfoReadService read2.ImageScanDeployInfoReadService - pipelineRepository pipelineConfig.PipelineRepository - pipelineOverrideRepository chartConfig.PipelineOverrideRepository - manifestPushConfigRepository repository.ManifestPushConfigRepository - chartRepository chartRepoRepository.ChartRepository - envRepository repository2.EnvironmentRepository - cdWorkflowRepository pipelineConfig.CdWorkflowRepository - ciWorkflowRepository pipelineConfig.CiWorkflowRepository - ciArtifactRepository repository3.CiArtifactRepository - ciTemplateService pipeline2.CiTemplateReadService - gitMaterialReadService read.GitMaterialReadService - appLabelRepository pipelineConfig.AppLabelRepository - ciPipelineRepository pipelineConfig.CiPipelineRepository - appWorkflowRepository appWorkflow.AppWorkflowRepository - dockerArtifactStoreRepository repository4.DockerArtifactStoreRepository - K8sUtil *util5.K8sServiceImpl - transactionUtilImpl *sql.TransactionUtilImpl - deploymentConfigService common.DeploymentConfigService - deploymentServiceTypeConfig *globalUtil.DeploymentServiceTypeConfig - ciCdPipelineOrchestrator pipeline.CiCdPipelineOrchestrator - gitOperationService git.GitOperationService - attributeService attributes.AttributesService - clusterRepository repository5.ClusterRepository + logger *zap.SugaredLogger + cdWorkflowCommonService cd.CdWorkflowCommonService + gitOpsManifestPushService publish.GitOpsPushService + gitOpsConfigReadService config.GitOpsConfigReadService + argoK8sClient argocdServer.ArgoK8sClient + ACDConfig *argocdServer.ACDConfig + argoClientWrapperService argocdServer.ArgoClientWrapperService + pipelineStatusTimelineService status.PipelineStatusTimelineService + chartTemplateService util.ChartTemplateService + eventFactory client.EventFactory + eventClient client.EventClient + globalEnvVariables *globalUtil.GlobalEnvVariables + workflowEventPublishService out.WorkflowEventPublishService + manifestCreationService manifest.ManifestCreationService + pipelineStageService pipeline.PipelineStageService + globalPluginService plugin.GlobalPluginService + customTagService pipeline.CustomTagService + pluginInputVariableParser pipeline.PluginInputVariableParser + prePostCdScriptHistoryService history.PrePostCdScriptHistoryService + scopedVariableManager variables.ScopedVariableCMCSManager + cdWorkflowService pipeline.WorkflowService + imageDigestPolicyService imageDigestPolicy.ImageDigestPolicyService + userService user.UserService + gitSensorClient gitSensorClient.Client + config *types.CdConfig + helmAppService client2.HelmAppService + imageScanService security2.ImageScanService + enforcerUtil rbac.EnforcerUtil + userDeploymentRequestService service.UserDeploymentRequestService + helmAppClient gRPC.HelmAppClient //TODO refactoring: use helm app service instead + appRepository appRepository.AppRepository + ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository + imageScanHistoryReadService read2.ImageScanHistoryReadService + imageScanDeployInfoService security2.ImageScanDeployInfoService + imageScanDeployInfoReadService read2.ImageScanDeployInfoReadService + pipelineRepository pipelineConfig.PipelineRepository + pipelineOverrideRepository chartConfig.PipelineOverrideRepository + manifestPushConfigRepository repository.ManifestPushConfigRepository + chartRepository chartRepoRepository.ChartRepository + envRepository repository2.EnvironmentRepository + cdWorkflowRepository pipelineConfig.CdWorkflowRepository + ciWorkflowRepository pipelineConfig.CiWorkflowRepository + ciArtifactRepository repository3.CiArtifactRepository + ciTemplateService pipeline2.CiTemplateReadService + gitMaterialReadService read.GitMaterialReadService + appLabelRepository pipelineConfig.AppLabelRepository + ciPipelineRepository pipelineConfig.CiPipelineRepository + appWorkflowRepository appWorkflow.AppWorkflowRepository + dockerArtifactStoreRepository repository4.DockerArtifactStoreRepository + K8sUtil *util5.K8sServiceImpl + transactionUtilImpl *sql.TransactionUtilImpl + deploymentConfigService common.DeploymentConfigService + deploymentServiceTypeConfig *globalUtil.DeploymentServiceTypeConfig + ciCdPipelineOrchestrator pipeline.CiCdPipelineOrchestrator + gitOperationService git.GitOperationService + attributeService attributes.AttributesService + clusterRepository repository5.ClusterRepository + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService } func NewTriggerServiceImpl(logger *zap.SugaredLogger, @@ -185,7 +186,6 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger, chartTemplateService util.ChartTemplateService, workflowEventPublishService out.WorkflowEventPublishService, manifestCreationService manifest.ManifestCreationService, - deployedConfigurationHistoryService history.DeployedConfigurationHistoryService, pipelineStageService pipeline.PipelineStageService, globalPluginService plugin.GlobalPluginService, customTagService pipeline.CustomTagService, @@ -230,34 +230,34 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger, gitOperationService git.GitOperationService, attributeService attributes.AttributesService, clusterRepository repository5.ClusterRepository, + deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, ) (*TriggerServiceImpl, error) { impl := &TriggerServiceImpl{ - logger: logger, - cdWorkflowCommonService: cdWorkflowCommonService, - gitOpsManifestPushService: gitOpsManifestPushService, - gitOpsConfigReadService: gitOpsConfigReadService, - argoK8sClient: argoK8sClient, - ACDConfig: ACDConfig, - argoClientWrapperService: argoClientWrapperService, - pipelineStatusTimelineService: pipelineStatusTimelineService, - chartTemplateService: chartTemplateService, - workflowEventPublishService: workflowEventPublishService, - manifestCreationService: manifestCreationService, - deployedConfigurationHistoryService: deployedConfigurationHistoryService, - pipelineStageService: pipelineStageService, - globalPluginService: globalPluginService, - customTagService: customTagService, - pluginInputVariableParser: pluginInputVariableParser, - prePostCdScriptHistoryService: prePostCdScriptHistoryService, - scopedVariableManager: scopedVariableManager, - cdWorkflowService: cdWorkflowService, - imageDigestPolicyService: imageDigestPolicyService, - userService: userService, - gitSensorClient: gitSensorClient, - helmAppService: helmAppService, - enforcerUtil: enforcerUtil, - eventFactory: eventFactory, - eventClient: eventClient, + logger: logger, + cdWorkflowCommonService: cdWorkflowCommonService, + gitOpsManifestPushService: gitOpsManifestPushService, + gitOpsConfigReadService: gitOpsConfigReadService, + argoK8sClient: argoK8sClient, + ACDConfig: ACDConfig, + argoClientWrapperService: argoClientWrapperService, + pipelineStatusTimelineService: pipelineStatusTimelineService, + chartTemplateService: chartTemplateService, + workflowEventPublishService: workflowEventPublishService, + manifestCreationService: manifestCreationService, + pipelineStageService: pipelineStageService, + globalPluginService: globalPluginService, + customTagService: customTagService, + pluginInputVariableParser: pluginInputVariableParser, + prePostCdScriptHistoryService: prePostCdScriptHistoryService, + scopedVariableManager: scopedVariableManager, + cdWorkflowService: cdWorkflowService, + imageDigestPolicyService: imageDigestPolicyService, + userService: userService, + gitSensorClient: gitSensorClient, + helmAppService: helmAppService, + enforcerUtil: enforcerUtil, + eventFactory: eventFactory, + eventClient: eventClient, globalEnvVariables: envVariables.GlobalEnvVariables, userDeploymentRequestService: userDeploymentRequestService, @@ -287,11 +287,12 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger, transactionUtilImpl: transactionUtilImpl, - deploymentConfigService: deploymentConfigService, - deploymentServiceTypeConfig: envVariables.DeploymentServiceTypeConfig, - ciCdPipelineOrchestrator: ciCdPipelineOrchestrator, - gitOperationService: gitOperationService, - attributeService: attributeService, + deploymentConfigService: deploymentConfigService, + deploymentServiceTypeConfig: envVariables.DeploymentServiceTypeConfig, + ciCdPipelineOrchestrator: ciCdPipelineOrchestrator, + gitOperationService: gitOperationService, + attributeService: attributeService, + deploymentTemplateHistoryService: deploymentTemplateHistoryService, clusterRepository: clusterRepository, } @@ -823,7 +824,7 @@ func (impl *TriggerServiceImpl) auditDeploymentTriggerHistory(cdWfrId int, value impl.logger.Warnw("unable to save histories for deployment trigger, invalid valuesOverrideResponse received", "cdWfrId", cdWfrId) return nil } - err1 := impl.deployedConfigurationHistoryService.CreateHistoriesForDeploymentTrigger(ctx, valuesOverrideResponse.Pipeline, valuesOverrideResponse.PipelineStrategy, valuesOverrideResponse.EnvOverride, triggeredAt, triggeredBy) + err1 := impl.deploymentTemplateHistoryService.CreateHistoriesForDeploymentTrigger(ctx, valuesOverrideResponse.Pipeline, valuesOverrideResponse.PipelineStrategy, valuesOverrideResponse.EnvOverride, triggeredAt, triggeredBy) if err1 != nil { impl.logger.Errorw("error in saving histories for deployment trigger", "err", err1, "pipelineId", valuesOverrideResponse.Pipeline.Id, "cdWfrId", cdWfrId) return nil diff --git a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go index 3917efb151..e3af20d9a6 100644 --- a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go +++ b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go @@ -1,13 +1,12 @@ package cdPipeline import ( - "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" + read2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" historyBean "github.com/devtron-labs/devtron/pkg/devtronResource/bean/history" "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/bean" - "github.com/devtron-labs/devtron/pkg/pipeline/history" bean2 "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" "go.uber.org/zap" ) @@ -18,27 +17,25 @@ type DeploymentHistoryService interface { } type DeploymentHistoryServiceImpl struct { - logger *zap.SugaredLogger - cdHandler pipeline.CdHandler - imageTaggingReadService read.ImageTaggingReadService - imageTaggingService imageTagging.ImageTaggingService - pipelineRepository pipelineConfig.PipelineRepository - deployedConfigurationHistoryService history.DeployedConfigurationHistoryService + logger *zap.SugaredLogger + cdHandler pipeline.CdHandler + imageTaggingReadService read.ImageTaggingReadService + imageTaggingService imageTagging.ImageTaggingService + deploymentTemplateHistoryReadService read2.DeploymentTemplateHistoryReadService } func NewDeploymentHistoryServiceImpl(logger *zap.SugaredLogger, cdHandler pipeline.CdHandler, imageTaggingReadService read.ImageTaggingReadService, imageTaggingService imageTagging.ImageTaggingService, - pipelineRepository pipelineConfig.PipelineRepository, - deployedConfigurationHistoryService history.DeployedConfigurationHistoryService) *DeploymentHistoryServiceImpl { + deploymentTemplateHistoryReadService read2.DeploymentTemplateHistoryReadService, +) *DeploymentHistoryServiceImpl { return &DeploymentHistoryServiceImpl{ - logger: logger, - cdHandler: cdHandler, - imageTaggingReadService: imageTaggingReadService, - imageTaggingService: imageTaggingService, - pipelineRepository: pipelineRepository, - deployedConfigurationHistoryService: deployedConfigurationHistoryService, + logger: logger, + cdHandler: cdHandler, + imageTaggingReadService: imageTaggingReadService, + imageTaggingService: imageTaggingService, + deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, } } @@ -69,7 +66,7 @@ func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistory(req *hi } func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistoryConfigList(req *historyBean.CdPipelineDeploymentHistoryConfigListReq) (resp []*bean2.DeployedHistoryComponentMetadataDto, err error) { - res, err := impl.deployedConfigurationHistoryService.GetDeployedHistoryComponentList(req.PipelineId, req.BaseConfigurationId, req.HistoryComponent, req.HistoryComponentName) + res, err := impl.deploymentTemplateHistoryReadService.GetDeployedHistoryComponentList(req.PipelineId, req.BaseConfigurationId, req.HistoryComponent, req.HistoryComponentName) if err != nil { impl.logger.Errorw("service err, GetDeployedHistoryComponentList", "err", err, "pipelineId", req.PipelineId) return nil, err diff --git a/pkg/pipeline/history/DeployedConfigurationHistoryService.go b/pkg/pipeline/history/DeployedConfigurationHistoryService.go deleted file mode 100644 index 6c41b7cc04..0000000000 --- a/pkg/pipeline/history/DeployedConfigurationHistoryService.go +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2024. Devtron Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package history - -import ( - "context" - "errors" - "fmt" - "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" - "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" - read2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" - "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" - bean2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/bean" - "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" - bean3 "github.com/devtron-labs/devtron/pkg/pipeline/history/bean" - "github.com/devtron-labs/devtron/pkg/variables" - repository5 "github.com/devtron-labs/devtron/pkg/variables/repository" - "github.com/devtron-labs/devtron/util/sliceUtil" - "go.opentelemetry.io/otel" - "time" - - "github.com/devtron-labs/devtron/api/bean" - repository2 "github.com/devtron-labs/devtron/internal/sql/repository" - "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" - "github.com/devtron-labs/devtron/pkg/auth/user" - "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" - "github.com/go-pg/pg" - "go.uber.org/zap" -) - -// TODO: Prakash, merge this interface with interface in deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go and extract out read logic in read repo -type DeployedConfigurationHistoryService interface { - //TODO: rethink if the below method right at this place - CreateHistoriesForDeploymentTrigger(ctx context.Context, pipeline *pipelineConfig.Pipeline, strategy *chartConfig.PipelineStrategy, envOverride *bean2.EnvConfigOverride, deployedOn time.Time, deployedBy int32) error - - GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*bean3.DeploymentConfigurationDto, error) - GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*bean3.DeployedHistoryComponentMetadataDto, error) - GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*bean3.HistoryDetailDto, error) - GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean3.AllDeploymentConfigurationDetail, error) - GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*bean3.AllDeploymentConfigurationDetail, error) - GetLatestDeployedArtifactByPipelineId(pipelineId int) (*repository2.CiArtifact, error) -} - -type DeployedConfigurationHistoryServiceImpl struct { - logger *zap.SugaredLogger - userService user.UserService - deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService - strategyHistoryService PipelineStrategyHistoryService - configMapHistoryService configMapAndSecret.ConfigMapHistoryService - cdWorkflowRepository pipelineConfig.CdWorkflowRepository - scopedVariableManager variables.ScopedVariableCMCSManager - deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService - configMapHistoryReadService read2.ConfigMapHistoryReadService -} - -func NewDeployedConfigurationHistoryServiceImpl(logger *zap.SugaredLogger, - userService user.UserService, deploymentTemplateHistoryService deploymentTemplate.DeploymentTemplateHistoryService, - strategyHistoryService PipelineStrategyHistoryService, configMapHistoryService configMapAndSecret.ConfigMapHistoryService, - cdWorkflowRepository pipelineConfig.CdWorkflowRepository, - scopedVariableManager variables.ScopedVariableCMCSManager, - deploymentTemplateHistoryReadService read.DeploymentTemplateHistoryReadService, - configMapHistoryReadService read2.ConfigMapHistoryReadService, -) *DeployedConfigurationHistoryServiceImpl { - return &DeployedConfigurationHistoryServiceImpl{ - logger: logger, - userService: userService, - deploymentTemplateHistoryService: deploymentTemplateHistoryService, - strategyHistoryService: strategyHistoryService, - configMapHistoryService: configMapHistoryService, - cdWorkflowRepository: cdWorkflowRepository, - scopedVariableManager: scopedVariableManager, - deploymentTemplateHistoryReadService: deploymentTemplateHistoryReadService, - configMapHistoryReadService: configMapHistoryReadService, - } -} - -func (impl *DeployedConfigurationHistoryServiceImpl) CreateHistoriesForDeploymentTrigger(ctx context.Context, pipeline *pipelineConfig.Pipeline, strategy *chartConfig.PipelineStrategy, envOverride *bean2.EnvConfigOverride, deployedOn time.Time, deployedBy int32) error { - _, span := otel.Tracer("orchestrator").Start(ctx, "DeployedConfigurationHistoryServiceImpl.CreateHistoriesForDeploymentTrigger") - defer span.End() - deploymentTemplateHistoryId, templateHistoryExists, err := impl.deploymentTemplateHistoryReadService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) - if err != nil { - impl.logger.Errorw("error in checking if deployment template history exists for deployment trigger", "err", err) - return err - } - if !templateHistoryExists { - // creating history for deployment template - deploymentTemplateHistory, err := impl.deploymentTemplateHistoryService.CreateDeploymentTemplateHistoryForDeploymentTrigger(pipeline, envOverride, envOverride.Chart.ImageDescriptorTemplate, deployedOn, deployedBy) - if err != nil { - impl.logger.Errorw("error in creating deployment template history for deployment trigger", "err", err) - return err - } - deploymentTemplateHistoryId = deploymentTemplateHistory.Id - } - cmId, csId, cmCsHistoryExists, err := impl.configMapHistoryReadService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) - if err != nil { - impl.logger.Errorw("error in checking if config map/ secrete history exists for deployment trigger", "err", err) - return err - } - if !cmCsHistoryExists { - cmId, csId, err = impl.configMapHistoryService.CreateCMCSHistoryForDeploymentTrigger(pipeline, deployedOn, deployedBy) - if err != nil { - impl.logger.Errorw("error in creating CM/CS history for deployment trigger", "err", err) - return err - } - } - if strategy != nil { - // checking if pipeline strategy configuration for this pipelineId and with deployedOn time exists or not - strategyHistoryExists, err := impl.strategyHistoryService.CheckIfTriggerHistoryExistsForPipelineIdOnTime(pipeline.Id, deployedOn) - if err != nil { - impl.logger.Errorw("error in checking if deployment template history exists for deployment trigger", "err", err) - return err - } - if !strategyHistoryExists { - err = impl.strategyHistoryService.CreateStrategyHistoryForDeploymentTrigger(strategy, deployedOn, deployedBy, pipeline.TriggerType) - if err != nil { - impl.logger.Errorw("error in creating strategy history for deployment trigger", "err", err) - return err - } - } - } - - var variableSnapshotHistories = sliceUtil.GetBeansPtr( - repository5.GetSnapshotBean(deploymentTemplateHistoryId, repository5.HistoryReferenceTypeDeploymentTemplate, envOverride.VariableSnapshot), - repository5.GetSnapshotBean(cmId, repository5.HistoryReferenceTypeConfigMap, envOverride.VariableSnapshotForCM), - repository5.GetSnapshotBean(csId, repository5.HistoryReferenceTypeSecret, envOverride.VariableSnapshotForCS), - ) - if len(variableSnapshotHistories) > 0 { - err = impl.scopedVariableManager.SaveVariableHistoriesForTrigger(variableSnapshotHistories, deployedBy) - if err != nil { - return err - } - } - return nil -} - -func (impl *DeployedConfigurationHistoryServiceImpl) GetLatestDeployedArtifactByPipelineId(pipelineId int) (*repository2.CiArtifact, error) { - wfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean.CD_WORKFLOW_TYPE_DEPLOY) - if err != nil { - impl.logger.Infow("error in getting latest deploy stage wfr by pipelineId", "err", err, "pipelineId", pipelineId) - return nil, err - } - return wfr.CdWorkflow.CiArtifact, nil -} - -func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedConfigurationByWfrId(ctx context.Context, pipelineId, wfrId int) ([]*bean3.DeploymentConfigurationDto, error) { - newCtx, span := otel.Tracer("orchestrator").Start(ctx, "DeployedConfigurationHistoryServiceImpl.GetDeployedConfigurationByWfrId") - defer span.End() - var deployedConfigurations []*bean3.DeploymentConfigurationDto - //checking if deployment template configuration for this pipelineId and wfrId exists or not - templateHistoryId, exists, err := impl.deploymentTemplateHistoryReadService.CheckIfHistoryExistsForPipelineIdAndWfrId(pipelineId, wfrId) - if err != nil { - impl.logger.Errorw("error in checking if history exists for deployment template", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - - deploymentTemplateConfiguration := &bean3.DeploymentConfigurationDto{ - Name: bean3.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT, - } - if exists { - deploymentTemplateConfiguration.Id = templateHistoryId - } - deployedConfigurations = append(deployedConfigurations, deploymentTemplateConfiguration) - - //checking if pipeline strategy configuration for this pipelineId and wfrId exists or not - - strategyHistoryId, exists, err := impl.strategyHistoryService.CheckIfHistoryExistsForPipelineIdAndWfrId(newCtx, pipelineId, wfrId) - if err != nil { - impl.logger.Errorw("error in checking if history exists for pipeline strategy", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - pipelineStrategyConfiguration := &bean3.DeploymentConfigurationDto{ - Name: bean3.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT, - } - if exists { - pipelineStrategyConfiguration.Id = strategyHistoryId - deployedConfigurations = append(deployedConfigurations, pipelineStrategyConfiguration) - } - - //checking if configmap history data exists and get its details - configmapHistory, exists, names, err := impl.configMapHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository.CONFIGMAP_TYPE) - if err != nil { - impl.logger.Errorw("error in checking if history exists for configmap", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - if exists { - configmapConfiguration := &bean3.DeploymentConfigurationDto{ - Id: configmapHistory.Id, - Name: bean3.CONFIGMAP_TYPE_HISTORY_COMPONENT, - ChildComponentNames: names, - } - deployedConfigurations = append(deployedConfigurations, configmapConfiguration) - } - - //checking if secret history data exists and get its details - secretHistory, exists, names, err := impl.configMapHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(pipelineId, wfrId, repository.SECRET_TYPE) - if err != nil { - impl.logger.Errorw("error in checking if history exists for secret", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - if exists { - secretConfiguration := &bean3.DeploymentConfigurationDto{ - Id: secretHistory.Id, - Name: bean3.SECRET_TYPE_HISTORY_COMPONENT, - ChildComponentNames: names, - } - deployedConfigurations = append(deployedConfigurations, secretConfiguration) - } - return deployedConfigurations, nil -} - -func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponentList(pipelineId, baseConfigId int, historyComponent, historyComponentName string) ([]*bean3.DeployedHistoryComponentMetadataDto, error) { - var historyList []*bean3.DeployedHistoryComponentMetadataDto - var err error - if historyComponent == string(bean3.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.deploymentTemplateHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId) - } else if historyComponent == string(bean3.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.strategyHistoryService.GetDeployedHistoryList(pipelineId, baseConfigId) - } else if historyComponent == string(bean3.CONFIGMAP_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.configMapHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId, repository.CONFIGMAP_TYPE, historyComponentName) - } else if historyComponent == string(bean3.SECRET_TYPE_HISTORY_COMPONENT) { - historyList, err = impl.configMapHistoryReadService.GetDeployedHistoryList(pipelineId, baseConfigId, repository.SECRET_TYPE, historyComponentName) - } else { - return nil, errors.New(fmt.Sprintf("history of %s not supported", historyComponent)) - } - if err != nil { - impl.logger.Errorw("error in getting deployed history component list", "err", err, "pipelineId", pipelineId, "historyComponent", historyComponent, "componentName", historyComponentName) - return nil, err - } - return historyList, nil -} - -func (impl *DeployedConfigurationHistoryServiceImpl) GetDeployedHistoryComponentDetail(ctx context.Context, pipelineId, id int, historyComponent, historyComponentName string, userHasAdminAccess bool) (*bean3.HistoryDetailDto, error) { - history := &bean3.HistoryDetailDto{} - var err error - if historyComponent == string(bean3.DEPLOYMENT_TEMPLATE_TYPE_HISTORY_COMPONENT) { - history, err = impl.deploymentTemplateHistoryReadService.GetHistoryForDeployedTemplateById(ctx, id, pipelineId) - } else if historyComponent == string(bean3.PIPELINE_STRATEGY_TYPE_HISTORY_COMPONENT) { - history, err = impl.strategyHistoryService.GetHistoryForDeployedStrategyById(id, pipelineId) - } else if historyComponent == string(bean3.CONFIGMAP_TYPE_HISTORY_COMPONENT) { - history, err = impl.configMapHistoryReadService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository.CONFIGMAP_TYPE, historyComponentName, userHasAdminAccess) - } else if historyComponent == string(bean3.SECRET_TYPE_HISTORY_COMPONENT) { - history, err = impl.configMapHistoryReadService.GetHistoryForDeployedCMCSById(ctx, id, pipelineId, repository.SECRET_TYPE, historyComponentName, userHasAdminAccess) - } else { - return nil, errors.New(fmt.Sprintf("history of %s not supported", historyComponent)) - } - if err != nil { - impl.logger.Errorw("error in getting deployed history component detail", "err", err, "pipelineId", pipelineId, "id", id, "historyComponent", historyComponent, "componentName", historyComponentName) - return nil, err - } - return history, nil -} - -func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfigurationByPipelineIdAndLatestWfrId(ctx context.Context, pipelineId int, userHasAdminAccess bool) (*bean3.AllDeploymentConfigurationDetail, error) { - //getting latest wfr from pipelineId - wfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean.CD_WORKFLOW_TYPE_DEPLOY) - if err != nil { - impl.logger.Errorw("error in getting latest deploy stage wfr by pipelineId", "err", err, "pipelineId", pipelineId) - return nil, err - } - deployedConfig, err := impl.GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx, pipelineId, wfr.Id, userHasAdminAccess) - if err != nil { - impl.logger.Errorw("error in getting GetAllDeployedConfigurationByPipelineIdAndWfrId", "err", err, "pipelineID", pipelineId, "wfrId", wfr.Id) - return nil, err - } - deployedConfig.WfrId = wfr.Id - return deployedConfig, nil -} -func (impl *DeployedConfigurationHistoryServiceImpl) GetAllDeployedConfigurationByPipelineIdAndWfrId(ctx context.Context, pipelineId, wfrId int, userHasAdminAccess bool) (*bean3.AllDeploymentConfigurationDetail, error) { - //getting history of deployment template for latest deployment - deploymentTemplateHistory, err := impl.deploymentTemplateHistoryReadService.GetDeployedHistoryByPipelineIdAndWfrId(ctx, pipelineId, wfrId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting deployment template history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - //getting history of config map for latest deployment - configMapHistory, err := impl.configMapHistoryReadService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository.CONFIGMAP_TYPE, userHasAdminAccess) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting config map history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - //getting history of secret for latest deployment - secretHistory, err := impl.configMapHistoryReadService.GetDeployedHistoryDetailForCMCSByPipelineIdAndWfrId(ctx, pipelineId, wfrId, repository.SECRET_TYPE, userHasAdminAccess) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting secret history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - //getting history of pipeline strategy for latest deployment - strategyHistory, err := impl.strategyHistoryService.GetLatestDeployedHistoryByPipelineIdAndWfrId(ctx, pipelineId, wfrId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting strategy history by pipelineId and wfrId", "err", err, "pipelineId", pipelineId, "wfrId", wfrId) - return nil, err - } - allDeploymentConfigurationHistoryDetail := &bean3.AllDeploymentConfigurationDetail{ - DeploymentTemplateConfig: deploymentTemplateHistory, - ConfigMapConfig: configMapHistory, - SecretConfig: secretHistory, - StrategyConfig: strategyHistory, - } - return allDeploymentConfigurationHistoryDetail, nil -} diff --git a/wire_gen.go b/wire_gen.go index b59e017b53..abad904414 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject @@ -140,7 +140,7 @@ import ( repository4 "github.com/devtron-labs/devtron/pkg/auth/user/repository" "github.com/devtron-labs/devtron/pkg/build/artifacts" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" - read12 "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" + read13 "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" "github.com/devtron-labs/devtron/pkg/build/git/gitHost" read16 "github.com/devtron-labs/devtron/pkg/build/git/gitHost/read" repository25 "github.com/devtron-labs/devtron/pkg/build/git/gitHost/repository" @@ -178,7 +178,7 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/gitOps/validation" "github.com/devtron-labs/devtron/pkg/deployment/manifest" "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" - read14 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" + read12 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" repository16 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics/repository" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" @@ -233,7 +233,7 @@ import ( "github.com/devtron-labs/devtron/pkg/plugin" repository18 "github.com/devtron-labs/devtron/pkg/plugin/repository" "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning" - read13 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/read" + read14 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/read" repository23 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/repository" "github.com/devtron-labs/devtron/pkg/policyGovernance/security/scanTool" repository15 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/scanTool/repository" @@ -641,7 +641,11 @@ func InitializeApp() (*App, error) { pipelineConfigRepositoryImpl := chartConfig.NewPipelineConfigRepository(db) configMapServiceImpl := pipeline.NewConfigMapServiceImpl(chartRepositoryImpl, sugaredLogger, chartRepoRepositoryImpl, mergeUtil, pipelineConfigRepositoryImpl, configMapRepositoryImpl, envConfigOverrideRepositoryImpl, commonServiceImpl, appRepositoryImpl, configMapHistoryServiceImpl, environmentRepositoryImpl, scopedVariableCMCSManagerImpl) deploymentTemplateHistoryRepositoryImpl := repository20.NewDeploymentTemplateHistoryRepositoryImpl(sugaredLogger, db) - deploymentTemplateHistoryServiceImpl := deploymentTemplate.NewDeploymentTemplateHistoryServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, pipelineRepositoryImpl, chartRepositoryImpl, userServiceImpl, cdWorkflowRepositoryImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl) + pipelineStrategyHistoryRepositoryImpl := repository20.NewPipelineStrategyHistoryRepositoryImpl(sugaredLogger, db) + pipelineStrategyHistoryServiceImpl := history.NewPipelineStrategyHistoryServiceImpl(sugaredLogger, pipelineStrategyHistoryRepositoryImpl, userServiceImpl) + configMapHistoryReadServiceImpl := read12.NewConfigMapHistoryReadService(sugaredLogger, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl) + deploymentTemplateHistoryReadServiceImpl := read7.NewDeploymentTemplateHistoryReadServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, scopedVariableManagerImpl, pipelineStrategyHistoryServiceImpl, cdWorkflowRepositoryImpl, configMapHistoryReadServiceImpl) + deploymentTemplateHistoryServiceImpl := deploymentTemplate.NewDeploymentTemplateHistoryServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, pipelineRepositoryImpl, chartRepositoryImpl, userServiceImpl, cdWorkflowRepositoryImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, pipelineStrategyHistoryServiceImpl, configMapHistoryServiceImpl, deploymentTemplateHistoryReadServiceImpl, configMapHistoryReadServiceImpl) chartServiceImpl := chart.NewChartServiceImpl(chartRepositoryImpl, sugaredLogger, chartTemplateServiceImpl, chartRepoRepositoryImpl, appRepositoryImpl, mergeUtil, envConfigOverrideRepositoryImpl, pipelineConfigRepositoryImpl, environmentRepositoryImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, gitOpsConfigReadServiceImpl, deploymentConfigServiceImpl, envConfigOverrideReadServiceImpl) ciCdPipelineOrchestratorImpl := pipeline.NewCiCdPipelineOrchestrator(appRepositoryImpl, sugaredLogger, materialRepositoryImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, cdWorkflowRepositoryImpl, clientImpl, ciCdConfig, appWorkflowRepositoryImpl, environmentRepositoryImpl, attributesServiceImpl, appCrudOperationServiceImpl, userAuthServiceImpl, prePostCdScriptHistoryServiceImpl, pipelineStageServiceImpl, gitMaterialHistoryServiceImpl, ciPipelineHistoryServiceImpl, ciTemplateReadServiceImpl, ciTemplateServiceImpl, dockerArtifactStoreRepositoryImpl, ciArtifactRepositoryImpl, configMapServiceImpl, customTagServiceImpl, genericNoteServiceImpl, chartServiceImpl, transactionUtilImpl, gitOpsConfigReadServiceImpl, deploymentConfigServiceImpl) ciServiceImpl := pipeline.NewCiServiceImpl(sugaredLogger, workflowServiceImpl, ciPipelineMaterialRepositoryImpl, ciWorkflowRepositoryImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineStageServiceImpl, userServiceImpl, ciTemplateReadServiceImpl, appCrudOperationServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, customTagServiceImpl, pluginInputVariableParserImpl, globalPluginServiceImpl, infraProviderImpl, ciCdPipelineOrchestratorImpl, attributesServiceImpl) @@ -653,7 +657,7 @@ func InitializeApp() (*App, error) { resourceGroupMappingRepositoryImpl := resourceGroup.NewResourceGroupMappingRepositoryImpl(db) resourceGroupServiceImpl := resourceGroup2.NewResourceGroupServiceImpl(sugaredLogger, resourceGroupRepositoryImpl, resourceGroupMappingRepositoryImpl, enforcerUtilImpl, devtronResourceSearchableKeyServiceImpl, appStatusRepositoryImpl) imageTaggingRepositoryImpl := repository21.NewImageTaggingRepositoryImpl(db, transactionUtilImpl) - imageTaggingReadServiceImpl, err := read12.NewImageTaggingReadServiceImpl(imageTaggingRepositoryImpl, sugaredLogger) + imageTaggingReadServiceImpl, err := read13.NewImageTaggingReadServiceImpl(imageTaggingRepositoryImpl, sugaredLogger) if err != nil { return nil, err } @@ -673,8 +677,6 @@ func InitializeApp() (*App, error) { ciPipelineConfigServiceImpl := pipeline.NewCiPipelineConfigServiceImpl(sugaredLogger, ciCdPipelineOrchestratorImpl, dockerArtifactStoreRepositoryImpl, gitMaterialReadServiceImpl, appRepositoryImpl, pipelineRepositoryImpl, ciPipelineConfigReadServiceImpl, ciPipelineRepositoryImpl, ecrConfig, appWorkflowRepositoryImpl, ciCdConfig, attributesServiceImpl, pipelineStageServiceImpl, ciPipelineMaterialRepositoryImpl, ciTemplateServiceImpl, ciTemplateReadServiceImpl, ciTemplateOverrideRepositoryImpl, ciTemplateHistoryServiceImpl, enforcerUtilImpl, ciWorkflowRepositoryImpl, resourceGroupServiceImpl, customTagServiceImpl, cdWorkflowRepositoryImpl, buildPipelineSwitchServiceImpl, pipelineStageRepositoryImpl, globalPluginRepositoryImpl) ciMaterialConfigServiceImpl := pipeline.NewCiMaterialConfigServiceImpl(sugaredLogger, materialRepositoryImpl, ciTemplateReadServiceImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, gitMaterialHistoryServiceImpl, pipelineRepositoryImpl, ciPipelineMaterialRepositoryImpl, transactionUtilImpl, gitMaterialReadServiceImpl) deploymentGroupRepositoryImpl := repository2.NewDeploymentGroupRepositoryImpl(sugaredLogger, db) - pipelineStrategyHistoryRepositoryImpl := repository20.NewPipelineStrategyHistoryRepositoryImpl(sugaredLogger, db) - pipelineStrategyHistoryServiceImpl := history.NewPipelineStrategyHistoryServiceImpl(sugaredLogger, pipelineStrategyHistoryRepositoryImpl, userServiceImpl) propertiesConfigServiceImpl := pipeline.NewPropertiesConfigServiceImpl(sugaredLogger, envConfigOverrideRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl, envConfigOverrideReadServiceImpl) imageDigestPolicyServiceImpl := imageDigestPolicy.NewImageDigestPolicyServiceImpl(sugaredLogger, qualifierMappingServiceImpl, devtronResourceSearchableKeyServiceImpl) pipelineConfigEventPublishServiceImpl := out.NewPipelineConfigEventPublishServiceImpl(sugaredLogger, pubSubClientServiceImpl) @@ -708,7 +710,6 @@ func InitializeApp() (*App, error) { appWorkflowServiceImpl := appWorkflow2.NewAppWorkflowServiceImpl(sugaredLogger, appWorkflowRepositoryImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, appRepositoryImpl, userAuthServiceImpl, chartServiceImpl, deploymentConfigServiceImpl) appCloneServiceImpl := appClone.NewAppCloneServiceImpl(sugaredLogger, pipelineBuilderImpl, attributesServiceImpl, chartServiceImpl, configMapServiceImpl, appWorkflowServiceImpl, appListingServiceImpl, propertiesConfigServiceImpl, pipelineStageServiceImpl, ciTemplateReadServiceImpl, appRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, ciPipelineConfigServiceImpl, gitOpsConfigReadServiceImpl) deploymentTemplateRepositoryImpl := repository2.NewDeploymentTemplateRepositoryImpl(db, sugaredLogger) - deploymentTemplateHistoryReadServiceImpl := read7.NewDeploymentTemplateHistoryReadServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, scopedVariableManagerImpl) generateManifestDeploymentTemplateServiceImpl, err := generateManifest.NewDeploymentTemplateServiceImpl(sugaredLogger, chartServiceImpl, appListingServiceImpl, deploymentTemplateRepositoryImpl, helmAppReadServiceImpl, chartTemplateServiceImpl, helmAppClientImpl, k8sServiceImpl, propertiesConfigServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, chartRefServiceImpl, pipelineOverrideRepositoryImpl, chartRepositoryImpl, pipelineRepositoryImpl, utilMergeUtil, deploymentTemplateHistoryReadServiceImpl) if err != nil { return nil, err @@ -718,25 +719,23 @@ func InitializeApp() (*App, error) { imageScanDeployInfoRepositoryImpl := repository23.NewImageScanDeployInfoRepositoryImpl(db, sugaredLogger) imageScanObjectMetaRepositoryImpl := repository23.NewImageScanObjectMetaRepositoryImpl(db, sugaredLogger) imageScanHistoryRepositoryImpl := repository23.NewImageScanHistoryRepositoryImpl(db, sugaredLogger) - imageScanHistoryReadServiceImpl := read13.NewImageScanHistoryReadService(sugaredLogger, imageScanHistoryRepositoryImpl) + imageScanHistoryReadServiceImpl := read14.NewImageScanHistoryReadService(sugaredLogger, imageScanHistoryRepositoryImpl) cveStoreRepositoryImpl := repository23.NewCveStoreRepositoryImpl(db, sugaredLogger) policyServiceImpl := imageScanning.NewPolicyServiceImpl(environmentServiceImpl, sugaredLogger, appRepositoryImpl, pipelineOverrideRepositoryImpl, cvePolicyRepositoryImpl, clusterServiceImplExtended, pipelineRepositoryImpl, imageScanResultRepositoryImpl, imageScanDeployInfoRepositoryImpl, imageScanObjectMetaRepositoryImpl, httpClient, ciArtifactRepositoryImpl, ciCdConfig, imageScanHistoryReadServiceImpl, cveStoreRepositoryImpl, ciTemplateRepositoryImpl, clusterReadServiceImpl, transactionUtilImpl) - imageScanResultReadServiceImpl := read13.NewImageScanResultReadServiceImpl(sugaredLogger, imageScanResultRepositoryImpl) + imageScanResultReadServiceImpl := read14.NewImageScanResultReadServiceImpl(sugaredLogger, imageScanResultRepositoryImpl) pipelineConfigRestHandlerImpl := configure.NewPipelineRestHandlerImpl(pipelineBuilderImpl, sugaredLogger, deploymentTemplateValidationServiceImpl, chartServiceImpl, devtronAppGitOpConfigServiceImpl, propertiesConfigServiceImpl, userServiceImpl, teamServiceImpl, enforcerImpl, ciHandlerImpl, validate, clientImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, dockerRegistryConfigImpl, cdHandlerImpl, appCloneServiceImpl, generateManifestDeploymentTemplateServiceImpl, appWorkflowServiceImpl, gitMaterialReadServiceImpl, policyServiceImpl, imageScanResultReadServiceImpl, ciPipelineMaterialRepositoryImpl, imageTaggingReadServiceImpl, imageTaggingServiceImpl, ciArtifactRepositoryImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, ciCdPipelineOrchestratorImpl, gitProviderReadServiceImpl, teamReadServiceImpl) gitOpsManifestPushServiceImpl := publish.NewGitOpsManifestPushServiceImpl(sugaredLogger, pipelineStatusTimelineServiceImpl, pipelineOverrideRepositoryImpl, acdConfig, chartRefServiceImpl, gitOpsConfigReadServiceImpl, chartServiceImpl, gitOperationServiceImpl, argoClientWrapperServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, chartTemplateServiceImpl) argoK8sClientImpl := argocdServer.NewArgoK8sClientImpl(sugaredLogger, k8sServiceImpl) manifestCreationServiceImpl := manifest.NewManifestCreationServiceImpl(sugaredLogger, dockerRegistryIpsConfigServiceImpl, chartRefServiceImpl, scopedVariableCMCSManagerImpl, k8sCommonServiceImpl, deployedAppMetricsServiceImpl, imageDigestPolicyServiceImpl, utilMergeUtil, appCrudOperationServiceImpl, deploymentTemplateServiceImpl, argoClientWrapperServiceImpl, configMapHistoryRepositoryImpl, configMapRepositoryImpl, chartRepositoryImpl, envConfigOverrideRepositoryImpl, environmentRepositoryImpl, pipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineOverrideRepositoryImpl, pipelineStrategyHistoryRepositoryImpl, pipelineConfigRepositoryImpl, deploymentTemplateHistoryRepositoryImpl, deploymentConfigServiceImpl, envConfigOverrideReadServiceImpl) - configMapHistoryReadServiceImpl := read14.NewConfigMapHistoryReadService(sugaredLogger, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl) - deployedConfigurationHistoryServiceImpl := history.NewDeployedConfigurationHistoryServiceImpl(sugaredLogger, userServiceImpl, deploymentTemplateHistoryServiceImpl, pipelineStrategyHistoryServiceImpl, configMapHistoryServiceImpl, cdWorkflowRepositoryImpl, scopedVariableCMCSManagerImpl, deploymentTemplateHistoryReadServiceImpl, configMapHistoryReadServiceImpl) userDeploymentRequestRepositoryImpl := repository24.NewUserDeploymentRequestRepositoryImpl(db, transactionUtilImpl) userDeploymentRequestServiceImpl := service3.NewUserDeploymentRequestServiceImpl(sugaredLogger, userDeploymentRequestRepositoryImpl) - imageScanDeployInfoReadServiceImpl := read13.NewImageScanDeployInfoReadService(sugaredLogger, imageScanDeployInfoRepositoryImpl) + imageScanDeployInfoReadServiceImpl := read14.NewImageScanDeployInfoReadService(sugaredLogger, imageScanDeployInfoRepositoryImpl) imageScanDeployInfoServiceImpl := imageScanning.NewImageScanDeployInfoService(sugaredLogger, imageScanDeployInfoRepositoryImpl) manifestPushConfigRepositoryImpl := repository17.NewManifestPushConfigRepository(sugaredLogger, db) scanToolExecutionHistoryMappingRepositoryImpl := repository23.NewScanToolExecutionHistoryMappingRepositoryImpl(db, sugaredLogger) cdWorkflowReadServiceImpl := read15.NewCdWorkflowReadServiceImpl(sugaredLogger, cdWorkflowRepositoryImpl) imageScanServiceImpl := imageScanning.NewImageScanServiceImpl(sugaredLogger, imageScanHistoryRepositoryImpl, imageScanResultRepositoryImpl, imageScanObjectMetaRepositoryImpl, cveStoreRepositoryImpl, imageScanDeployInfoRepositoryImpl, userServiceImpl, appRepositoryImpl, environmentServiceImpl, ciArtifactRepositoryImpl, policyServiceImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, scanToolMetadataRepositoryImpl, scanToolExecutionHistoryMappingRepositoryImpl, cvePolicyRepositoryImpl, cdWorkflowReadServiceImpl) - triggerServiceImpl, err := devtronApps.NewTriggerServiceImpl(sugaredLogger, cdWorkflowCommonServiceImpl, gitOpsManifestPushServiceImpl, gitOpsConfigReadServiceImpl, argoK8sClientImpl, acdConfig, argoClientWrapperServiceImpl, pipelineStatusTimelineServiceImpl, chartTemplateServiceImpl, workflowEventPublishServiceImpl, manifestCreationServiceImpl, deployedConfigurationHistoryServiceImpl, pipelineStageServiceImpl, globalPluginServiceImpl, customTagServiceImpl, pluginInputVariableParserImpl, prePostCdScriptHistoryServiceImpl, scopedVariableCMCSManagerImpl, workflowServiceImpl, imageDigestPolicyServiceImpl, userServiceImpl, clientImpl, helmAppServiceImpl, enforcerUtilImpl, userDeploymentRequestServiceImpl, helmAppClientImpl, eventSimpleFactoryImpl, eventRESTClientImpl, environmentVariables, appRepositoryImpl, ciPipelineMaterialRepositoryImpl, imageScanHistoryReadServiceImpl, imageScanDeployInfoReadServiceImpl, imageScanDeployInfoServiceImpl, pipelineRepositoryImpl, pipelineOverrideRepositoryImpl, manifestPushConfigRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, cdWorkflowRepositoryImpl, ciWorkflowRepositoryImpl, ciArtifactRepositoryImpl, ciTemplateReadServiceImpl, gitMaterialReadServiceImpl, appLabelRepositoryImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, dockerArtifactStoreRepositoryImpl, imageScanServiceImpl, k8sServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, ciCdPipelineOrchestratorImpl, gitOperationServiceImpl, attributesServiceImpl, clusterRepositoryImpl) + triggerServiceImpl, err := devtronApps.NewTriggerServiceImpl(sugaredLogger, cdWorkflowCommonServiceImpl, gitOpsManifestPushServiceImpl, gitOpsConfigReadServiceImpl, argoK8sClientImpl, acdConfig, argoClientWrapperServiceImpl, pipelineStatusTimelineServiceImpl, chartTemplateServiceImpl, workflowEventPublishServiceImpl, manifestCreationServiceImpl, pipelineStageServiceImpl, globalPluginServiceImpl, customTagServiceImpl, pluginInputVariableParserImpl, prePostCdScriptHistoryServiceImpl, scopedVariableCMCSManagerImpl, workflowServiceImpl, imageDigestPolicyServiceImpl, userServiceImpl, clientImpl, helmAppServiceImpl, enforcerUtilImpl, userDeploymentRequestServiceImpl, helmAppClientImpl, eventSimpleFactoryImpl, eventRESTClientImpl, environmentVariables, appRepositoryImpl, ciPipelineMaterialRepositoryImpl, imageScanHistoryReadServiceImpl, imageScanDeployInfoReadServiceImpl, imageScanDeployInfoServiceImpl, pipelineRepositoryImpl, pipelineOverrideRepositoryImpl, manifestPushConfigRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, cdWorkflowRepositoryImpl, ciWorkflowRepositoryImpl, ciArtifactRepositoryImpl, ciTemplateReadServiceImpl, gitMaterialReadServiceImpl, appLabelRepositoryImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, dockerArtifactStoreRepositoryImpl, imageScanServiceImpl, k8sServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, ciCdPipelineOrchestratorImpl, gitOperationServiceImpl, attributesServiceImpl, clusterRepositoryImpl, deploymentTemplateHistoryServiceImpl) if err != nil { return nil, err } @@ -935,7 +934,7 @@ func InitializeApp() (*App, error) { pipelineConfigRouterImpl := configure2.NewPipelineRouterImpl(pipelineConfigRestHandlerImpl, webhookDataRestHandlerImpl) prePostCiScriptHistoryRepositoryImpl := repository20.NewPrePostCiScriptHistoryRepositoryImpl(sugaredLogger, db) prePostCiScriptHistoryServiceImpl := history.NewPrePostCiScriptHistoryServiceImpl(sugaredLogger, prePostCiScriptHistoryRepositoryImpl) - pipelineHistoryRestHandlerImpl := history2.NewPipelineHistoryRestHandlerImpl(sugaredLogger, userServiceImpl, enforcerImpl, pipelineStrategyHistoryServiceImpl, deploymentTemplateHistoryServiceImpl, configMapHistoryServiceImpl, prePostCiScriptHistoryServiceImpl, prePostCdScriptHistoryServiceImpl, enforcerUtilImpl, deployedConfigurationHistoryServiceImpl) + pipelineHistoryRestHandlerImpl := history2.NewPipelineHistoryRestHandlerImpl(sugaredLogger, userServiceImpl, enforcerImpl, pipelineStrategyHistoryServiceImpl, configMapHistoryServiceImpl, prePostCiScriptHistoryServiceImpl, prePostCdScriptHistoryServiceImpl, enforcerUtilImpl, deploymentTemplateHistoryReadServiceImpl) pipelineHistoryRouterImpl := history3.NewPipelineHistoryRouterImpl(pipelineHistoryRestHandlerImpl) pipelineStatusTimelineRestHandlerImpl := status3.NewPipelineStatusTimelineRestHandlerImpl(sugaredLogger, userServiceImpl, pipelineStatusTimelineServiceImpl, enforcerUtilImpl, enforcerImpl, cdApplicationStatusUpdateHandlerImpl, pipelineBuilderImpl) pipelineStatusRouterImpl := status4.NewPipelineStatusRouterImpl(pipelineStatusTimelineRestHandlerImpl) @@ -1036,7 +1035,7 @@ func InitializeApp() (*App, error) { infraConfigRouterImpl := infraConfig.NewInfraProfileRouterImpl(infraConfigRestHandlerImpl) argoApplicationRestHandlerImpl := argoApplication2.NewArgoApplicationRestHandlerImpl(argoApplicationServiceExtendedImpl, argoApplicationReadServiceImpl, sugaredLogger, enforcerImpl) argoApplicationRouterImpl := argoApplication2.NewArgoApplicationRouterImpl(argoApplicationRestHandlerImpl) - deploymentHistoryServiceImpl := cdPipeline.NewDeploymentHistoryServiceImpl(sugaredLogger, cdHandlerImpl, imageTaggingReadServiceImpl, imageTaggingServiceImpl, pipelineRepositoryImpl, deployedConfigurationHistoryServiceImpl) + deploymentHistoryServiceImpl := cdPipeline.NewDeploymentHistoryServiceImpl(sugaredLogger, cdHandlerImpl, imageTaggingReadServiceImpl, imageTaggingServiceImpl, deploymentTemplateHistoryReadServiceImpl) apiReqDecoderServiceImpl := devtronResource.NewAPIReqDecoderServiceImpl(sugaredLogger, pipelineRepositoryImpl) historyRestHandlerImpl := devtronResource2.NewHistoryRestHandlerImpl(sugaredLogger, enforcerImpl, deploymentHistoryServiceImpl, apiReqDecoderServiceImpl, enforcerUtilImpl) historyRouterImpl := devtronResource2.NewHistoryRouterImpl(historyRestHandlerImpl)