Skip to content
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

misc: merge DeployedConfigurationHistoryService.go in deplTemplateHistory read service and service #6325

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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
}
Loading
Loading