From dcfd98baccc1441afac09f75cfaab6510abe28ce Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Thu, 16 Jan 2025 20:03:53 +0530 Subject: [PATCH 01/16] wip:deployment config old data migration code --- .../repository/deploymentConfig/repository.go | 13 +- pkg/appStore/bean/bean.go | 25 +- pkg/chartRepo/repository/ChartsRepository.go | 2 +- pkg/deployment/common/adapter.go | 35 +- pkg/deployment/common/bean/bean.go | 65 +- .../common/deploymentConfigService.go | 559 +++++++++++------- .../DeploymentPipelineConfigService.go | 1 - wire_gen.go | 2 +- 8 files changed, 460 insertions(+), 242 deletions(-) diff --git a/internal/sql/repository/deploymentConfig/repository.go b/internal/sql/repository/deploymentConfig/repository.go index 0dac42b98b..de57e4fe3f 100644 --- a/internal/sql/repository/deploymentConfig/repository.go +++ b/internal/sql/repository/deploymentConfig/repository.go @@ -29,7 +29,8 @@ type DeploymentConfig struct { ConfigType string `sql:"config_type"` RepoUrl string `sql:"repo_url"` RepoName string `sql:"repo_name"` - ReleaseMode string `json:"release_mode"` + ReleaseMode string `sql:"release_mode"` + ReleaseConfig string `sql:"release_config"` Active bool `sql:"active,notnull"` sql.AuditLog } @@ -46,6 +47,7 @@ type Repository interface { GetAppAndEnvLevelConfigsInBulk(appIdToEnvIdsMap map[int][]int) ([]*DeploymentConfig, error) GetByAppIdAndEnvIdEvenIfInactive(appId, envId int) (*DeploymentConfig, error) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, envId int) error + GetAllWithEmptyReleaseConfig() ([]*DeploymentConfig, error) } type RepositoryImpl struct { @@ -172,3 +174,12 @@ func (impl *RepositoryImpl) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, Update() return err } + +func (impl *RepositoryImpl) GetAllWithEmptyReleaseConfig() ([]*DeploymentConfig, error) { + result := make([]*DeploymentConfig, 0) + err := impl.dbConnection.Model(&result).Where("length(release_config)=0 ").Select() + if err != nil { + return nil, err + } + return result, nil +} diff --git a/pkg/appStore/bean/bean.go b/pkg/appStore/bean/bean.go index e74f3dc032..efac1068ba 100644 --- a/pkg/appStore/bean/bean.go +++ b/pkg/appStore/bean/bean.go @@ -19,14 +19,16 @@ package appStoreBean import ( "encoding/json" "github.com/argoproj/gitops-engine/pkg/health" + "github.com/devtron-labs/common-lib/utils/k8s/commonBean" apiBean "github.com/devtron-labs/devtron/api/bean/gitOps" openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient" bean3 "github.com/devtron-labs/devtron/api/helm-app/service/bean" + "github.com/devtron-labs/devtron/client/argocdServer" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" + util2 "github.com/devtron-labs/devtron/internal/util" "github.com/devtron-labs/devtron/pkg/cluster/environment/bean" bean2 "github.com/devtron-labs/devtron/pkg/deployment/common/bean" "github.com/devtron-labs/devtron/util" - "github.com/devtron-labs/devtron/util/gitUtil" "slices" "time" ) @@ -218,9 +220,24 @@ func (chart *InstallAppVersionDTO) GetDeploymentConfig() *bean2.DeploymentConfig EnvironmentId: chart.EnvironmentId, ConfigType: configType, DeploymentAppType: chart.DeploymentAppType, - RepoURL: chart.GitOpsRepoURL, - RepoName: gitUtil.GetGitRepoNameFromGitRepoUrl(chart.GitOpsRepoURL), - Active: true, + ReleaseMode: util2.PIPELINE_RELEASE_MODE_CREATE, + ReleaseConfiguration: &bean2.ReleaseConfiguration{ + ArgoCDSpec: bean2.ArgoCDSpec{ + ClusterId: DEFAULT_CLUSTER_ID, + Namespace: argocdServer.DevtronInstalationNs, + Destination: &bean2.Destination{ + Namespace: chart.Namespace, + Server: commonBean.DefaultClusterUrl, + }, + Source: &bean2.Source{ + RepoURL: chart.GitOpsRepoURL, + ChartPath: util.BuildDeployedAppName(chart.AppName, chart.EnvironmentName), + ValuesFilePath: "values.yaml", + TargetRevision: "master", + }, + }, + }, + Active: true, } } diff --git a/pkg/chartRepo/repository/ChartsRepository.go b/pkg/chartRepo/repository/ChartsRepository.go index 32229c17c9..b73b06e69e 100644 --- a/pkg/chartRepo/repository/ChartsRepository.go +++ b/pkg/chartRepo/repository/ChartsRepository.go @@ -38,7 +38,7 @@ type Chart struct { Status models.ChartStatus `sql:"status"` //(new , deployment-in-progress, deployed-To-production, error ) Active bool `sql:"active"` GitRepoUrl string `sql:"git_repo_url"` // Deprecated; use deployment_config table instead //git repository where chart is stored - ChartLocation string `sql:"chart_location"` //location within git repo where current chart is pointing + ChartLocation string `sql:"chart_location"` // Deprecated; location within git repo where current chart is pointing ReferenceTemplate string `sql:"reference_template"` ImageDescriptorTemplate string `sql:"image_descriptor_template"` ChartRefId int `sql:"chart_ref_id"` diff --git a/pkg/deployment/common/adapter.go b/pkg/deployment/common/adapter.go index 9d58afaa20..34f29ca03e 100644 --- a/pkg/deployment/common/adapter.go +++ b/pkg/deployment/common/adapter.go @@ -1,32 +1,41 @@ package common import ( + "encoding/json" "github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig" "github.com/devtron-labs/devtron/pkg/deployment/common/bean" ) -func ConvertDeploymentConfigDTOToDbObj(config *bean.DeploymentConfig) *deploymentConfig.DeploymentConfig { +func ConvertDeploymentConfigDTOToDbObj(config *bean.DeploymentConfig) (*deploymentConfig.DeploymentConfig, error) { return &deploymentConfig.DeploymentConfig{ Id: config.Id, AppId: config.AppId, EnvironmentId: config.EnvironmentId, DeploymentAppType: config.DeploymentAppType, ConfigType: config.ConfigType, - RepoUrl: config.RepoURL, Active: config.Active, ReleaseMode: config.ReleaseMode, - } + ReleaseConfig: string(config.ReleaseConfiguration.JSON()), + }, nil } -func ConvertDeploymentConfigDbObjToDTO(dbObj *deploymentConfig.DeploymentConfig) *bean.DeploymentConfig { - return &bean.DeploymentConfig{ - Id: dbObj.Id, - AppId: dbObj.AppId, - EnvironmentId: dbObj.EnvironmentId, - DeploymentAppType: dbObj.DeploymentAppType, - ConfigType: dbObj.ConfigType, - RepoURL: dbObj.RepoUrl, - Active: dbObj.Active, - ReleaseMode: dbObj.ReleaseMode, +func ConvertDeploymentConfigDbObjToDTO(dbObj *deploymentConfig.DeploymentConfig) (*bean.DeploymentConfig, error) { + + var releaseConfig bean.ReleaseConfiguration + err := json.Unmarshal([]byte(dbObj.ReleaseConfig), &releaseConfig) + if err != nil { + return nil, err } + + return &bean.DeploymentConfig{ + Id: dbObj.Id, + AppId: dbObj.AppId, + EnvironmentId: dbObj.EnvironmentId, + DeploymentAppType: dbObj.DeploymentAppType, + ConfigType: dbObj.ConfigType, + Active: dbObj.Active, + ReleaseMode: dbObj.ReleaseMode, + RepoURL: dbObj.RepoUrl, + ReleaseConfiguration: &releaseConfig, + }, nil } diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index e057c24998..4f99f71726 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -1,21 +1,68 @@ package bean import ( + "encoding/json" "fmt" + "log" "strconv" "strings" ) +type Destination struct { + Namespace string `json:"namespace,omitempty"` + Server string `json:"server,omitempty"` +} + +type Source struct { + RepoURL string `json:"repoURL,omitempty"` + ChartPath string `json:"chartPath,omitempty"` + ValuesFilePath string `json:"valuesFilePath,omitempty"` + TargetRevision string `json:"targetRevision,omitempty"` //target branch +} + +type SyncPolicy struct { + SyncPolicy string `json:"syncPolicy,omitempty"` +} + +type ArgoCDSpec struct { + ClusterId int `json:"clusterId,omitempty"` + Namespace string `json:"namespace,omitempty"` + Destination *Destination `json:"destination,omitempty"` + Source *Source `json:"source,omitempty"` + SyncPolicy *SyncPolicy `json:"syncPolicy,omitempty"` +} + +type ReleaseConfiguration struct { + ArgoCDSpec ArgoCDSpec `json:"argoCDSpec"` +} + +func (r *ReleaseConfiguration) JSON() []byte { + releaseConfigJson, err := json.Marshal(r) + if err != nil { + log.Print("error in marshaling releaseConfiguration", "err") + return nil + } + return releaseConfigJson +} + type DeploymentConfig struct { - Id int - AppId int - EnvironmentId int - ConfigType string - DeploymentAppType string - RepoURL string - RepoName string - ReleaseMode string - Active bool + Id int + AppId int + EnvironmentId int + ConfigType string + DeploymentAppType string + ReleaseMode string + RepoURL string // DEPRECATED; + Active bool + ReleaseConfiguration *ReleaseConfiguration +} + +func (c *DeploymentConfig) GetRepoURL() string { + return c.ReleaseConfiguration.ArgoCDSpec.Source.RepoURL +} + +func (c *DeploymentConfig) SetRepoURL(repoURL string) { + c.ReleaseConfiguration.ArgoCDSpec.Source.RepoURL = repoURL } type UniqueDeploymentConfigIdentifier string diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index 86b8ddcc10..cf6362bb2f 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -1,8 +1,11 @@ package common import ( + "errors" "fmt" + "github.com/devtron-labs/common-lib/utils/k8s/commonBean" "github.com/devtron-labs/devtron/api/bean/gitOps" + "github.com/devtron-labs/devtron/client/argocdServer" appRepository "github.com/devtron-labs/devtron/internal/sql/repository/app" "github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" @@ -10,7 +13,12 @@ import ( installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read" bean3 "github.com/devtron-labs/devtron/pkg/auth/user/bean" chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" + bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean" + bean4 "github.com/devtron-labs/devtron/pkg/cluster/environment/bean" + "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" + "github.com/devtron-labs/devtron/pkg/commonService" "github.com/devtron-labs/devtron/pkg/deployment/common/bean" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/util" "github.com/go-pg/pg" "go.uber.org/zap" @@ -18,13 +26,11 @@ import ( type DeploymentConfigService interface { CreateOrUpdateConfig(tx *pg.Tx, config *bean.DeploymentConfig, userId int32) (*bean.DeploymentConfig, error) - IsDeploymentConfigUsed() bool GetConfigForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) GetAndMigrateConfigIfAbsentForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) GetConfigForHelmApps(appId, envId int) (*bean.DeploymentConfig, error) GetConfigEvenIfInactive(appId, envId int) (*bean.DeploymentConfig, error) GetAndMigrateConfigIfAbsentForHelmApp(appId, envId int) (*bean.DeploymentConfig, error) - GetAppLevelConfigForDevtronApp(appId int) (*bean.DeploymentConfig, error) UpdateRepoUrlForAppAndEnvId(repoURL string, appId, envId int) error GetDeploymentAppTypeForCDInBulk(pipelines []*pipelineConfig.Pipeline) (map[int]string, error) } @@ -37,6 +43,9 @@ type DeploymentConfigServiceImpl struct { appRepository appRepository.AppRepository installedAppReadService installedAppReader.InstalledAppReadServiceEA deploymentServiceTypeConfig *util.DeploymentServiceTypeConfig + EnvConfigOverrideService read.EnvConfigOverrideService + CommonService commonService.CommonService + environmentRepository repository.EnvironmentRepository } func NewDeploymentConfigServiceImpl( @@ -47,7 +56,11 @@ func NewDeploymentConfigServiceImpl( appRepository appRepository.AppRepository, installedAppReadService installedAppReader.InstalledAppReadServiceEA, envVariables *util.EnvironmentVariables, + EnvConfigOverrideService read.EnvConfigOverrideService, + CommonService commonService.CommonService, + environmentRepository repository.EnvironmentRepository, ) *DeploymentConfigServiceImpl { + return &DeploymentConfigServiceImpl{ deploymentConfigRepository: deploymentConfigRepository, logger: logger, @@ -56,6 +69,9 @@ func NewDeploymentConfigServiceImpl( appRepository: appRepository, installedAppReadService: installedAppReadService, deploymentServiceTypeConfig: envVariables.DeploymentServiceTypeConfig, + EnvConfigOverrideService: EnvConfigOverrideService, + CommonService: CommonService, + environmentRepository: environmentRepository, } } @@ -67,9 +83,13 @@ func (impl *DeploymentConfigServiceImpl) CreateOrUpdateConfig(tx *pg.Tx, config "appId", config.AppId, "envId", config.EnvironmentId, "err", err) } - newDBObj := ConvertDeploymentConfigDTOToDbObj(config) + newDBObj, err := ConvertDeploymentConfigDTOToDbObj(config) + if err != nil { + impl.logger.Errorw("error in converting deployment config DTO to db object", "appId", config.AppId, "envId", config.EnvironmentId) + return nil, err + } - if configDbObj == nil || (configDbObj != nil && configDbObj.Id == 0) { + if configDbObj == nil || configDbObj.Id == 0 { newDBObj.AuditLog.CreateAuditLog(userId) newDBObj, err = impl.deploymentConfigRepository.Save(tx, newDBObj) if err != nil { @@ -86,206 +106,310 @@ func (impl *DeploymentConfigServiceImpl) CreateOrUpdateConfig(tx *pg.Tx, config return nil, err } } - - return ConvertDeploymentConfigDbObjToDTO(newDBObj), nil -} - -func (impl *DeploymentConfigServiceImpl) IsDeploymentConfigUsed() bool { - return impl.deploymentServiceTypeConfig.UseDeploymentConfigData + newObj, err := ConvertDeploymentConfigDbObjToDTO(newDBObj) + if err != nil { + impl.logger.Errorw("error in converting deployment config DTO to db object", "appId", config.AppId, "envId", config.EnvironmentId) + return nil, err + } + return newObj, nil } func (impl *DeploymentConfigServiceImpl) GetConfigForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) { - if !impl.deploymentServiceTypeConfig.UseDeploymentConfigData { - configFromOldData, err := impl.parseFromOldTablesForDevtronApps(appId, envId) + appLevelConfig, err := impl.getAppLevelConfigForDevtronApps(appId, envId, false) + if err != nil { + impl.logger.Errorw("error in getting app level Config for devtron apps", "appId", appId, "envId", envId, "err", err) + return nil, err + } + + if envId > 0 { + // if envId>0 then only env level config will be returned, + //for getting app level config envId should be zero + appAndEnvLevelConfig, err := impl.getEnvLevelDataForDevtronApps(appId, envId, appLevelConfig, false) if err != nil { - impl.logger.Errorw("error in parsing config from charts and pipeline repository", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in getting env level data for devtron apps", "appId", appId, "envId", envId, "err", err) return nil, err } - if envId > 0 { - // add columns added after migration (of deployment app type and repo url) here - appAndEnvLevelConfig, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting deployment config db object by appId and envId", "appId", appId, "envId", envId, "err", err) - return nil, err - } - if err == pg.ErrNoRows { - // deployment config is not done - configFromOldData.ReleaseMode = util2.PIPELINE_RELEASE_MODE_CREATE - } else { - configFromOldData.ReleaseMode = appAndEnvLevelConfig.ReleaseMode - } + + appAndEnvLevelConfig, err = impl.ConfigureEnvURLByAppURLIfNotConfigured(appAndEnvLevelConfig, appLevelConfig.GetRepoURL(), false) + if err != nil { + impl.logger.Errorw("error in configuring env level url with app url", "appId", appId, "envId", envId, "err", err) + return nil, err } - return configFromOldData, nil - } - // if USE_DEPLOYMENT_CONFIG_DATA is true, first try to fetch data from deployment_config table and if not found use charts and pipeline respectively + return appAndEnvLevelConfig, nil + } + return appLevelConfig, nil +} +func (impl *DeploymentConfigServiceImpl) getAppLevelConfigForDevtronApps(appId int, envId int, migrateDataIfAbsent bool) (*bean.DeploymentConfig, error) { + var appLevelConfig *bean.DeploymentConfig appLevelConfigDbObj, err := impl.deploymentConfigRepository.GetAppLevelConfigForDevtronApps(appId) - if err != nil && err != pg.ErrNoRows { + if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in getting deployment config db object by appId", "appId", appId, "err", err) return nil, err - } - if err == pg.ErrNoRows { - appLevelConfigDbObj, err = impl.parseAppLevelConfigForDevtronApps(appId) + } else if errors.Is(err, pg.ErrNoRows) { + appLevelConfig, err = impl.parseAppLevelMigrationDataForDevtronApps(appId) if err != nil { impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) return nil, err } - } - if envId > 0 { - // if envId>0 then only env level config will be returned, for getting app level config envId should be zero - appAndEnvLevelConfig, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting deployment config db object by appId and envId", "appId", appId, "envId", envId, "err", err) - return nil, err - } - if err == pg.ErrNoRows { - appAndEnvLevelConfig, err = impl.parseEnvLevelConfigForDevtronApps(appLevelConfigDbObj, appId, envId) + if migrateDataIfAbsent { + _, err := impl.CreateOrUpdateConfig(nil, appLevelConfig, bean3.SYSTEM_USER_ID) if err != nil { impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) return nil, err } - } else if gitOps.IsGitOpsRepoNotConfigured(appAndEnvLevelConfig.RepoUrl) && gitOps.IsGitOpsRepoConfigured(appLevelConfigDbObj.RepoUrl) { - // if url is present at app level and not at env level then copy app level url to env level config - appAndEnvLevelConfig.RepoUrl = appLevelConfigDbObj.RepoUrl } + } else { + appLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj) + if err != nil { + impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) + return nil, err + } + if appLevelConfig.ReleaseConfiguration == nil { + releaseConfig, err := impl.parseAppLevelReleaseConfigForDevtronApp(appId, appLevelConfig) + if err != nil { + impl.logger.Errorw("error in parsing release configuration for app", "appId", appId, "err", err) + return nil, err + } + appLevelConfig.ReleaseConfiguration = releaseConfig + + if migrateDataIfAbsent { + _, err := impl.CreateOrUpdateConfig(nil, appLevelConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) + return nil, err + } + } - return ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfig), nil + } } - return ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj), nil + return appLevelConfig, nil } -func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) { +func (impl *DeploymentConfigServiceImpl) parseAppLevelReleaseConfigForDevtronApp(appId int, appLevelConfig *bean.DeploymentConfig) (*bean.ReleaseConfiguration, error) { - appLevelConfigDbObj, err := impl.deploymentConfigRepository.GetAppLevelConfigForDevtronApps(appId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting deployment config db object by appId", "appId", appId, "err", err) + chart, err := impl.chartRepository.FindLatestChartForAppByAppId(appId) + if err != nil { return nil, err } - if err == pg.ErrNoRows { - impl.logger.Infow("app level deployment config not found, migrating data from charts to deployment_config", "appId", appId, "err", err) - appLevelConfigDbObj, err = impl.migrateChartsDataToDeploymentConfig(appId) - if err != nil { - impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) - return nil, err - } + + repoURL := chart.GitRepoUrl + if impl.deploymentServiceTypeConfig.UseDeploymentConfigData { + repoURL = appLevelConfig.RepoURL } - var envLevelConfig *bean.DeploymentConfig - if envId > 0 { - appAndEnvLevelConfig, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting deployment config db object by appId and envId", "appId", appId, "envId", envId, "err", err) + + releaseConfig := newAppLevelReleaseConfigFromChart(repoURL, chart.ChartLocation) + return releaseConfig, nil +} + +func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, envId int, appLevelConfig *bean.DeploymentConfig, migrateDataIfAbsent bool) (*bean.DeploymentConfig, error) { + var appAndEnvLevelConfig *bean.DeploymentConfig + appAndEnvLevelConfigDBObj, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) + if err != nil && !errors.Is(err, pg.ErrNoRows) { + impl.logger.Errorw("error in getting deployment config db object by appId and envId", "appId", appId, "envId", envId, "err", err) + return nil, err + } else if errors.Is(err, pg.ErrNoRows) { + appAndEnvLevelConfig, err = impl.parseEnvLevelMigrationDataForDevtronApps(appLevelConfig, appId, envId) + if err != nil { + impl.logger.Errorw("error in parsing env level config to deployment config", "appId", appId, "envId", envId, "err", err) return nil, err } - if err == pg.ErrNoRows { - impl.logger.Infow("env level deployment config not found, migrating data from pipeline to deployment_config", "appId", appId, "envId", envId, "err", err) - appAndEnvLevelConfig, err = impl.migrateDevtronAppsPipelineDataToDeploymentConfig(appLevelConfigDbObj, appId, envId) + if migrateDataIfAbsent { + _, err := impl.CreateOrUpdateConfig(nil, appAndEnvLevelConfig, bean3.SYSTEM_USER_ID) if err != nil { - impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) + impl.logger.Errorw("error in migrating env level config to deployment config", "appId", appId, "envId", envId, "err", err) return nil, err } - } else if gitOps.IsGitOpsRepoNotConfigured(appAndEnvLevelConfig.RepoUrl) && gitOps.IsGitOpsRepoConfigured(appLevelConfigDbObj.RepoUrl) { - // if url is present at app level and not at env level then copy app level url to env level config - // will happen when custom gitOps is enabled and app is cloned. In this case when user configure app level gitOps , env level gitOps will not be updated - appAndEnvLevelConfig.RepoUrl = appLevelConfigDbObj.RepoUrl - appAndEnvLevelConfig.AuditLog.UpdateAuditLog(1) - appAndEnvLevelConfig, err = impl.deploymentConfigRepository.Update(nil, appAndEnvLevelConfig) + } + } else { + appAndEnvLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfigDBObj) + if err != nil { + impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) + return nil, err + } + if appAndEnvLevelConfig.ReleaseConfiguration == nil { + releaseConfig, err := impl.parseEnvLevelReleaseConfigForDevtronApp(appAndEnvLevelConfig, appId, envId) if err != nil { - impl.logger.Errorw("error in updating deploymentConfig", "appId", appAndEnvLevelConfig.AppId, "envId", appAndEnvLevelConfig.EnvironmentId, "err", err) + impl.logger.Errorw("error in parsing env level release config", "appId", appId, "envId", envId, "err", err) return nil, err } + appAndEnvLevelConfig.ReleaseConfiguration = releaseConfig + if migrateDataIfAbsent { + _, err := impl.CreateOrUpdateConfig(nil, appAndEnvLevelConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) + return nil, err + } + } } - envLevelConfig = ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfig) + } + return appAndEnvLevelConfig, nil +} + +func (impl *DeploymentConfigServiceImpl) ConfigureEnvURLByAppURLIfNotConfigured(appAndEnvLevelConfig *bean.DeploymentConfig, appLevelURL string, migrateDataIfAbsent bool) (*bean.DeploymentConfig, error) { + + /* + if custom gitOps is configured in repo + and app is cloned then cloned pipelines repo URL=NOT_CONFIGURED . + In this case User manually configures repoURL. The configured repo_url is saved in app level config but is absent + in env level config. + */ + + if gitOps.IsGitOpsRepoNotConfigured(appAndEnvLevelConfig.GetRepoURL()) && + gitOps.IsGitOpsRepoConfigured(appLevelURL) { + // if url is present at app level and not at env level then copy app level url to env level config + appAndEnvLevelConfig.SetRepoURL(appAndEnvLevelConfig.GetRepoURL()) } - if !impl.deploymentServiceTypeConfig.UseDeploymentConfigData { - configFromOldData, err := impl.parseFromOldTablesForDevtronApps(appId, envId) + if migrateDataIfAbsent { + _, err := impl.CreateOrUpdateConfig(nil, appAndEnvLevelConfig, bean3.SYSTEM_USER_ID) if err != nil { - impl.logger.Errorw("error in parsing config from charts and pipeline repository", "appId", appId, "envId", envId, "err", err) return nil, err } - if envId > 0 { - configFromOldData.ReleaseMode = envLevelConfig.ReleaseMode - } - return configFromOldData, nil - } - - if envId > 0 { - return envLevelConfig, nil } - return ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj), nil + return appAndEnvLevelConfig, nil } -func (impl *DeploymentConfigServiceImpl) migrateChartsDataToDeploymentConfig(appId int) (*deploymentConfig.DeploymentConfig, error) { +func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) { - configDbObj, err := impl.parseAppLevelConfigForDevtronApps(appId) + appLevelConfig, err := impl.getAppLevelConfigForDevtronApps(appId, envId, true) if err != nil { - impl.logger.Errorw("error in parsing charts data for devtron apps", "appId", appId, "err", err) + impl.logger.Errorw("error in getting app level Config for devtron apps", "appId", appId, "envId", envId, "err", err) return nil, err } - configDbObj.AuditLog.CreateAuditLog(1) - configDbObj, err = impl.deploymentConfigRepository.Save(nil, configDbObj) - if err != nil { - impl.logger.Errorw("error in saving deployment config in DB", "appId", appId, "err", err) - return nil, err + + var envLevelConfig *bean.DeploymentConfig + if envId > 0 { + envLevelConfig, err = impl.getEnvLevelDataForDevtronApps(appId, envId, appLevelConfig, true) + if err != nil { + impl.logger.Errorw("error in getting env level data for devtron apps", "appId", appId, "envId", envId, "err", err) + return nil, err + } + envLevelConfig, err = impl.ConfigureEnvURLByAppURLIfNotConfigured(envLevelConfig, appLevelConfig.GetRepoURL(), true) + if err != nil { + impl.logger.Errorw("error in getting env level data for devtron apps", "appId", appId, "envId", envId, "err", err) + return nil, err + } } - return configDbObj, nil + + return envLevelConfig, nil +} + +func newAppLevelReleaseConfigFromChart(gitRepoURL, chartLocation string) *bean.ReleaseConfiguration { + return &bean.ReleaseConfiguration{ + ArgoCDSpec: bean.ArgoCDSpec{ + Source: &bean.Source{ + RepoURL: gitRepoURL, + ChartPath: chartLocation, + }, + }} } -func (impl *DeploymentConfigServiceImpl) parseAppLevelConfigForDevtronApps(appId int) (*deploymentConfig.DeploymentConfig, error) { +func (impl *DeploymentConfigServiceImpl) parseAppLevelMigrationDataForDevtronApps(appId int) (*bean.DeploymentConfig, error) { chart, err := impl.chartRepository.FindLatestChartForAppByAppId(appId) if err != nil { - impl.logger.Errorw("error in fetch chart for git repo migration by appId", "appId", appId, "err", err) return nil, err } - ConfigDbObj := &deploymentConfig.DeploymentConfig{ - ConfigType: GetDeploymentConfigType(chart.IsCustomGitRepository), - AppId: appId, - Active: true, - RepoUrl: chart.GitRepoUrl, + releaseConfig := newAppLevelReleaseConfigFromChart(chart.GitRepoUrl, chart.ChartLocation) + config := &bean.DeploymentConfig{ + AppId: appId, + ConfigType: GetDeploymentConfigType(chart.IsCustomGitRepository), + Active: true, + ReleaseConfiguration: releaseConfig, } - return ConfigDbObj, nil + return config, nil } -func (impl *DeploymentConfigServiceImpl) migrateDevtronAppsPipelineDataToDeploymentConfig(appLevelConfig *deploymentConfig.DeploymentConfig, appId int, envId int) (*deploymentConfig.DeploymentConfig, error) { +func (impl *DeploymentConfigServiceImpl) parseEnvLevelMigrationDataForDevtronApps(appLevelConfig *bean.DeploymentConfig, appId, envId int) (*bean.DeploymentConfig, error) { + + /* + We can safely assume that no link argoCD pipeline is created if migration is happening + migration case, default values for below fields will be => + 1) repoUrl => same as app level url + 2) chartLocation => we should fetch active envConfigOverride and use chart path from that + 3) valuesFile => _-values.yaml + 4) branch => master + 5) releaseMode => create + 6) Default ClusterId for application object => 1 + 7) Default Namespace for application object => devtroncd + */ + + config := &bean.DeploymentConfig{ + AppId: appId, + EnvironmentId: envId, + ConfigType: appLevelConfig.ConfigType, + ReleaseMode: util2.PIPELINE_RELEASE_MODE_CREATE, + Active: true, + } - configDbObj, err := impl.parseEnvLevelConfigForDevtronApps(appLevelConfig, appId, envId) + deploymentAppType, err := impl.pipelineRepository.FindDeploymentAppTypeByAppIdAndEnvId(appId, envId) if err != nil { - impl.logger.Errorw("error in parsing config for cd pipeline from appId and envId", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in getting deployment app type by appId and envId", "appId", appId, "envId", envId, "err", err) return nil, err } + config.DeploymentAppType = deploymentAppType - configDbObj.AuditLog.CreateAuditLog(bean3.SYSTEM_USER_ID) - configDbObj, err = impl.deploymentConfigRepository.Save(nil, configDbObj) + releaseConfig, err := impl.parseEnvLevelReleaseConfigForDevtronApp(config, appId, envId) if err != nil { - impl.logger.Errorw("error in saving deployment config in DB", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in parsing env level release config", "appId", appId, "envId", envId, "err", err) return nil, err } + config.ReleaseConfiguration = releaseConfig - return configDbObj, nil + return config, nil } -func (impl *DeploymentConfigServiceImpl) parseEnvLevelConfigForDevtronApps(appLevelConfig *deploymentConfig.DeploymentConfig, appId int, envId int) (*deploymentConfig.DeploymentConfig, error) { +func (impl *DeploymentConfigServiceImpl) parseEnvLevelReleaseConfigForDevtronApp(config *bean.DeploymentConfig, appId int, envId int) (*bean.ReleaseConfiguration, error) { + var releaseConfig *bean.ReleaseConfiguration + if config.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD { + envOverride, err := impl.EnvConfigOverrideService.ActiveEnvConfigOverride(appId, envId) + if err != nil { + return nil, err + } - configDbObj := &deploymentConfig.DeploymentConfig{ - AppId: appId, - EnvironmentId: envId, - ConfigType: appLevelConfig.ConfigType, - RepoUrl: appLevelConfig.RepoUrl, - ReleaseMode: util2.PIPELINE_RELEASE_MODE_CREATE, //for migration it is always equal to create as migration is happening for old cd pipelines - Active: true, - } + var latestChart *chartRepoRepository.Chart + if (envOverride.Id == 0) || (envOverride.Id > 0 && !envOverride.IsOverride) { + latestChart, err = impl.chartRepository.FindLatestChartForAppByAppId(appId) + if err != nil { + return nil, err + } + } else { + //if chart is overrides in env, it means it may have different version than app level. + latestChart = envOverride.Chart + } - deploymentAppType, err := impl.pipelineRepository.FindDeploymentAppTypeByAppIdAndEnvId(appId, envId) - if err != nil { - impl.logger.Errorw("error in getting deployment app type by appId and envId", "appId", appId, "envId", envId, "err", err) - return nil, err - } - configDbObj.DeploymentAppType = deploymentAppType + env, err := impl.environmentRepository.FindById(envId) + if err != nil { + impl.logger.Errorw("error in finding environment by id", "envId", envId, "err", err) + return nil, err + } - return configDbObj, nil + gitRepoUrl := latestChart.GitRepoUrl + if len(config.RepoURL) > 0 { + gitRepoUrl = config.RepoURL + } + releaseConfig = &bean.ReleaseConfiguration{ + ArgoCDSpec: bean.ArgoCDSpec{ + ClusterId: bean2.DefaultClusterId, + Namespace: argocdServer.DevtronInstalationNs, + Destination: &bean.Destination{ + Namespace: env.Namespace, + Server: commonBean.DefaultClusterUrl, + }, + Source: &bean.Source{ + RepoURL: gitRepoUrl, + ChartPath: latestChart.ChartLocation, + ValuesFilePath: fmt.Sprintf("_%d-values.yaml", env.Namespace), + TargetRevision: "master", + }, + }, + } + config.ReleaseConfiguration = releaseConfig + } + return releaseConfig, nil } func (impl *DeploymentConfigServiceImpl) GetConfigDBObj(appId, envId int) (*deploymentConfig.DeploymentConfig, error) { @@ -308,87 +432,82 @@ func (impl *DeploymentConfigServiceImpl) GetConfigDBObj(appId, envId int) (*depl } func (impl *DeploymentConfigServiceImpl) GetConfigForHelmApps(appId, envId int) (*bean.DeploymentConfig, error) { - - if !impl.deploymentServiceTypeConfig.UseDeploymentConfigData { - configFromOldData, err := impl.parseConfigForHelmApps(appId, envId) - if err != nil { - impl.logger.Errorw("error in parsing config from charts and pipeline repository", "appId", appId, "envId", envId, "err", err) - return nil, err - } - return ConvertDeploymentConfigDbObjToDTO(configFromOldData), nil - } - - helmDeploymentConfig, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in fetching deployment config by by appId and envId", "appId", appId, "envId", envId, "err", err) - return nil, err - } - - if err == pg.ErrNoRows { - helmDeploymentConfig, err = impl.parseConfigForHelmApps(appId, envId) - if err != nil { - impl.logger.Errorw("error in migrating helm deployment config", "appId", appId, "envId", envId, "err", err) - return nil, err - } - } - return ConvertDeploymentConfigDbObjToDTO(helmDeploymentConfig), nil -} - -func (impl *DeploymentConfigServiceImpl) GetConfigEvenIfInactive(appId, envId int) (*bean.DeploymentConfig, error) { - config, err := impl.deploymentConfigRepository.GetByAppIdAndEnvIdEvenIfInactive(appId, envId) + helmDeploymentConfig, err := impl.getConfigForHelmApps(appId, envId, false) if err != nil { - impl.logger.Errorw("error in getting deployment config by appId and envId", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in getting deployment config for helm app", "appId", appId, "envId", envId, "err", err) return nil, err } - return ConvertDeploymentConfigDbObjToDTO(config), nil + return helmDeploymentConfig, nil } -func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForHelmApp(appId, envId int) (*bean.DeploymentConfig, error) { - - helmDeploymentConfig, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) - if err != nil && err != pg.ErrNoRows { +func (impl *DeploymentConfigServiceImpl) getConfigForHelmApps(appId int, envId int, migrateIfAbsent bool) (*bean.DeploymentConfig, error) { + var helmDeploymentConfig *bean.DeploymentConfig + config, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) + if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in fetching deployment config by by appId and envId", "appId", appId, "envId", envId, "err", err) return nil, err - } - - if err == pg.ErrNoRows { - helmDeploymentConfig, err = impl.migrateHelmAppDataToDeploymentConfig(appId, envId) + } else if errors.Is(err, pg.ErrNoRows) { + helmDeploymentConfig, err = impl.parseDeploymentConfigForHelmApps(appId, envId) if err != nil { - impl.logger.Errorw("error in migrating helm deployment config", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in parsing helm deployment config", "appId", appId, "envId", envId, "err", err) return nil, err } - } - - if !impl.deploymentServiceTypeConfig.UseDeploymentConfigData { - configFromOldData, err := impl.parseConfigForHelmApps(appId, envId) + if migrateIfAbsent { + _, err = impl.CreateOrUpdateConfig(nil, helmDeploymentConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in creating helm deployment config ", "appId", appId, "envId", envId, "err", err) + return nil, err + } + } + } else { + helmDeploymentConfig, err = ConvertDeploymentConfigDbObjToDTO(config) if err != nil { - impl.logger.Errorw("error in parsing config from charts and pipeline repository", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in converting helm deployment config dbObj to DTO", "appId", appId, "envId", envId, "err", err) return nil, err } - return ConvertDeploymentConfigDbObjToDTO(configFromOldData), nil + if helmDeploymentConfig.ReleaseConfiguration == nil { + releaseConfig, err := impl.parseReleaseConfigForHelmApps(appId, envId, helmDeploymentConfig) + if err != nil { + impl.logger.Errorw("error in parsing release config", "appId", appId, "envId", envId, "err", err) + return nil, err + } + helmDeploymentConfig.ReleaseConfiguration = releaseConfig + if migrateIfAbsent { + _, err = impl.CreateOrUpdateConfig(nil, helmDeploymentConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in creating helm deployment config ", "appId", appId, "envId", envId, "err", err) + return nil, err + } + } + } } - - return ConvertDeploymentConfigDbObjToDTO(helmDeploymentConfig), nil + return helmDeploymentConfig, err } -func (impl *DeploymentConfigServiceImpl) migrateHelmAppDataToDeploymentConfig(appId, envId int) (*deploymentConfig.DeploymentConfig, error) { - - helmDeploymentConfig, err := impl.parseConfigForHelmApps(appId, envId) +func (impl *DeploymentConfigServiceImpl) GetConfigEvenIfInactive(appId, envId int) (*bean.DeploymentConfig, error) { + dbConfig, err := impl.deploymentConfigRepository.GetByAppIdAndEnvIdEvenIfInactive(appId, envId) if err != nil { - impl.logger.Errorw("error in parsing deployment config for helm app", "appId", appId, "envId", envId, "err", err) - return helmDeploymentConfig, err + impl.logger.Errorw("error in getting deployment config by appId and envId", "appId", appId, "envId", envId, "err", err) + return nil, err + } + config, err := ConvertDeploymentConfigDbObjToDTO(dbConfig) + if err != nil { + impl.logger.Errorw("error in converting deployment config db obj to dto", "appId", appId, "envId", envId, "err", err) + return nil, err } + return config, nil +} - helmDeploymentConfig.CreateAuditLog(bean3.SYSTEM_USER_ID) - helmDeploymentConfig, err = impl.deploymentConfigRepository.Save(nil, helmDeploymentConfig) +func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForHelmApp(appId, envId int) (*bean.DeploymentConfig, error) { + helmDeploymentConfig, err := impl.getConfigForHelmApps(appId, envId, true) if err != nil { - impl.logger.Errorw("error in saving deployment config for helm app", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in getting deployment config for helm app", "appId", appId, "envId", envId, "err", err) return nil, err } return helmDeploymentConfig, nil } -func (impl *DeploymentConfigServiceImpl) parseConfigForHelmApps(appId int, envId int) (*deploymentConfig.DeploymentConfig, error) { +func (impl *DeploymentConfigServiceImpl) parseDeploymentConfigForHelmApps(appId int, envId int) (*bean.DeploymentConfig, error) { installedApp, err := impl.installedAppReadService.GetInstalledAppsByAppId(appId) if err != nil { impl.logger.Errorw("error in getting installed app by appId", "appId", appId, "err", err) @@ -397,50 +516,66 @@ func (impl *DeploymentConfigServiceImpl) parseConfigForHelmApps(appId int, envId if installedApp.EnvironmentId != envId { return nil, pg.ErrNoRows } - helmDeploymentConfig := &deploymentConfig.DeploymentConfig{ + helmDeploymentConfig := &bean.DeploymentConfig{ AppId: appId, EnvironmentId: envId, DeploymentAppType: installedApp.DeploymentAppType, ConfigType: GetDeploymentConfigType(installedApp.IsCustomRepository), - RepoUrl: installedApp.GitOpsRepoUrl, - RepoName: installedApp.GitOpsRepoName, + RepoURL: installedApp.GitOpsRepoUrl, Active: true, } - return helmDeploymentConfig, nil -} - -func (impl *DeploymentConfigServiceImpl) parseFromOldTablesForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) { - appLevelConfig, err := impl.parseAppLevelConfigForDevtronApps(appId) + releaseConfig, err := impl.parseReleaseConfigForHelmApps(appId, envId, helmDeploymentConfig) if err != nil { - impl.logger.Errorw("error in parsing charts data to deployment config", "appId", appId, "err", err) return nil, err } - if envId > 0 { - appAndEnvLevelConfig, err := impl.parseEnvLevelConfigForDevtronApps(appLevelConfig, appId, envId) + helmDeploymentConfig.ReleaseConfiguration = releaseConfig + return helmDeploymentConfig, nil +} + +func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int, envId int, config *bean.DeploymentConfig) (*bean.ReleaseConfiguration, error) { + var releaseConfig *bean.ReleaseConfiguration + if config.DeploymentAppType == bean4.PIPELINE_DEPLOYMENT_TYPE_ACD { + app, err := impl.appRepository.FindById(appId) if err != nil { - impl.logger.Errorw("error in parsing env level config to deployment config", "appId", appId, "err", err) + impl.logger.Errorw("error in getting app by id", "appId", appId, "err", err) return nil, err } - return ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfig), nil - } - return ConvertDeploymentConfigDbObjToDTO(appLevelConfig), nil -} - -func (impl *DeploymentConfigServiceImpl) GetAppLevelConfigForDevtronApp(appId int) (*bean.DeploymentConfig, error) { - appLevelConfigDbObj, err := impl.deploymentConfigRepository.GetAppLevelConfigForDevtronApps(appId) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in getting deployment config db object by appId", "appId", appId, "err", err) - return nil, err - } - if err == pg.ErrNoRows { - impl.logger.Infow("app level deployment config not found, migrating data from charts to deployment_config", "appId", appId, "err", err) - appLevelConfigDbObj, err = impl.migrateChartsDataToDeploymentConfig(appId) + env, err := impl.environmentRepository.FindById(envId) if err != nil { - impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) + impl.logger.Errorw("error in getting installed app by environmentId", "appId", appId, "envId", envId, "err", err) return nil, err } + + var gitRepoURL string + if len(config.RepoURL) > 0 { + gitRepoURL = config.RepoURL + } else { + installedApp, err := impl.installedAppReadService.GetInstalledAppsByAppId(appId) + if err != nil { + impl.logger.Errorw("error in getting installed app by appId", "appId", appId, "err", err) + return nil, err + } + gitRepoURL = installedApp.GitOpsRepoUrl + } + + releaseConfig = &bean.ReleaseConfiguration{ + ArgoCDSpec: bean.ArgoCDSpec{ + ClusterId: bean2.DefaultClusterId, + Namespace: argocdServer.DevtronInstalationNs, + Destination: &bean.Destination{ + Namespace: env.Namespace, + Server: commonBean.DefaultClusterUrl, + }, + Source: &bean.Source{ + RepoURL: gitRepoURL, + ChartPath: util.BuildDeployedAppName(app.AppName, env.Name), + ValuesFilePath: "values.yaml", + TargetRevision: "master", + }, + }, + } } - return ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj), nil + return releaseConfig, nil } func (impl *DeploymentConfigServiceImpl) UpdateRepoUrlForAppAndEnvId(repoURL string, appId, envId int) error { diff --git a/pkg/pipeline/DeploymentPipelineConfigService.go b/pkg/pipeline/DeploymentPipelineConfigService.go index 43894b9d7b..d40ff86d3f 100644 --- a/pkg/pipeline/DeploymentPipelineConfigService.go +++ b/pkg/pipeline/DeploymentPipelineConfigService.go @@ -467,7 +467,6 @@ func (impl *CdPipelineConfigServiceImpl) CreateCdPipelines(pipelineCreateRequest ConfigType: AppDeploymentConfig.ConfigType, DeploymentAppType: pipeline.DeploymentAppType, RepoURL: AppDeploymentConfig.RepoURL, - RepoName: AppDeploymentConfig.RepoName, ReleaseMode: pipeline.ReleaseMode, Active: true, } diff --git a/wire_gen.go b/wire_gen.go index d356eaa9e7..7fa328d30c 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -510,7 +510,7 @@ func InitializeApp() (*App, error) { pipelineStatusSyncDetailServiceImpl := status.NewPipelineStatusSyncDetailServiceImpl(sugaredLogger, pipelineStatusSyncDetailRepositoryImpl) installedAppVersionHistoryRepositoryImpl := repository3.NewInstalledAppVersionHistoryRepositoryImpl(sugaredLogger, db) repositoryImpl := deploymentConfig.NewRepositoryImpl(db) - deploymentConfigServiceImpl := common.NewDeploymentConfigServiceImpl(repositoryImpl, sugaredLogger, chartRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, installedAppReadServiceEAImpl, environmentVariables) + deploymentConfigServiceImpl := common.NewDeploymentConfigServiceImpl(repositoryImpl, sugaredLogger, chartRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, installedAppReadServiceEAImpl, environmentVariables, envConfigOverrideReadServiceImpl, commonServiceImpl, environmentRepositoryImpl) pipelineStatusTimelineServiceImpl := status.NewPipelineStatusTimelineServiceImpl(sugaredLogger, pipelineStatusTimelineRepositoryImpl, cdWorkflowRepositoryImpl, userServiceImpl, pipelineStatusTimelineResourcesServiceImpl, pipelineStatusSyncDetailServiceImpl, installedAppRepositoryImpl, installedAppVersionHistoryRepositoryImpl, deploymentConfigServiceImpl) appServiceConfig, err := app2.GetAppServiceConfig() if err != nil { From 6864e0781ea9069185057760a1926656b290b899 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Fri, 17 Jan 2025 12:14:22 +0530 Subject: [PATCH 02/16] updating repo url get usage --- cmd/external-app/wire.go | 8 +++ cmd/external-app/wire_gen.go | 18 +++-- pkg/appStore/adapter/Adapter.go | 2 +- .../service/AppStoreDeploymentService.go | 68 ++----------------- .../deployment/InstalledAppGitOpsService.go | 2 +- pkg/chart/ChartService.go | 4 +- .../DevtronAppGitOpsConfigService.go | 2 +- pkg/deployment/common/adapter.go | 1 + pkg/deployment/common/bean/bean.go | 7 ++ .../common/deploymentConfigService.go | 6 +- .../trigger/devtronApps/TriggerService.go | 14 ++-- .../AppDeploymentTypeChangeManager.go | 2 +- .../DeploymentPipelineConfigService.go | 2 +- wire_gen.go | 2 +- 14 files changed, 49 insertions(+), 89 deletions(-) diff --git a/cmd/external-app/wire.go b/cmd/external-app/wire.go index 8c9ad5faec..767f21b59b 100644 --- a/cmd/external-app/wire.go +++ b/cmd/external-app/wire.go @@ -62,6 +62,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository" app2 "github.com/devtron-labs/devtron/internal/sql/repository/app" "github.com/devtron-labs/devtron/internal/sql/repository/appStatus" + "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" "github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig" dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" @@ -76,6 +77,7 @@ import ( delete2 "github.com/devtron-labs/devtron/pkg/delete" "github.com/devtron-labs/devtron/pkg/deployment/common" "github.com/devtron-labs/devtron/pkg/deployment/gitOps" + "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/pkg/deployment/providerConfig" "github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs" repository2 "github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs/repository" @@ -271,6 +273,12 @@ func InitializeApp() (*App, error) { dbMigration.NewDbMigrationServiceImpl, wire.Bind(new(dbMigration.DbMigration), new(*dbMigration.DbMigrationServiceImpl)), + + read.NewEnvConfigOverrideReadServiceImpl, + wire.Bind(new(read.EnvConfigOverrideService), new(*read.EnvConfigOverrideReadServiceImpl)), + + chartConfig.NewEnvConfigOverrideRepository, + wire.Bind(new(chartConfig.EnvConfigOverrideRepository), new(*chartConfig.EnvConfigOverrideRepositoryImpl)), ) return &App{}, nil } diff --git a/cmd/external-app/wire_gen.go b/cmd/external-app/wire_gen.go index c3fb2fd983..b07b00feef 100644 --- a/cmd/external-app/wire_gen.go +++ b/cmd/external-app/wire_gen.go @@ -54,6 +54,7 @@ import ( repository5 "github.com/devtron-labs/devtron/internal/sql/repository" "github.com/devtron-labs/devtron/internal/sql/repository/app" "github.com/devtron-labs/devtron/internal/sql/repository/appStatus" + "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" "github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig" repository7 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" @@ -74,7 +75,7 @@ import ( "github.com/devtron-labs/devtron/pkg/appStore/values/repository" service4 "github.com/devtron-labs/devtron/pkg/appStore/values/service" "github.com/devtron-labs/devtron/pkg/argoApplication" - read6 "github.com/devtron-labs/devtron/pkg/argoApplication/read" + read7 "github.com/devtron-labs/devtron/pkg/argoApplication/read" config3 "github.com/devtron-labs/devtron/pkg/argoApplication/read/config" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/auth/authentication" @@ -82,13 +83,13 @@ import ( "github.com/devtron-labs/devtron/pkg/auth/sso" "github.com/devtron-labs/devtron/pkg/auth/user" "github.com/devtron-labs/devtron/pkg/auth/user/repository" - read7 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read" + read8 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read" repository12 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository" "github.com/devtron-labs/devtron/pkg/chartRepo" "github.com/devtron-labs/devtron/pkg/chartRepo/repository" "github.com/devtron-labs/devtron/pkg/cluster" "github.com/devtron-labs/devtron/pkg/cluster/environment" - read5 "github.com/devtron-labs/devtron/pkg/cluster/environment/read" + read6 "github.com/devtron-labs/devtron/pkg/cluster/environment/read" repository4 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" rbac2 "github.com/devtron-labs/devtron/pkg/cluster/rbac" read2 "github.com/devtron-labs/devtron/pkg/cluster/read" @@ -97,6 +98,7 @@ import ( delete2 "github.com/devtron-labs/devtron/pkg/delete" "github.com/devtron-labs/devtron/pkg/deployment/common" config2 "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" + read5 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/pkg/deployment/providerConfig" "github.com/devtron-labs/devtron/pkg/externalLink" "github.com/devtron-labs/devtron/pkg/fluxApplication" @@ -307,7 +309,9 @@ func InitializeApp() (*App, error) { installedAppVersionHistoryRepositoryImpl := repository6.NewInstalledAppVersionHistoryRepositoryImpl(sugaredLogger, db) repositoryImpl := deploymentConfig.NewRepositoryImpl(db) chartRepositoryImpl := chartRepoRepository.NewChartRepository(db, transactionUtilImpl) - deploymentConfigServiceImpl := common.NewDeploymentConfigServiceImpl(repositoryImpl, sugaredLogger, chartRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, installedAppReadServiceEAImpl, environmentVariables) + envConfigOverrideRepositoryImpl := chartConfig.NewEnvConfigOverrideRepository(db) + envConfigOverrideReadServiceImpl := read5.NewEnvConfigOverrideReadServiceImpl(envConfigOverrideRepositoryImpl, sugaredLogger) + deploymentConfigServiceImpl := common.NewDeploymentConfigServiceImpl(repositoryImpl, sugaredLogger, chartRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, installedAppReadServiceEAImpl, environmentVariables, envConfigOverrideReadServiceImpl, environmentRepositoryImpl) installedAppDBServiceImpl := EAMode.NewInstalledAppDBServiceImpl(sugaredLogger, installedAppRepositoryImpl, appRepositoryImpl, userServiceImpl, environmentServiceImpl, installedAppVersionHistoryRepositoryImpl, deploymentConfigServiceImpl) gitOpsConfigRepositoryImpl := repository5.NewGitOpsConfigRepositoryImpl(sugaredLogger, db) gitOpsConfigReadServiceImpl := config2.NewGitOpsConfigReadServiceImpl(sugaredLogger, gitOpsConfigRepositoryImpl, userServiceImpl, environmentVariables) @@ -340,10 +344,10 @@ func InitializeApp() (*App, error) { argoApplicationServiceImpl := argoApplication.NewArgoApplicationServiceImpl(sugaredLogger, clusterRepositoryImpl, k8sServiceImpl, helmAppClientImpl, helmAppServiceImpl, k8sApplicationServiceImpl, argoApplicationConfigServiceImpl) helmAppRestHandlerImpl := client2.NewHelmAppRestHandlerImpl(sugaredLogger, helmAppServiceImpl, enforcerImpl, clusterServiceImpl, enforcerUtilHelmImpl, appStoreDeploymentServiceImpl, installedAppDBServiceImpl, userServiceImpl, attributesServiceImpl, serverEnvConfigServerEnvConfig, fluxApplicationServiceImpl, argoApplicationServiceImpl) helmAppRouterImpl := client2.NewHelmAppRouterImpl(helmAppRestHandlerImpl) - environmentReadServiceImpl := read5.NewEnvironmentReadServiceImpl(sugaredLogger, environmentRepositoryImpl) + environmentReadServiceImpl := read6.NewEnvironmentReadServiceImpl(sugaredLogger, environmentRepositoryImpl) environmentRestHandlerImpl := cluster2.NewEnvironmentRestHandlerImpl(environmentServiceImpl, environmentReadServiceImpl, sugaredLogger, userServiceImpl, validate, enforcerImpl, deleteServiceImpl, k8sServiceImpl, k8sCommonServiceImpl) environmentRouterImpl := cluster2.NewEnvironmentRouterImpl(environmentRestHandlerImpl) - argoApplicationReadServiceImpl := read6.NewArgoApplicationReadServiceImpl(sugaredLogger, clusterRepositoryImpl, k8sServiceImpl, helmAppClientImpl, helmAppServiceImpl) + argoApplicationReadServiceImpl := read7.NewArgoApplicationReadServiceImpl(sugaredLogger, clusterRepositoryImpl, k8sServiceImpl, helmAppClientImpl, helmAppServiceImpl) k8sApplicationRestHandlerImpl := application2.NewK8sApplicationRestHandlerImpl(sugaredLogger, k8sApplicationServiceImpl, pumpImpl, terminalSessionHandlerImpl, enforcerImpl, enforcerUtilHelmImpl, enforcerUtilImpl, helmAppServiceImpl, userServiceImpl, k8sCommonServiceImpl, validate, environmentVariables, fluxApplicationServiceImpl, argoApplicationReadServiceImpl) k8sApplicationRouterImpl := application2.NewK8sApplicationRouterImpl(k8sApplicationRestHandlerImpl) chartRepositoryRestHandlerImpl := chartRepo2.NewChartRepositoryRestHandlerImpl(sugaredLogger, userServiceImpl, chartRepositoryServiceImpl, enforcerImpl, validate, deleteServiceImpl, attributesServiceImpl) @@ -450,7 +454,7 @@ func InitializeApp() (*App, error) { return nil, err } materialRepositoryImpl := repository12.NewMaterialRepositoryImpl(db) - gitMaterialReadServiceImpl := read7.NewGitMaterialReadServiceImpl(sugaredLogger, materialRepositoryImpl) + gitMaterialReadServiceImpl := read8.NewGitMaterialReadServiceImpl(sugaredLogger, materialRepositoryImpl) appCrudOperationServiceImpl := app2.NewAppCrudOperationServiceImpl(appLabelRepositoryImpl, sugaredLogger, appRepositoryImpl, userRepositoryImpl, installedAppRepositoryImpl, genericNoteServiceImpl, installedAppDBServiceImpl, crudOperationServiceConfig, dbMigrationServiceImpl, gitMaterialReadServiceImpl) appInfoRestHandlerImpl := appInfo.NewAppInfoRestHandlerImpl(sugaredLogger, appCrudOperationServiceImpl, userServiceImpl, validate, enforcerUtilImpl, enforcerImpl, helmAppServiceImpl, enforcerUtilHelmImpl, genericNoteServiceImpl) appInfoRouterImpl := appInfo2.NewAppInfoRouterImpl(sugaredLogger, appInfoRestHandlerImpl) diff --git a/pkg/appStore/adapter/Adapter.go b/pkg/appStore/adapter/Adapter.go index 8c92890eaf..c4fdce362e 100644 --- a/pkg/appStore/adapter/Adapter.go +++ b/pkg/appStore/adapter/Adapter.go @@ -274,7 +274,7 @@ func UpdateInstallAppDetails(request *appStoreBean.InstallAppVersionDTO, install request.Status = installedApp.Status request.DeploymentAppType = config.DeploymentAppType if util.IsAcdApp(config.DeploymentAppType) { - request.GitOpsRepoURL = config.RepoURL + request.GitOpsRepoURL = config.GetRepoURL() } } diff --git a/pkg/appStore/installedApp/service/AppStoreDeploymentService.go b/pkg/appStore/installedApp/service/AppStoreDeploymentService.go index 1c0863644c..17be3ebfca 100644 --- a/pkg/appStore/installedApp/service/AppStoreDeploymentService.go +++ b/pkg/appStore/installedApp/service/AppStoreDeploymentService.go @@ -592,14 +592,14 @@ func (impl *AppStoreDeploymentServiceImpl) updateInstalledApp(ctx context.Contex installedAppDeploymentAction := adapter.NewInstalledAppDeploymentAction(deploymentConfig.DeploymentAppType) // migrate installedApp.GitOpsRepoName to installedApp.GitOpsRepoUrl if util.IsAcdApp(deploymentConfig.DeploymentAppType) && - len(deploymentConfig.RepoURL) == 0 { + len(deploymentConfig.GetRepoURL()) == 0 { gitRepoUrl, err := impl.fullModeDeploymentService.GetAcdAppGitOpsRepoURL(installedApp.App.AppName, installedApp.Environment.Name) if err != nil { impl.logger.Errorw("error in GitOps repository url migration", "err", err) return nil, err } - deploymentConfig.RepoURL = gitRepoUrl - installedApp.GitOpsRepoUrl = gitRepoUrl + deploymentConfig.SetRepoURL(gitRepoUrl) + //installedApp.GitOpsRepoUrl = gitRepoUrl installedApp.GitOpsRepoName = impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(gitRepoUrl) } // migration ends @@ -754,7 +754,7 @@ func (impl *AppStoreDeploymentServiceImpl) updateInstalledApp(ctx context.Contex if monoRepoMigrationRequired { //if monorepo case is true then repoUrl is changed then also update repo url in database installedApp.UpdateGitOpsRepository(gitOpsResponse.ChartGitAttribute.RepoUrl, installedApp.IsCustomRepository) - deploymentConfig.RepoURL = gitOpsResponse.ChartGitAttribute.RepoUrl + deploymentConfig.SetRepoURL(gitOpsResponse.ChartGitAttribute.RepoUrl) } installedApp, err = impl.installedAppRepository.UpdateInstalledApp(installedApp, tx) if err != nil { @@ -998,11 +998,11 @@ func (impl *AppStoreDeploymentServiceImpl) linkHelmApplicationToChartStore(insta // checkIfMonoRepoMigrationRequired checks if gitOps repo name is changed func (impl *AppStoreDeploymentServiceImpl) checkIfMonoRepoMigrationRequired(installedApp *repository.InstalledApps, deploymentConfig *bean5.DeploymentConfig) bool { monoRepoMigrationRequired := false - if !util.IsAcdApp(deploymentConfig.DeploymentAppType) || gitOps.IsGitOpsRepoNotConfigured(deploymentConfig.RepoURL) || deploymentConfig.ConfigType == bean5.CUSTOM.String() { + if !util.IsAcdApp(deploymentConfig.DeploymentAppType) || gitOps.IsGitOpsRepoNotConfigured(deploymentConfig.GetRepoURL()) || deploymentConfig.ConfigType == bean5.CUSTOM.String() { return false } var err error - gitOpsRepoName := impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(deploymentConfig.RepoURL) + gitOpsRepoName := impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(deploymentConfig.GetRepoURL()) if len(gitOpsRepoName) == 0 { gitOpsRepoName, err = impl.fullModeDeploymentService.GetAcdAppGitOpsRepoName(installedApp.App.AppName, installedApp.Environment.Name) if err != nil || gitOpsRepoName == "" { @@ -1019,62 +1019,6 @@ func (impl *AppStoreDeploymentServiceImpl) checkIfMonoRepoMigrationRequired(inst return monoRepoMigrationRequired } -// handleGitOpsRepoUrlMigration will migrate git_ops_repo_name to git_ops_repo_url -func (impl *AppStoreDeploymentServiceImpl) handleGitOpsRepoUrlMigration(tx *pg.Tx, installedApp *repository.InstalledApps, deploymentConfig *bean5.DeploymentConfig, userId int32) error { - var ( - localTx *pg.Tx - err error - ) - - if tx == nil { - dbConnection := impl.installedAppRepository.GetConnection() - localTx, err = dbConnection.Begin() - if err != nil { - return err - } - // Rollback tx on error. - defer localTx.Rollback() - } - - gitRepoUrl, err := impl.fullModeDeploymentService.GetGitRepoUrl(installedApp.GitOpsRepoName) - if err != nil { - impl.logger.Errorw("error in GitOps repository url migration", "err", err) - return err - } - installedApp.GitOpsRepoUrl = gitRepoUrl - installedApp.UpdatedOn = time.Now() - installedApp.UpdatedBy = userId - - var dbTx *pg.Tx - if localTx != nil { - dbTx = localTx - } else { - dbTx = tx - } - - _, err = impl.installedAppRepository.UpdateInstalledApp(installedApp, dbTx) - if err != nil { - impl.logger.Errorw("error in updating installed app model", "err", err) - return err - } - - deploymentConfig.RepoURL = gitRepoUrl - deploymentConfig, err = impl.deploymentConfigService.CreateOrUpdateConfig(dbTx, deploymentConfig, userId) - if err != nil { - impl.logger.Errorw("error in updating deployment config", "err", err) - return err - } - - if localTx != nil { - err = localTx.Commit() - if err != nil { - impl.logger.Errorw("error while committing transaction to db", "error", err) - return err - } - } - return err -} - // getAppNameForInstalledApp will fetch and returns AppName from app table func (impl *AppStoreDeploymentServiceImpl) getAppNameForInstalledApp(installedAppId int) string { installedApp, err := impl.installedAppRepository.GetInstalledApp(installedAppId) diff --git a/pkg/appStore/installedApp/service/FullMode/deployment/InstalledAppGitOpsService.go b/pkg/appStore/installedApp/service/FullMode/deployment/InstalledAppGitOpsService.go index f960a44760..6386e6a9de 100644 --- a/pkg/appStore/installedApp/service/FullMode/deployment/InstalledAppGitOpsService.go +++ b/pkg/appStore/installedApp/service/FullMode/deployment/InstalledAppGitOpsService.go @@ -332,7 +332,7 @@ func (impl *FullModeDeploymentServiceImpl) getGitCommitConfig(installAppVersionR return nil, apiErr } //installAppVersionRequest.GitOpsRepoURL = InstalledApp.GitOpsRepoUrl - installAppVersionRequest.GitOpsRepoURL = deploymentConfig.RepoURL + installAppVersionRequest.GitOpsRepoURL = deploymentConfig.GetRepoURL() } gitOpsRepoName := impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(installAppVersionRequest.GitOpsRepoURL) userEmailId, userName := impl.gitOpsConfigReadService.GetUserEmailIdAndNameForGitOpsCommit(installAppVersionRequest.UserId) diff --git a/pkg/chart/ChartService.go b/pkg/chart/ChartService.go index 74db49eefb..5e44e90fee 100644 --- a/pkg/chart/ChartService.go +++ b/pkg/chart/ChartService.go @@ -464,8 +464,8 @@ func (impl *ChartServiceImpl) chartAdaptor(chart *chartRepoRepository.Chart, isA return &TemplateRequest{}, &util.ApiError{UserMessage: "no chart found"} } gitRepoUrl := "" - if !apiGitOpsBean.IsGitOpsRepoNotConfigured(deploymentConfig.RepoURL) { - gitRepoUrl = deploymentConfig.RepoURL + if !apiGitOpsBean.IsGitOpsRepoNotConfigured(deploymentConfig.GetRepoURL()) { + gitRepoUrl = deploymentConfig.GetRepoURL() } templateRequest := &TemplateRequest{ RefChartTemplate: chart.ReferenceTemplate, diff --git a/pkg/chart/gitOpsConfig/DevtronAppGitOpsConfigService.go b/pkg/chart/gitOpsConfig/DevtronAppGitOpsConfigService.go index d85e99bf69..c9b309c3db 100644 --- a/pkg/chart/gitOpsConfig/DevtronAppGitOpsConfigService.go +++ b/pkg/chart/gitOpsConfig/DevtronAppGitOpsConfigService.go @@ -201,5 +201,5 @@ func (impl *DevtronAppGitOpConfigServiceImpl) isGitRepoUrlPresent(appId int) boo impl.logger.Errorw("error fetching git repo url from deploymentConfig for latest chart") return false } - return !apiGitOpsBean.IsGitOpsRepoNotConfigured(deploymentConfig.RepoURL) + return !apiGitOpsBean.IsGitOpsRepoNotConfigured(deploymentConfig.GetRepoURL()) } diff --git a/pkg/deployment/common/adapter.go b/pkg/deployment/common/adapter.go index 34f29ca03e..9908f3d53b 100644 --- a/pkg/deployment/common/adapter.go +++ b/pkg/deployment/common/adapter.go @@ -12,6 +12,7 @@ func ConvertDeploymentConfigDTOToDbObj(config *bean.DeploymentConfig) (*deployme AppId: config.AppId, EnvironmentId: config.EnvironmentId, DeploymentAppType: config.DeploymentAppType, + RepoUrl: config.RepoURL, ConfigType: config.ConfigType, Active: config.Active, ReleaseMode: config.ReleaseMode, diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index 4f99f71726..17e88564e5 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -37,6 +37,9 @@ type ReleaseConfiguration struct { } func (r *ReleaseConfiguration) JSON() []byte { + if r == nil { + return nil + } releaseConfigJson, err := json.Marshal(r) if err != nil { log.Print("error in marshaling releaseConfiguration", "err") @@ -61,6 +64,10 @@ func (c *DeploymentConfig) GetRepoURL() string { return c.ReleaseConfiguration.ArgoCDSpec.Source.RepoURL } +func (c *DeploymentConfig) GetChartLocation() string { + return c.ReleaseConfiguration.ArgoCDSpec.Source.ChartPath +} + func (c *DeploymentConfig) SetRepoURL(repoURL string) { c.ReleaseConfiguration.ArgoCDSpec.Source.RepoURL = repoURL } diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index cf6362bb2f..1b314d86ff 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -16,7 +16,6 @@ import ( bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean" bean4 "github.com/devtron-labs/devtron/pkg/cluster/environment/bean" "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" - "github.com/devtron-labs/devtron/pkg/commonService" "github.com/devtron-labs/devtron/pkg/deployment/common/bean" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/util" @@ -44,7 +43,6 @@ type DeploymentConfigServiceImpl struct { installedAppReadService installedAppReader.InstalledAppReadServiceEA deploymentServiceTypeConfig *util.DeploymentServiceTypeConfig EnvConfigOverrideService read.EnvConfigOverrideService - CommonService commonService.CommonService environmentRepository repository.EnvironmentRepository } @@ -57,7 +55,6 @@ func NewDeploymentConfigServiceImpl( installedAppReadService installedAppReader.InstalledAppReadServiceEA, envVariables *util.EnvironmentVariables, EnvConfigOverrideService read.EnvConfigOverrideService, - CommonService commonService.CommonService, environmentRepository repository.EnvironmentRepository, ) *DeploymentConfigServiceImpl { @@ -70,7 +67,6 @@ func NewDeploymentConfigServiceImpl( installedAppReadService: installedAppReadService, deploymentServiceTypeConfig: envVariables.DeploymentServiceTypeConfig, EnvConfigOverrideService: EnvConfigOverrideService, - CommonService: CommonService, environmentRepository: environmentRepository, } } @@ -78,7 +74,7 @@ func NewDeploymentConfigServiceImpl( func (impl *DeploymentConfigServiceImpl) CreateOrUpdateConfig(tx *pg.Tx, config *bean.DeploymentConfig, userId int32) (*bean.DeploymentConfig, error) { configDbObj, err := impl.GetConfigDBObj(config.AppId, config.EnvironmentId) - if err != nil && err != pg.ErrNoRows { + if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in fetching deployment config from DB by appId and envId", "appId", config.AppId, "envId", config.EnvironmentId, "err", err) } diff --git a/pkg/deployment/trigger/devtronApps/TriggerService.go b/pkg/deployment/trigger/devtronApps/TriggerService.go index faf30adb53..b52385a94a 100644 --- a/pkg/deployment/trigger/devtronApps/TriggerService.go +++ b/pkg/deployment/trigger/devtronApps/TriggerService.go @@ -919,7 +919,7 @@ func (impl *TriggerServiceImpl) performGitOps(ctx context.Context, } if manifestPushResponse.IsNewGitRepoConfigured() { // Update GitOps repo url after repo new repo created - valuesOverrideResponse.DeploymentConfig.RepoURL = manifestPushResponse.NewGitRepoUrl + valuesOverrideResponse.DeploymentConfig.SetRepoURL(manifestPushResponse.NewGitRepoUrl) } valuesOverrideResponse.ManifestPushTemplate = manifestPushTemplate return nil @@ -1034,7 +1034,7 @@ func (impl *TriggerServiceImpl) buildManifestPushTemplate(overrideRequest *bean3 manifestPushTemplate.ChartName = valuesOverrideResponse.EnvOverride.Chart.ChartName manifestPushTemplate.ChartVersion = valuesOverrideResponse.EnvOverride.Chart.ChartVersion manifestPushTemplate.ChartLocation = valuesOverrideResponse.EnvOverride.Chart.ChartLocation - manifestPushTemplate.RepoUrl = valuesOverrideResponse.DeploymentConfig.RepoURL + manifestPushTemplate.RepoUrl = valuesOverrideResponse.DeploymentConfig.GetRepoURL() manifestPushTemplate.IsCustomGitRepository = common.IsCustomGitOpsRepo(valuesOverrideResponse.DeploymentConfig.ConfigType) } return manifestPushTemplate, nil @@ -1231,15 +1231,15 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(ctx context.Context, pipeline appStatus, _ := status2.FromError(err) if appStatus.Code() == codes.OK { impl.logger.Debugw("argo app exists", "app", argoAppName, "pipeline", pipeline.Name) - if impl.argoClientWrapperService.IsArgoAppPatchRequired(argoApplication.Spec.Source, deploymentConfig.RepoURL, envOverride.Chart.ChartLocation) { + if impl.argoClientWrapperService.IsArgoAppPatchRequired(argoApplication.Spec.Source, deploymentConfig.GetRepoURL(), envOverride.Chart.ChartLocation) { patchRequestDto := &bean7.ArgoCdAppPatchReqDto{ ArgoAppName: argoAppName, ChartLocation: envOverride.Chart.ChartLocation, - GitRepoUrl: deploymentConfig.RepoURL, + GitRepoUrl: deploymentConfig.GetRepoURL(), TargetRevision: bean7.TargetRevisionMaster, PatchType: bean7.PatchTypeMerge, } - url, err := impl.gitOperationService.GetRepoUrlWithUserName(deploymentConfig.RepoURL) + url, err := impl.gitOperationService.GetRepoUrlWithUserName(deploymentConfig.GetRepoURL()) if err != nil { return false, err } @@ -1249,7 +1249,7 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(ctx context.Context, pipeline impl.logger.Errorw("error in patching argo pipeline", "err", err, "req", patchRequestDto) return false, err } - if deploymentConfig.RepoURL != argoApplication.Spec.Source.RepoURL { + if deploymentConfig.GetRepoURL() != argoApplication.Spec.Source.RepoURL { impl.logger.Infow("patching argo application's repo url", "argoAppName", argoAppName) } impl.logger.Debugw("pipeline update req", "res", patchRequestDto) @@ -1514,7 +1514,7 @@ func (impl *TriggerServiceImpl) handleCustomGitOpsRepoValidation(runner *pipelin // impl.logger.Errorw("error in fetching latest chart for app by appId", "err", err, "appId", pipeline.AppId) // return err //} - if gitOps.IsGitOpsRepoNotConfigured(envDeploymentConfig.RepoURL) { + if gitOps.IsGitOpsRepoNotConfigured(envDeploymentConfig.GetRepoURL()) { if err = impl.cdWorkflowCommonService.MarkCurrentDeploymentFailed(runner, errors.New(cdWorkflow.GITOPS_REPO_NOT_CONFIGURED), triggeredBy); err != nil { impl.logger.Errorw("error while updating current runner status to failed, TriggerDeployment", "wfrId", runner.Id, "err", err) } diff --git a/pkg/pipeline/AppDeploymentTypeChangeManager.go b/pkg/pipeline/AppDeploymentTypeChangeManager.go index a2d4cdcc34..8ed329151e 100644 --- a/pkg/pipeline/AppDeploymentTypeChangeManager.go +++ b/pkg/pipeline/AppDeploymentTypeChangeManager.go @@ -520,7 +520,7 @@ func (impl *AppDeploymentTypeChangeManagerImpl) DeleteDeploymentApps(ctx context impl.logger.Errorw("error in updating git repo url in charts", "err", RepoURLUpdateErr) } envDeploymentConfig.ConfigType = common.GetDeploymentConfigType(chart.IsCustomGitRepository) - envDeploymentConfig.RepoURL = chartGitAttr.RepoUrl + envDeploymentConfig.SetRepoURL(chartGitAttr.RepoUrl) envDeploymentConfig, RepoURLUpdateErr = impl.deploymentConfigService.CreateOrUpdateConfig(nil, envDeploymentConfig, userId) if RepoURLUpdateErr != nil { diff --git a/pkg/pipeline/DeploymentPipelineConfigService.go b/pkg/pipeline/DeploymentPipelineConfigService.go index d40ff86d3f..ea4924fa85 100644 --- a/pkg/pipeline/DeploymentPipelineConfigService.go +++ b/pkg/pipeline/DeploymentPipelineConfigService.go @@ -429,7 +429,7 @@ func (impl *CdPipelineConfigServiceImpl) CreateCdPipelines(pipelineCreateRequest // TODO: creating git repo for all apps irrespective of acd or helm if gitOpsConfigurationStatus.IsGitOpsConfigured && isGitOpsRequiredForCD && !pipelineCreateRequest.IsCloneAppReq { - if gitOps.IsGitOpsRepoNotConfigured(AppDeploymentConfig.RepoURL) { + if gitOps.IsGitOpsRepoNotConfigured(AppDeploymentConfig.GetRepoURL()) { if gitOpsConfigurationStatus.AllowCustomRepository || AppDeploymentConfig.ConfigType == bean4.CUSTOM.String() { apiErr := &util.ApiError{ HttpStatusCode: http.StatusConflict, diff --git a/wire_gen.go b/wire_gen.go index 7fa328d30c..2ef7dfebc0 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -510,7 +510,7 @@ func InitializeApp() (*App, error) { pipelineStatusSyncDetailServiceImpl := status.NewPipelineStatusSyncDetailServiceImpl(sugaredLogger, pipelineStatusSyncDetailRepositoryImpl) installedAppVersionHistoryRepositoryImpl := repository3.NewInstalledAppVersionHistoryRepositoryImpl(sugaredLogger, db) repositoryImpl := deploymentConfig.NewRepositoryImpl(db) - deploymentConfigServiceImpl := common.NewDeploymentConfigServiceImpl(repositoryImpl, sugaredLogger, chartRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, installedAppReadServiceEAImpl, environmentVariables, envConfigOverrideReadServiceImpl, commonServiceImpl, environmentRepositoryImpl) + deploymentConfigServiceImpl := common.NewDeploymentConfigServiceImpl(repositoryImpl, sugaredLogger, chartRepositoryImpl, pipelineRepositoryImpl, appRepositoryImpl, installedAppReadServiceEAImpl, environmentVariables, envConfigOverrideReadServiceImpl, environmentRepositoryImpl) pipelineStatusTimelineServiceImpl := status.NewPipelineStatusTimelineServiceImpl(sugaredLogger, pipelineStatusTimelineRepositoryImpl, cdWorkflowRepositoryImpl, userServiceImpl, pipelineStatusTimelineResourcesServiceImpl, pipelineStatusSyncDetailServiceImpl, installedAppRepositoryImpl, installedAppVersionHistoryRepositoryImpl, deploymentConfigServiceImpl) appServiceConfig, err := app2.GetAppServiceConfig() if err != nil { From abc8fea913425f448d4406cac193e86a3f81fa76 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Fri, 17 Jan 2025 13:00:58 +0530 Subject: [PATCH 03/16] comments --- pkg/deployment/common/bean/bean.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index 17e88564e5..986a304a90 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -9,8 +9,8 @@ import ( ) type Destination struct { - Namespace string `json:"namespace,omitempty"` - Server string `json:"server,omitempty"` + Namespace string `json:"namespace,omitempty"` // deployed application namespace + Server string `json:"server,omitempty"` // deployed application cluster url } type Source struct { @@ -25,8 +25,8 @@ type SyncPolicy struct { } type ArgoCDSpec struct { - ClusterId int `json:"clusterId,omitempty"` - Namespace string `json:"namespace,omitempty"` + ClusterId int `json:"clusterId,omitempty"` // Application object cluster + Namespace string `json:"namespace,omitempty"` // Application object namespace Destination *Destination `json:"destination,omitempty"` Source *Source `json:"source,omitempty"` SyncPolicy *SyncPolicy `json:"syncPolicy,omitempty"` From ca6fda736df05fe3138c316bab30401a374736e8 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Fri, 17 Jan 2025 13:06:50 +0530 Subject: [PATCH 04/16] adding comments --- pkg/deployment/common/deploymentConfigService.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index 1b314d86ff..9c0ebff0db 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -207,6 +207,7 @@ func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, en impl.logger.Errorw("error in getting deployment config db object by appId and envId", "appId", appId, "envId", envId, "err", err) return nil, err } else if errors.Is(err, pg.ErrNoRows) { + // case: deployment config data is not yet migrated appAndEnvLevelConfig, err = impl.parseEnvLevelMigrationDataForDevtronApps(appLevelConfig, appId, envId) if err != nil { impl.logger.Errorw("error in parsing env level config to deployment config", "appId", appId, "envId", envId, "err", err) @@ -220,6 +221,7 @@ func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, en } } } else { + // case: deployment config is migrated but release config is absent appAndEnvLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfigDBObj) if err != nil { impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) From a18b96f662fb2e394e121b27942ed092ae02c445 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Fri, 17 Jan 2025 13:22:41 +0530 Subject: [PATCH 05/16] wip: adding repo name in deployment config struct --- pkg/deployment/common/bean/bean.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index 986a304a90..cf995e8cdd 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -56,6 +56,7 @@ type DeploymentConfig struct { DeploymentAppType string ReleaseMode string RepoURL string // DEPRECATED; + RepoName string Active bool ReleaseConfiguration *ReleaseConfiguration } From 81ccd3a5e4cf9becccde3920fa437d1315df554d Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Fri, 17 Jan 2025 14:23:07 +0530 Subject: [PATCH 06/16] migration files --- scripts/sql/31602801_release_config.down.sql | 1 + scripts/sql/31602801_release_config.up.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 scripts/sql/31602801_release_config.down.sql create mode 100644 scripts/sql/31602801_release_config.up.sql diff --git a/scripts/sql/31602801_release_config.down.sql b/scripts/sql/31602801_release_config.down.sql new file mode 100644 index 0000000000..17cb9f5c42 --- /dev/null +++ b/scripts/sql/31602801_release_config.down.sql @@ -0,0 +1 @@ +ALTER TABLE deployment_config DROP COLUMN release_config text; \ No newline at end of file diff --git a/scripts/sql/31602801_release_config.up.sql b/scripts/sql/31602801_release_config.up.sql new file mode 100644 index 0000000000..db870a6a1c --- /dev/null +++ b/scripts/sql/31602801_release_config.up.sql @@ -0,0 +1 @@ +ALTER TABLE deployment_config ADD COLUMN release_config text; \ No newline at end of file From 20e0b4de82190e03bb9aa1e852387961d8657ce8 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Fri, 17 Jan 2025 14:45:24 +0530 Subject: [PATCH 07/16] migration update --- scripts/sql/31602801_release_config.down.sql | 2 +- scripts/sql/31602801_release_config.up.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/sql/31602801_release_config.down.sql b/scripts/sql/31602801_release_config.down.sql index 17cb9f5c42..88dfc62b31 100644 --- a/scripts/sql/31602801_release_config.down.sql +++ b/scripts/sql/31602801_release_config.down.sql @@ -1 +1 @@ -ALTER TABLE deployment_config DROP COLUMN release_config text; \ No newline at end of file +ALTER TABLE deployment_config DROP COLUMN release_config; \ No newline at end of file diff --git a/scripts/sql/31602801_release_config.up.sql b/scripts/sql/31602801_release_config.up.sql index db870a6a1c..f00353a697 100644 --- a/scripts/sql/31602801_release_config.up.sql +++ b/scripts/sql/31602801_release_config.up.sql @@ -1 +1 @@ -ALTER TABLE deployment_config ADD COLUMN release_config text; \ No newline at end of file +ALTER TABLE deployment_config ADD COLUMN release_config jsonb; \ No newline at end of file From ecf84f11ac3403fed3c793d948fc027ea723fee7 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 01:20:25 +0530 Subject: [PATCH 08/16] review changes --- .../repository/deploymentConfig/repository.go | 12 +- pkg/appStore/bean/bean.go | 28 +-- pkg/deployment/common/adapter.go | 6 +- pkg/deployment/common/bean/bean.go | 140 +++++++++++++-- .../common/deploymentConfigService.go | 164 ++++++++++-------- util/GlobalConfig.go | 1 + 6 files changed, 236 insertions(+), 115 deletions(-) diff --git a/internal/sql/repository/deploymentConfig/repository.go b/internal/sql/repository/deploymentConfig/repository.go index de57e4fe3f..b13c32b926 100644 --- a/internal/sql/repository/deploymentConfig/repository.go +++ b/internal/sql/repository/deploymentConfig/repository.go @@ -30,7 +30,7 @@ type DeploymentConfig struct { RepoUrl string `sql:"repo_url"` RepoName string `sql:"repo_name"` ReleaseMode string `sql:"release_mode"` - ReleaseConfig string `sql:"release_config"` + ReleaseConfig []byte `sql:"release_config"` Active bool `sql:"active,notnull"` sql.AuditLog } @@ -47,7 +47,6 @@ type Repository interface { GetAppAndEnvLevelConfigsInBulk(appIdToEnvIdsMap map[int][]int) ([]*DeploymentConfig, error) GetByAppIdAndEnvIdEvenIfInactive(appId, envId int) (*DeploymentConfig, error) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, envId int) error - GetAllWithEmptyReleaseConfig() ([]*DeploymentConfig, error) } type RepositoryImpl struct { @@ -174,12 +173,3 @@ func (impl *RepositoryImpl) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, Update() return err } - -func (impl *RepositoryImpl) GetAllWithEmptyReleaseConfig() ([]*DeploymentConfig, error) { - result := make([]*DeploymentConfig, 0) - err := impl.dbConnection.Model(&result).Where("length(release_config)=0 ").Select() - if err != nil { - return nil, err - } - return result, nil -} diff --git a/pkg/appStore/bean/bean.go b/pkg/appStore/bean/bean.go index efac1068ba..5a7f0baf4e 100644 --- a/pkg/appStore/bean/bean.go +++ b/pkg/appStore/bean/bean.go @@ -222,18 +222,26 @@ func (chart *InstallAppVersionDTO) GetDeploymentConfig() *bean2.DeploymentConfig DeploymentAppType: chart.DeploymentAppType, ReleaseMode: util2.PIPELINE_RELEASE_MODE_CREATE, ReleaseConfiguration: &bean2.ReleaseConfiguration{ + Version: bean2.Version, ArgoCDSpec: bean2.ArgoCDSpec{ - ClusterId: DEFAULT_CLUSTER_ID, - Namespace: argocdServer.DevtronInstalationNs, - Destination: &bean2.Destination{ - Namespace: chart.Namespace, - Server: commonBean.DefaultClusterUrl, + Metadata: bean2.ApplicationMetadata{ + ClusterId: DEFAULT_CLUSTER_ID, + Namespace: argocdServer.DevtronInstalationNs, }, - Source: &bean2.Source{ - RepoURL: chart.GitOpsRepoURL, - ChartPath: util.BuildDeployedAppName(chart.AppName, chart.EnvironmentName), - ValuesFilePath: "values.yaml", - TargetRevision: "master", + Spec: bean2.ApplicationSpec{ + Destination: &bean2.Destination{ + Namespace: chart.Namespace, + Server: commonBean.DefaultClusterUrl, + }, + Source: &bean2.ApplicationSource{ + RepoURL: chart.GitOpsRepoURL, + Path: util.BuildDeployedAppName(chart.AppName, chart.EnvironmentName), + Helm: &bean2.ApplicationSourceHelm{ + ValueFiles: []string{"values.yaml"}, + }, + TargetRevision: "master", + }, + SyncPolicy: nil, }, }, }, diff --git a/pkg/deployment/common/adapter.go b/pkg/deployment/common/adapter.go index 9908f3d53b..21d82f9575 100644 --- a/pkg/deployment/common/adapter.go +++ b/pkg/deployment/common/adapter.go @@ -16,14 +16,14 @@ func ConvertDeploymentConfigDTOToDbObj(config *bean.DeploymentConfig) (*deployme ConfigType: config.ConfigType, Active: config.Active, ReleaseMode: config.ReleaseMode, - ReleaseConfig: string(config.ReleaseConfiguration.JSON()), + ReleaseConfig: config.ReleaseConfiguration.JSON(), }, nil } - func ConvertDeploymentConfigDbObjToDTO(dbObj *deploymentConfig.DeploymentConfig) (*bean.DeploymentConfig, error) { var releaseConfig bean.ReleaseConfiguration - err := json.Unmarshal([]byte(dbObj.ReleaseConfig), &releaseConfig) + + err := json.Unmarshal(dbObj.ReleaseConfig, &releaseConfig) if err != nil { return nil, err } diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index cf995e8cdd..7365089c26 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -8,32 +8,134 @@ import ( "strings" ) +type ReleaseConfigVersion string + +const ( + Version ReleaseConfigVersion = "v1.0.0" +) + +type ReleaseConfiguration struct { + Version ReleaseConfigVersion `json:"version"` + ArgoCDSpec ArgoCDSpec `json:"argoCDSpec"` +} + +type ArgoCDSpec struct { + Metadata ApplicationMetadata `json:"metadata"` + Spec ApplicationSpec `json:"spec"` +} + +type ApplicationMetadata struct { + ClusterId int `json:"clusterId"` + Namespace string `json:"namespace"` +} + +type ApplicationSpec struct { + Destination *Destination `json:"destination,omitempty"` + Source *ApplicationSource `json:"source,omitempty"` + SyncPolicy *SyncPolicyAutomated `json:"syncPolicy,omitempty"` +} + +type ApplicationSource struct { + // RepoURL is the URL to the repository (Git or Helm) that contains the application manifests + RepoURL string `json:"repoURL"` + // Path is a directory path within the Git repository, and is only valid for applications sourced from Git. + Path string `json:"path,omitempty"` + // TargetRevision defines the revision of the source to sync the application to. + // In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. + // In case of Helm, this is a semver tag for the Chart's version. + TargetRevision string `json:"targetRevision,omitempty"` + // Helm holds helm specific options + Helm *ApplicationSourceHelm `json:"helm,omitempty"` + // Chart is a Helm chart name, and must be specified for applications sourced from a Helm repo. + Chart string `json:"chart,omitempty"` + // Ref is reference to another source within sources field. This field will not be used if used with a `source` tag. + Ref string `json:"ref,omitempty"` +} + +// ApplicationSourceHelm holds helm specific options +type ApplicationSourceHelm struct { + // ValuesFiles is a list of Helm value files to use when generating a template + ValueFiles []string `json:"valueFiles,omitempty"` + // Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation + Parameters []HelmParameter `json:"parameters,omitempty"` + // ReleaseName is the Helm release name to use. If omitted it will use the application name + ReleaseName string `json:"releaseName,omitempty"` + // Values specifies Helm values to be passed to helm template, typically defined as a block + Values string `json:"values,omitempty"` + // FileParameters are file parameters to the helm template + FileParameters []HelmFileParameter `json:"fileParameters,omitempty"` + // Version is the Helm version to use for templating ("3") + Version string `json:"version,omitempty"` + // PassCredentials pass credentials to all domains (Helm's --pass-credentials) + PassCredentials bool `json:"passCredentials,omitempty"` + // IgnoreMissingValueFiles prevents helm template from failing when valueFiles do not exist locally by not appending them to helm template --values + IgnoreMissingValueFiles bool `json:"ignoreMissingValueFiles,omitempty"` + // SkipCrds skips custom resource definition installation step (Helm's --skip-crds) + SkipCrds bool `json:"skipCrds,omitempty"` +} + +type HelmParameter struct { + // Name is the name of the Helm parameter + Name string `json:"name,omitempty"` + // Value is the value for the Helm parameter + Value string `json:"value,omitempty"` + // ForceString determines whether to tell Helm to interpret booleans and numbers as strings + ForceString bool `json:"forceString,omitempty"` +} + +// HelmFileParameter is a file parameter that's passed to helm template during manifest generation +type HelmFileParameter struct { + // Name is the name of the Helm parameter + Name string `json:"name,omitempty"` + // Path is the path to the file containing the values for the Helm parameter + Path string `json:"path,omitempty"` +} + type Destination struct { Namespace string `json:"namespace,omitempty"` // deployed application namespace Server string `json:"server,omitempty"` // deployed application cluster url } -type Source struct { - RepoURL string `json:"repoURL,omitempty"` - ChartPath string `json:"chartPath,omitempty"` - ValuesFilePath string `json:"valuesFilePath,omitempty"` - TargetRevision string `json:"targetRevision,omitempty"` //target branch +type Automated struct { + Prune bool `json:"prune"` } type SyncPolicy struct { - SyncPolicy string `json:"syncPolicy,omitempty"` + Automated *SyncPolicyAutomated `json:"automated,omitempty"` + SyncOptions SyncOptions `json:"syncOptions,omitempty"` + Retry *RetryStrategy `json:"retry,omitempty"` + ManagedNamespaceMetadata *ManagedNamespaceMetadata `json:"managedNamespaceMetadata,omitempty"` } -type ArgoCDSpec struct { - ClusterId int `json:"clusterId,omitempty"` // Application object cluster - Namespace string `json:"namespace,omitempty"` // Application object namespace - Destination *Destination `json:"destination,omitempty"` - Source *Source `json:"source,omitempty"` - SyncPolicy *SyncPolicy `json:"syncPolicy,omitempty"` +type SyncPolicyAutomated struct { + Prune bool `json:"prune,omitempty"` + SelfHeal bool `json:"selfHeal,omitempty"` + AllowEmpty bool `json:"allowEmpty,omitempty"` } -type ReleaseConfiguration struct { - ArgoCDSpec ArgoCDSpec `json:"argoCDSpec"` +type SyncOptions []string + +// RetryStrategy contains information about the strategy to apply when a sync failed +type RetryStrategy struct { + // Limit is the maximum number of attempts for retrying a failed sync. If set to 0, no retries will be performed. + Limit int64 `json:"limit,omitempty"` + // Backoff controls how to backoff on subsequent retries of failed syncs + Backoff *Backoff `json:"backoff,omitempty"` +} + +// Backoff is the backoff strategy to use on subsequent retries for failing syncs +type Backoff struct { + // Duration is the amount to back off. Default unit is seconds, but could also be a duration (e.g. "2m", "1h") + Duration string `json:"duration,omitempty"` + // Factor is a factor to multiply the base duration after each failed retry + Factor *int64 `json:"factor,omitempty"` + // MaxDuration is the maximum amount of time allowed for the backoff strategy + MaxDuration string `json:"maxDuration,omitempty"` +} + +type ManagedNamespaceMetadata struct { + Labels map[string]string `json:"labels,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` } func (r *ReleaseConfiguration) JSON() []byte { @@ -62,15 +164,19 @@ type DeploymentConfig struct { } func (c *DeploymentConfig) GetRepoURL() string { - return c.ReleaseConfiguration.ArgoCDSpec.Source.RepoURL + return c.ReleaseConfiguration.ArgoCDSpec.Spec.Source.RepoURL } func (c *DeploymentConfig) GetChartLocation() string { - return c.ReleaseConfiguration.ArgoCDSpec.Source.ChartPath + return c.ReleaseConfiguration.ArgoCDSpec.Spec.Source.Path } func (c *DeploymentConfig) SetRepoURL(repoURL string) { - c.ReleaseConfiguration.ArgoCDSpec.Source.RepoURL = repoURL + c.ReleaseConfiguration.ArgoCDSpec.Spec.Source.RepoURL = repoURL +} + +func (c *DeploymentConfig) GetRevision() string { + return c.ReleaseConfiguration.ArgoCDSpec.Spec.Source.TargetRevision } type UniqueDeploymentConfigIdentifier string diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index 9c0ebff0db..842a999729 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -139,24 +139,22 @@ func (impl *DeploymentConfigServiceImpl) GetConfigForDevtronApps(appId, envId in } func (impl *DeploymentConfigServiceImpl) getAppLevelConfigForDevtronApps(appId int, envId int, migrateDataIfAbsent bool) (*bean.DeploymentConfig, error) { - var appLevelConfig *bean.DeploymentConfig + + var ( + appLevelConfig *bean.DeploymentConfig + isMigrationNeeded bool + ) appLevelConfigDbObj, err := impl.deploymentConfigRepository.GetAppLevelConfigForDevtronApps(appId) if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in getting deployment config db object by appId", "appId", appId, "err", err) return nil, err } else if errors.Is(err, pg.ErrNoRows) { + isMigrationNeeded = true appLevelConfig, err = impl.parseAppLevelMigrationDataForDevtronApps(appId) if err != nil { impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) return nil, err } - if migrateDataIfAbsent { - _, err := impl.CreateOrUpdateConfig(nil, appLevelConfig, bean3.SYSTEM_USER_ID) - if err != nil { - impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) - return nil, err - } - } } else { appLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj) if err != nil { @@ -164,24 +162,24 @@ func (impl *DeploymentConfigServiceImpl) getAppLevelConfigForDevtronApps(appId i return nil, err } if appLevelConfig.ReleaseConfiguration == nil { + isMigrationNeeded = true releaseConfig, err := impl.parseAppLevelReleaseConfigForDevtronApp(appId, appLevelConfig) if err != nil { impl.logger.Errorw("error in parsing release configuration for app", "appId", appId, "err", err) return nil, err } appLevelConfig.ReleaseConfiguration = releaseConfig - - if migrateDataIfAbsent { - _, err := impl.CreateOrUpdateConfig(nil, appLevelConfig, bean3.SYSTEM_USER_ID) - if err != nil { - impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) - return nil, err - } - } - + } + } + if migrateDataIfAbsent && isMigrationNeeded { + _, err := impl.CreateOrUpdateConfig(nil, appLevelConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) + return nil, err } } return appLevelConfig, nil + } func (impl *DeploymentConfigServiceImpl) parseAppLevelReleaseConfigForDevtronApp(appId int, appLevelConfig *bean.DeploymentConfig) (*bean.ReleaseConfiguration, error) { @@ -192,7 +190,7 @@ func (impl *DeploymentConfigServiceImpl) parseAppLevelReleaseConfigForDevtronApp } repoURL := chart.GitRepoUrl - if impl.deploymentServiceTypeConfig.UseDeploymentConfigData { + if len(appLevelConfig.RepoURL) > 0 { repoURL = appLevelConfig.RepoURL } @@ -201,7 +199,10 @@ func (impl *DeploymentConfigServiceImpl) parseAppLevelReleaseConfigForDevtronApp } func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, envId int, appLevelConfig *bean.DeploymentConfig, migrateDataIfAbsent bool) (*bean.DeploymentConfig, error) { - var appAndEnvLevelConfig *bean.DeploymentConfig + var ( + appAndEnvLevelConfig *bean.DeploymentConfig + isMigrationNeeded bool + ) appAndEnvLevelConfigDBObj, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in getting deployment config db object by appId and envId", "appId", appId, "envId", envId, "err", err) @@ -213,13 +214,8 @@ func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, en impl.logger.Errorw("error in parsing env level config to deployment config", "appId", appId, "envId", envId, "err", err) return nil, err } - if migrateDataIfAbsent { - _, err := impl.CreateOrUpdateConfig(nil, appAndEnvLevelConfig, bean3.SYSTEM_USER_ID) - if err != nil { - impl.logger.Errorw("error in migrating env level config to deployment config", "appId", appId, "envId", envId, "err", err) - return nil, err - } - } + isMigrationNeeded = true + } else { // case: deployment config is migrated but release config is absent appAndEnvLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfigDBObj) @@ -227,20 +223,22 @@ func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, en impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) return nil, err } + if appAndEnvLevelConfig.ReleaseConfiguration == nil { + isMigrationNeeded = true releaseConfig, err := impl.parseEnvLevelReleaseConfigForDevtronApp(appAndEnvLevelConfig, appId, envId) if err != nil { impl.logger.Errorw("error in parsing env level release config", "appId", appId, "envId", envId, "err", err) return nil, err } appAndEnvLevelConfig.ReleaseConfiguration = releaseConfig - if migrateDataIfAbsent { - _, err := impl.CreateOrUpdateConfig(nil, appAndEnvLevelConfig, bean3.SYSTEM_USER_ID) - if err != nil { - impl.logger.Errorw("error in migrating app level config to deployment config", "appId", appId, "err", err) - return nil, err - } - } + } + } + if migrateDataIfAbsent && isMigrationNeeded { + _, err := impl.CreateOrUpdateConfig(nil, appAndEnvLevelConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in migrating env level config to deployment config", "appId", appId, "envId", envId, "err", err) + return nil, err } } return appAndEnvLevelConfig, nil @@ -273,7 +271,9 @@ func (impl *DeploymentConfigServiceImpl) ConfigureEnvURLByAppURLIfNotConfigured( func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error) { - appLevelConfig, err := impl.getAppLevelConfigForDevtronApps(appId, envId, true) + migrateDeploymentConfigData := impl.deploymentServiceTypeConfig.MigrateDeploymentConfigData + + appLevelConfig, err := impl.getAppLevelConfigForDevtronApps(appId, envId, migrateDeploymentConfigData) if err != nil { impl.logger.Errorw("error in getting app level Config for devtron apps", "appId", appId, "envId", envId, "err", err) return nil, err @@ -281,12 +281,12 @@ func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForDevtronAp var envLevelConfig *bean.DeploymentConfig if envId > 0 { - envLevelConfig, err = impl.getEnvLevelDataForDevtronApps(appId, envId, appLevelConfig, true) + envLevelConfig, err = impl.getEnvLevelDataForDevtronApps(appId, envId, appLevelConfig, migrateDeploymentConfigData) if err != nil { impl.logger.Errorw("error in getting env level data for devtron apps", "appId", appId, "envId", envId, "err", err) return nil, err } - envLevelConfig, err = impl.ConfigureEnvURLByAppURLIfNotConfigured(envLevelConfig, appLevelConfig.GetRepoURL(), true) + envLevelConfig, err = impl.ConfigureEnvURLByAppURLIfNotConfigured(envLevelConfig, appLevelConfig.GetRepoURL(), migrateDeploymentConfigData) if err != nil { impl.logger.Errorw("error in getting env level data for devtron apps", "appId", appId, "envId", envId, "err", err) return nil, err @@ -298,10 +298,13 @@ func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForDevtronAp func newAppLevelReleaseConfigFromChart(gitRepoURL, chartLocation string) *bean.ReleaseConfiguration { return &bean.ReleaseConfiguration{ + Version: bean.Version, ArgoCDSpec: bean.ArgoCDSpec{ - Source: &bean.Source{ - RepoURL: gitRepoURL, - ChartPath: chartLocation, + Spec: bean.ApplicationSpec{ + Source: &bean.ApplicationSource{ + RepoURL: gitRepoURL, + Path: chartLocation, + }, }, }} } @@ -363,6 +366,9 @@ func (impl *DeploymentConfigServiceImpl) parseEnvLevelMigrationDataForDevtronApp func (impl *DeploymentConfigServiceImpl) parseEnvLevelReleaseConfigForDevtronApp(config *bean.DeploymentConfig, appId int, envId int) (*bean.ReleaseConfiguration, error) { var releaseConfig *bean.ReleaseConfiguration if config.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD { + + releaseConfig.Version = bean.Version + envOverride, err := impl.EnvConfigOverrideService.ActiveEnvConfigOverride(appId, envId) if err != nil { return nil, err @@ -389,23 +395,26 @@ func (impl *DeploymentConfigServiceImpl) parseEnvLevelReleaseConfigForDevtronApp if len(config.RepoURL) > 0 { gitRepoUrl = config.RepoURL } - releaseConfig = &bean.ReleaseConfiguration{ - ArgoCDSpec: bean.ArgoCDSpec{ + releaseConfig.ArgoCDSpec = bean.ArgoCDSpec{ + Metadata: bean.ApplicationMetadata{ ClusterId: bean2.DefaultClusterId, Namespace: argocdServer.DevtronInstalationNs, + }, + Spec: bean.ApplicationSpec{ + Source: &bean.ApplicationSource{ + RepoURL: gitRepoUrl, + Path: latestChart.ChartLocation, + Helm: &bean.ApplicationSourceHelm{ + ValueFiles: []string{fmt.Sprintf("_%d-values.yaml", env.Namespace)}, + }, + TargetRevision: "master", + }, Destination: &bean.Destination{ Namespace: env.Namespace, Server: commonBean.DefaultClusterUrl, }, - Source: &bean.Source{ - RepoURL: gitRepoUrl, - ChartPath: latestChart.ChartLocation, - ValuesFilePath: fmt.Sprintf("_%d-values.yaml", env.Namespace), - TargetRevision: "master", - }, }, } - config.ReleaseConfiguration = releaseConfig } return releaseConfig, nil } @@ -439,24 +448,21 @@ func (impl *DeploymentConfigServiceImpl) GetConfigForHelmApps(appId, envId int) } func (impl *DeploymentConfigServiceImpl) getConfigForHelmApps(appId int, envId int, migrateIfAbsent bool) (*bean.DeploymentConfig, error) { - var helmDeploymentConfig *bean.DeploymentConfig + var ( + helmDeploymentConfig *bean.DeploymentConfig + isMigrationNeeded bool + ) config, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) if err != nil && !errors.Is(err, pg.ErrNoRows) { impl.logger.Errorw("error in fetching deployment config by by appId and envId", "appId", appId, "envId", envId, "err", err) return nil, err } else if errors.Is(err, pg.ErrNoRows) { + isMigrationNeeded = true helmDeploymentConfig, err = impl.parseDeploymentConfigForHelmApps(appId, envId) if err != nil { impl.logger.Errorw("error in parsing helm deployment config", "appId", appId, "envId", envId, "err", err) return nil, err } - if migrateIfAbsent { - _, err = impl.CreateOrUpdateConfig(nil, helmDeploymentConfig, bean3.SYSTEM_USER_ID) - if err != nil { - impl.logger.Errorw("error in creating helm deployment config ", "appId", appId, "envId", envId, "err", err) - return nil, err - } - } } else { helmDeploymentConfig, err = ConvertDeploymentConfigDbObjToDTO(config) if err != nil { @@ -464,19 +470,20 @@ func (impl *DeploymentConfigServiceImpl) getConfigForHelmApps(appId int, envId i return nil, err } if helmDeploymentConfig.ReleaseConfiguration == nil { + isMigrationNeeded = true releaseConfig, err := impl.parseReleaseConfigForHelmApps(appId, envId, helmDeploymentConfig) if err != nil { impl.logger.Errorw("error in parsing release config", "appId", appId, "envId", envId, "err", err) return nil, err } helmDeploymentConfig.ReleaseConfiguration = releaseConfig - if migrateIfAbsent { - _, err = impl.CreateOrUpdateConfig(nil, helmDeploymentConfig, bean3.SYSTEM_USER_ID) - if err != nil { - impl.logger.Errorw("error in creating helm deployment config ", "appId", appId, "envId", envId, "err", err) - return nil, err - } - } + } + } + if migrateIfAbsent && isMigrationNeeded { + _, err = impl.CreateOrUpdateConfig(nil, helmDeploymentConfig, bean3.SYSTEM_USER_ID) + if err != nil { + impl.logger.Errorw("error in creating helm deployment config ", "appId", appId, "envId", envId, "err", err) + return nil, err } } return helmDeploymentConfig, err @@ -497,7 +504,8 @@ func (impl *DeploymentConfigServiceImpl) GetConfigEvenIfInactive(appId, envId in } func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForHelmApp(appId, envId int) (*bean.DeploymentConfig, error) { - helmDeploymentConfig, err := impl.getConfigForHelmApps(appId, envId, true) + migrateDataIfAbsent := impl.deploymentServiceTypeConfig.MigrateDeploymentConfigData + helmDeploymentConfig, err := impl.getConfigForHelmApps(appId, envId, migrateDataIfAbsent) if err != nil { impl.logger.Errorw("error in getting deployment config for helm app", "appId", appId, "envId", envId, "err", err) return nil, err @@ -533,6 +541,7 @@ func (impl *DeploymentConfigServiceImpl) parseDeploymentConfigForHelmApps(appId func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int, envId int, config *bean.DeploymentConfig) (*bean.ReleaseConfiguration, error) { var releaseConfig *bean.ReleaseConfiguration if config.DeploymentAppType == bean4.PIPELINE_DEPLOYMENT_TYPE_ACD { + releaseConfig.Version = bean.Version app, err := impl.appRepository.FindById(appId) if err != nil { impl.logger.Errorw("error in getting app by id", "appId", appId, "err", err) @@ -557,18 +566,25 @@ func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int } releaseConfig = &bean.ReleaseConfiguration{ + Version: bean.Version, ArgoCDSpec: bean.ArgoCDSpec{ - ClusterId: bean2.DefaultClusterId, - Namespace: argocdServer.DevtronInstalationNs, - Destination: &bean.Destination{ - Namespace: env.Namespace, - Server: commonBean.DefaultClusterUrl, + Metadata: bean.ApplicationMetadata{ + ClusterId: bean2.DefaultClusterId, + Namespace: argocdServer.DevtronInstalationNs, }, - Source: &bean.Source{ - RepoURL: gitRepoURL, - ChartPath: util.BuildDeployedAppName(app.AppName, env.Name), - ValuesFilePath: "values.yaml", - TargetRevision: "master", + Spec: bean.ApplicationSpec{ + Destination: &bean.Destination{ + Namespace: env.Namespace, + Server: commonBean.DefaultClusterUrl, + }, + Source: &bean.ApplicationSource{ + RepoURL: gitRepoURL, + Path: util.BuildDeployedAppName(app.AppName, env.Name), + Helm: &bean.ApplicationSourceHelm{ + ValueFiles: []string{"values.yaml"}, + }, + TargetRevision: "master", + }, }, }, } diff --git a/util/GlobalConfig.go b/util/GlobalConfig.go index 879c34094e..06cb9dc55c 100644 --- a/util/GlobalConfig.go +++ b/util/GlobalConfig.go @@ -32,6 +32,7 @@ type DeploymentServiceTypeConfig struct { ExternallyManagedDeploymentType bool `env:"IS_INTERNAL_USE" envDefault:"false"` HelmInstallASyncMode bool `env:"RUN_HELM_INSTALL_IN_ASYNC_MODE_HELM_APPS" envDefault:"false"` UseDeploymentConfigData bool `env:"USE_DEPLOYMENT_CONFIG_DATA" envDefault:"false"` + MigrateDeploymentConfigData bool `json:"MIGRATE_DEPLOYMENT_CONFIG_DATA" envDefault:"false"` } type GlobalEnvVariables struct { From 2f76843dc129436f6f076a635f700ba1b2f5f672 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 01:34:49 +0530 Subject: [PATCH 09/16] nil handling --- pkg/deployment/common/adapter.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/deployment/common/adapter.go b/pkg/deployment/common/adapter.go index 21d82f9575..1b0be2d896 100644 --- a/pkg/deployment/common/adapter.go +++ b/pkg/deployment/common/adapter.go @@ -23,9 +23,11 @@ func ConvertDeploymentConfigDbObjToDTO(dbObj *deploymentConfig.DeploymentConfig) var releaseConfig bean.ReleaseConfiguration - err := json.Unmarshal(dbObj.ReleaseConfig, &releaseConfig) - if err != nil { - return nil, err + if dbObj.ReleaseConfig != nil { + err := json.Unmarshal(dbObj.ReleaseConfig, &releaseConfig) + if err != nil { + return nil, err + } } return &bean.DeploymentConfig{ From 8cf7ea634509232d1e72c2d4ff9fe07c308b5d57 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 01:55:19 +0530 Subject: [PATCH 10/16] dev testing bug fixes --- pkg/deployment/common/deploymentConfigService.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index 842a999729..bcf83b8e12 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -364,7 +364,7 @@ func (impl *DeploymentConfigServiceImpl) parseEnvLevelMigrationDataForDevtronApp } func (impl *DeploymentConfigServiceImpl) parseEnvLevelReleaseConfigForDevtronApp(config *bean.DeploymentConfig, appId int, envId int) (*bean.ReleaseConfiguration, error) { - var releaseConfig *bean.ReleaseConfiguration + releaseConfig := &bean.ReleaseConfiguration{} if config.DeploymentAppType == util2.PIPELINE_DEPLOYMENT_TYPE_ACD { releaseConfig.Version = bean.Version @@ -539,7 +539,7 @@ func (impl *DeploymentConfigServiceImpl) parseDeploymentConfigForHelmApps(appId } func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int, envId int, config *bean.DeploymentConfig) (*bean.ReleaseConfiguration, error) { - var releaseConfig *bean.ReleaseConfiguration + releaseConfig := &bean.ReleaseConfiguration{} if config.DeploymentAppType == bean4.PIPELINE_DEPLOYMENT_TYPE_ACD { releaseConfig.Version = bean.Version app, err := impl.appRepository.FindById(appId) From 4d062a559bb129203c5c48ab0d9ef7b8498ec376 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 02:00:03 +0530 Subject: [PATCH 11/16] fixes --- pkg/deployment/common/deploymentConfigService.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index bcf83b8e12..d6866dc773 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -224,7 +224,7 @@ func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, en return nil, err } - if appAndEnvLevelConfig.ReleaseConfiguration == nil { + if appAndEnvLevelConfig.ReleaseConfiguration == nil || len(appAndEnvLevelConfig.ReleaseConfiguration.Version) == 0 { isMigrationNeeded = true releaseConfig, err := impl.parseEnvLevelReleaseConfigForDevtronApp(appAndEnvLevelConfig, appId, envId) if err != nil { @@ -291,6 +291,7 @@ func (impl *DeploymentConfigServiceImpl) GetAndMigrateConfigIfAbsentForDevtronAp impl.logger.Errorw("error in getting env level data for devtron apps", "appId", appId, "envId", envId, "err", err) return nil, err } + return envLevelConfig, nil } return envLevelConfig, nil @@ -469,7 +470,7 @@ func (impl *DeploymentConfigServiceImpl) getConfigForHelmApps(appId int, envId i impl.logger.Errorw("error in converting helm deployment config dbObj to DTO", "appId", appId, "envId", envId, "err", err) return nil, err } - if helmDeploymentConfig.ReleaseConfiguration == nil { + if helmDeploymentConfig.ReleaseConfiguration == nil || len(helmDeploymentConfig.ReleaseConfiguration.Version) == 0 { isMigrationNeeded = true releaseConfig, err := impl.parseReleaseConfigForHelmApps(appId, envId, helmDeploymentConfig) if err != nil { From fc43af7c3264bccdb0f39ba95e51ebc93d55494f Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 02:05:54 +0530 Subject: [PATCH 12/16] value file name fix --- pkg/deployment/common/deploymentConfigService.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index d6866dc773..babacbb905 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -406,7 +406,7 @@ func (impl *DeploymentConfigServiceImpl) parseEnvLevelReleaseConfigForDevtronApp RepoURL: gitRepoUrl, Path: latestChart.ChartLocation, Helm: &bean.ApplicationSourceHelm{ - ValueFiles: []string{fmt.Sprintf("_%d-values.yaml", env.Namespace)}, + ValueFiles: []string{fmt.Sprintf("_%d-values.yaml", env.Id)}, }, TargetRevision: "master", }, From f842233edd83d960d9da332bc90e2906180ffc4c Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 02:12:56 +0530 Subject: [PATCH 13/16] fixes --- pkg/deployment/common/deploymentConfigService.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index babacbb905..e292a8f9a3 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -161,7 +161,7 @@ func (impl *DeploymentConfigServiceImpl) getAppLevelConfigForDevtronApps(appId i impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) return nil, err } - if appLevelConfig.ReleaseConfiguration == nil { + if appLevelConfig.ReleaseConfiguration == nil || len(appLevelConfig.ReleaseConfiguration.Version) == 0 { isMigrationNeeded = true releaseConfig, err := impl.parseAppLevelReleaseConfigForDevtronApp(appId, appLevelConfig) if err != nil { From 6a5bf444ebae11002ff160aeb7e13078f2e9af59 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 02:27:08 +0530 Subject: [PATCH 14/16] repo url function update --- .../common/deploymentConfigService.go | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index e292a8f9a3..55e2687a94 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -594,11 +594,27 @@ func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int } func (impl *DeploymentConfigServiceImpl) UpdateRepoUrlForAppAndEnvId(repoURL string, appId, envId int) error { - err := impl.deploymentConfigRepository.UpdateRepoUrlByAppIdAndEnvId(repoURL, appId, envId) + + dbObj, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, envId) + if err != nil { + impl.logger.Errorw("error in getting deployment config by appId", "appId", appId, "envId", envId, "err", err) + return err + } + + config, err := ConvertDeploymentConfigDbObjToDTO(dbObj) if err != nil { - impl.logger.Errorw("error in updating repoUrl by app-id and env-id", "appId", appId, "envId", envId, "err", err) + impl.logger.Errorw("error in converting deployment config to DTO", "appId", appId, "envId", envId, "err", err) return err } + + config.SetRepoURL(repoURL) + + dbObj, err = impl.deploymentConfigRepository.Update(nil, dbObj) + if err != nil { + impl.logger.Errorw("error in updating deployment config", appId, "envId", envId, "err", err) + return err + } + return nil } From 2ba80d3f00cb6a4f96cfa39ccad9bf32a58bf4f6 Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 03:32:27 +0530 Subject: [PATCH 15/16] git repo url handing using code --- .../sql/repository/AppListingRepository.go | 18 +++++++++++++++++- .../repository/deploymentConfig/repository.go | 9 +++++++++ .../service/EAMode/InstalledAppDBService.go | 14 +++++++------- .../FullMode/InstalledAppDBExtendedService.go | 9 +++++++++ pkg/chart/ChartService.go | 9 +++++++++ pkg/deployment/common/bean/bean.go | 5 ++++- .../common/deploymentConfigService.go | 19 +++++++++++++++++++ 7 files changed, 74 insertions(+), 9 deletions(-) diff --git a/internal/sql/repository/AppListingRepository.go b/internal/sql/repository/AppListingRepository.go index 864f87921e..154916702d 100644 --- a/internal/sql/repository/AppListingRepository.go +++ b/internal/sql/repository/AppListingRepository.go @@ -30,6 +30,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig" "github.com/devtron-labs/devtron/internal/util" repository2 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" + "github.com/devtron-labs/devtron/pkg/deployment/common" "go.opentelemetry.io/otel" "strings" "time" @@ -624,7 +625,22 @@ func (impl AppListingRepositoryImpl) FetchAppStageStatus(appId int, appType int) if model != nil && model.Id > 0 && model.AllowCustomRepository { isCustomGitopsRepoUrl = true } - if (gitOps.IsGitOpsRepoNotConfigured(stages.ChartGitRepoUrl) && gitOps.IsGitOpsRepoNotConfigured(stages.DeploymentConfigRepoURL)) && stages.CiPipelineId == 0 { + + deploymentConfigDB, err := impl.deploymentConfigRepository.GetByAppIdAndEnvId(appId, 0) + if err != nil && err != pg.ErrNoRows { + impl.Logger.Errorw("error while getting deploymentConfig", "appId", appId, "err", err) + return appStageStatus, err + } + + dc, err := common.ConvertDeploymentConfigDbObjToDTO(deploymentConfigDB) + if err != nil { + impl.Logger.Errorw("error while converting DeploymentConfigDbObjToDTO", "err", err) + return nil, err + } + + if (gitOps.IsGitOpsRepoNotConfigured(stages.ChartGitRepoUrl) && + gitOps.IsGitOpsRepoNotConfigured(stages.DeploymentConfigRepoURL) && + (dc != nil && gitOps.IsGitOpsRepoNotConfigured(dc.GetRepoURL()))) && stages.CiPipelineId == 0 { stages.ChartGitRepoUrl = "" stages.DeploymentConfigRepoURL = "" } diff --git a/internal/sql/repository/deploymentConfig/repository.go b/internal/sql/repository/deploymentConfig/repository.go index b13c32b926..f23ed5cde0 100644 --- a/internal/sql/repository/deploymentConfig/repository.go +++ b/internal/sql/repository/deploymentConfig/repository.go @@ -47,6 +47,7 @@ type Repository interface { GetAppAndEnvLevelConfigsInBulk(appIdToEnvIdsMap map[int][]int) ([]*DeploymentConfig, error) GetByAppIdAndEnvIdEvenIfInactive(appId, envId int) (*DeploymentConfig, error) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, envId int) error + GetAllConfigsWithCustomGitOpsURL() ([]*DeploymentConfig, error) } type RepositoryImpl struct { @@ -173,3 +174,11 @@ func (impl *RepositoryImpl) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, Update() return err } + +func (impl *RepositoryImpl) GetAllConfigsWithCustomGitOpsURL() ([]*DeploymentConfig, error) { + result := make([]*DeploymentConfig, 0) + err := impl.dbConnection.Model(&result). + Where("active = ? and config_type = ? ", true, Custom). + Select() + return result, err +} diff --git a/pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go b/pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go index 621668ae55..d15747f22c 100644 --- a/pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go +++ b/pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go @@ -78,7 +78,7 @@ type InstalledAppDBServiceImpl struct { UserService user.UserService EnvironmentService environment.EnvironmentService InstalledAppRepositoryHistory appStoreRepo.InstalledAppVersionHistoryRepository - deploymentConfigService common.DeploymentConfigService + DeploymentConfigService common.DeploymentConfigService } func NewInstalledAppDBServiceImpl(logger *zap.SugaredLogger, @@ -95,7 +95,7 @@ func NewInstalledAppDBServiceImpl(logger *zap.SugaredLogger, UserService: userService, EnvironmentService: environmentService, InstalledAppRepositoryHistory: installedAppRepositoryHistory, - deploymentConfigService: deploymentConfigService, + DeploymentConfigService: deploymentConfigService, } } @@ -209,7 +209,7 @@ func (impl *InstalledAppDBServiceImpl) FindAppDetailsForAppstoreApplication(inst return bean2.AppDetailContainer{}, err } - deploymentConfig, err := impl.deploymentConfigService.GetConfigForHelmApps(installedAppVerison.InstalledApp.AppId, installedAppVerison.InstalledApp.EnvironmentId) + deploymentConfig, err := impl.DeploymentConfigService.GetConfigForHelmApps(installedAppVerison.InstalledApp.AppId, installedAppVerison.InstalledApp.EnvironmentId) if err != nil { impl.Logger.Errorw("error in getiting deployment config db object by appId and envId", "appId", installedAppVerison.InstalledApp.AppId, "envId", installedAppVerison.InstalledApp.EnvironmentId, "err", err) return bean2.AppDetailContainer{}, err @@ -292,7 +292,7 @@ func (impl *InstalledAppDBServiceImpl) GetInstalledAppByClusterNamespaceAndName( if err != nil { return nil, err } - deploymentConfig, err := impl.deploymentConfigService.GetConfigForHelmApps(installedApp.AppId, installedApp.EnvironmentId) + deploymentConfig, err := impl.DeploymentConfigService.GetConfigForHelmApps(installedApp.AppId, installedApp.EnvironmentId) if err != nil { impl.Logger.Errorw("error in getiting deployment config db object by appId and envId", "appId", installedApp.AppId, "envId", installedApp.EnvironmentId, "err", err) return nil, err @@ -309,7 +309,7 @@ func (impl *InstalledAppDBServiceImpl) GetInstalledAppByInstalledAppId(installed return nil, err } installedApp := &installedAppVersion.InstalledApp - deploymentConfig, err := impl.deploymentConfigService.GetConfigForHelmApps(installedApp.AppId, installedApp.EnvironmentId) + deploymentConfig, err := impl.DeploymentConfigService.GetConfigForHelmApps(installedApp.AppId, installedApp.EnvironmentId) if err != nil { impl.Logger.Errorw("error in getiting deployment config db object by appId and envId", "appId", installedApp.AppId, "envId", installedApp.EnvironmentId, "err", err) return nil, err @@ -326,7 +326,7 @@ func (impl *InstalledAppDBServiceImpl) GetInstalledAppVersion(id int, userId int impl.Logger.Errorw("error while fetching from db", "error", err) return nil, err } - deploymentConfig, err := impl.deploymentConfigService.GetConfigForHelmApps(model.InstalledApp.AppId, model.InstalledApp.EnvironmentId) + deploymentConfig, err := impl.DeploymentConfigService.GetConfigForHelmApps(model.InstalledApp.AppId, model.InstalledApp.EnvironmentId) if err != nil { impl.Logger.Errorw("error in getiting deployment config db object by appId and envId", "appId", model.InstalledApp.AppId, "envId", model.InstalledApp.EnvironmentId, "err", err) return nil, err @@ -370,7 +370,7 @@ func (impl *InstalledAppDBServiceImpl) GetInstalledAppVersionByIdIncludeDeleted( impl.Logger.Errorw("error while fetching from db", "error", err) return nil, err } - deploymentConfig, err := impl.deploymentConfigService.GetConfigForHelmApps(model.InstalledApp.AppId, model.InstalledApp.EnvironmentId) + deploymentConfig, err := impl.DeploymentConfigService.GetConfigForHelmApps(model.InstalledApp.AppId, model.InstalledApp.EnvironmentId) if err != nil { impl.Logger.Errorw("error in getiting deployment config db object by appId and envId", "appId", model.InstalledApp.AppId, "envId", model.InstalledApp.EnvironmentId, "err", err) return nil, err diff --git a/pkg/appStore/installedApp/service/FullMode/InstalledAppDBExtendedService.go b/pkg/appStore/installedApp/service/FullMode/InstalledAppDBExtendedService.go index 79d8e11684..aa8347bf73 100644 --- a/pkg/appStore/installedApp/service/FullMode/InstalledAppDBExtendedService.go +++ b/pkg/appStore/installedApp/service/FullMode/InstalledAppDBExtendedService.go @@ -92,6 +92,15 @@ func (impl *InstalledAppDBExtendedServiceImpl) UpdateInstalledAppVersionStatus(a } func (impl *InstalledAppDBExtendedServiceImpl) IsGitOpsRepoAlreadyRegistered(repoUrl string) (bool, error) { + + deploymentConfig, err := impl.InstalledAppDBServiceImpl.DeploymentConfigService.GetAllConfigsWithCustomGitOpsURL() + for _, dc := range deploymentConfig { + if dc.GetRepoURL() == repoUrl { + impl.Logger.Warnw("repository is already in use for helm app", "repoUrl", repoUrl) + return true, nil + } + } + repoName := impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(repoUrl) installedAppModel, err := impl.InstalledAppRepository.GetInstalledAppByGitRepoUrl(repoName, repoUrl) if err != nil && !util.IsErrNoRows(err) { diff --git a/pkg/chart/ChartService.go b/pkg/chart/ChartService.go index 5e44e90fee..3db122b375 100644 --- a/pkg/chart/ChartService.go +++ b/pkg/chart/ChartService.go @@ -1063,6 +1063,15 @@ func (impl *ChartServiceImpl) ConfigureGitOpsRepoUrlForApp(appId int, repoUrl, c //} func (impl *ChartServiceImpl) IsGitOpsRepoAlreadyRegistered(gitOpsRepoUrl string) (bool, error) { + + deploymentConfig, err := impl.deploymentConfigService.GetAllConfigsWithCustomGitOpsURL() + for _, dc := range deploymentConfig { + if dc.GetRepoURL() == gitOpsRepoUrl { + impl.logger.Warnw("repository is already in use for helm app", "repoUrl", gitOpsRepoUrl) + return true, nil + } + } + chartModel, err := impl.chartRepository.FindChartByGitRepoUrl(gitOpsRepoUrl) if err != nil && !util.IsErrNoRows(err) { impl.logger.Errorw("error in fetching chartModel", "repoUrl", gitOpsRepoUrl, "err", err) diff --git a/pkg/deployment/common/bean/bean.go b/pkg/deployment/common/bean/bean.go index 7365089c26..abec603e2f 100644 --- a/pkg/deployment/common/bean/bean.go +++ b/pkg/deployment/common/bean/bean.go @@ -164,7 +164,10 @@ type DeploymentConfig struct { } func (c *DeploymentConfig) GetRepoURL() string { - return c.ReleaseConfiguration.ArgoCDSpec.Spec.Source.RepoURL + if c.ReleaseConfiguration != nil { + return c.ReleaseConfiguration.ArgoCDSpec.Spec.Source.RepoURL + } + return "" } func (c *DeploymentConfig) GetChartLocation() string { diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index 55e2687a94..4f4c510c56 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -32,6 +32,7 @@ type DeploymentConfigService interface { GetAndMigrateConfigIfAbsentForHelmApp(appId, envId int) (*bean.DeploymentConfig, error) UpdateRepoUrlForAppAndEnvId(repoURL string, appId, envId int) error GetDeploymentAppTypeForCDInBulk(pipelines []*pipelineConfig.Pipeline) (map[int]string, error) + GetAllConfigsWithCustomGitOpsURL() ([]*bean.DeploymentConfig, error) } type DeploymentConfigServiceImpl struct { @@ -644,3 +645,21 @@ func (impl *DeploymentConfigServiceImpl) GetDeploymentAppTypeForCDInBulk(pipelin } return resp, nil } + +func (impl *DeploymentConfigServiceImpl) GetAllConfigsWithCustomGitOpsURL() ([]*bean.DeploymentConfig, error) { + dbConfigs, err := impl.deploymentConfigRepository.GetAllConfigsWithCustomGitOpsURL() + if err != nil { + impl.logger.Errorw("error in getting all configs with custom gitops url", "err", err) + return nil, err + } + var configs []*bean.DeploymentConfig + for _, dbConfig := range dbConfigs { + config, err := ConvertDeploymentConfigDbObjToDTO(dbConfig) + if err != nil { + impl.logger.Error("error in converting dbObj to dto", "err", err) + return nil, err + } + configs = append(configs, config) + } + return configs, nil +} From b3024171da882a4c6d360e5ed187cf95c88b801a Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Tue, 21 Jan 2025 03:47:15 +0530 Subject: [PATCH 16/16] fixing import cycle --- internal/sql/repository/AppListingRepository.go | 4 ++-- pkg/deployment/common/{ => adapter}/adapter.go | 2 +- .../common/deploymentConfigService.go | 17 +++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) rename pkg/deployment/common/{ => adapter}/adapter.go (98%) diff --git a/internal/sql/repository/AppListingRepository.go b/internal/sql/repository/AppListingRepository.go index 154916702d..a5097e054a 100644 --- a/internal/sql/repository/AppListingRepository.go +++ b/internal/sql/repository/AppListingRepository.go @@ -30,7 +30,7 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/deploymentConfig" "github.com/devtron-labs/devtron/internal/util" repository2 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" - "github.com/devtron-labs/devtron/pkg/deployment/common" + "github.com/devtron-labs/devtron/pkg/deployment/common/adapter" "go.opentelemetry.io/otel" "strings" "time" @@ -632,7 +632,7 @@ func (impl AppListingRepositoryImpl) FetchAppStageStatus(appId int, appType int) return appStageStatus, err } - dc, err := common.ConvertDeploymentConfigDbObjToDTO(deploymentConfigDB) + dc, err := adapter.ConvertDeploymentConfigDbObjToDTO(deploymentConfigDB) if err != nil { impl.Logger.Errorw("error while converting DeploymentConfigDbObjToDTO", "err", err) return nil, err diff --git a/pkg/deployment/common/adapter.go b/pkg/deployment/common/adapter/adapter.go similarity index 98% rename from pkg/deployment/common/adapter.go rename to pkg/deployment/common/adapter/adapter.go index 1b0be2d896..4ec5c780db 100644 --- a/pkg/deployment/common/adapter.go +++ b/pkg/deployment/common/adapter/adapter.go @@ -1,4 +1,4 @@ -package common +package adapter import ( "encoding/json" diff --git a/pkg/deployment/common/deploymentConfigService.go b/pkg/deployment/common/deploymentConfigService.go index 4f4c510c56..6730addc07 100644 --- a/pkg/deployment/common/deploymentConfigService.go +++ b/pkg/deployment/common/deploymentConfigService.go @@ -16,6 +16,7 @@ import ( bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean" bean4 "github.com/devtron-labs/devtron/pkg/cluster/environment/bean" "github.com/devtron-labs/devtron/pkg/cluster/environment/repository" + "github.com/devtron-labs/devtron/pkg/deployment/common/adapter" "github.com/devtron-labs/devtron/pkg/deployment/common/bean" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/util" @@ -80,7 +81,7 @@ func (impl *DeploymentConfigServiceImpl) CreateOrUpdateConfig(tx *pg.Tx, config "appId", config.AppId, "envId", config.EnvironmentId, "err", err) } - newDBObj, err := ConvertDeploymentConfigDTOToDbObj(config) + newDBObj, err := adapter.ConvertDeploymentConfigDTOToDbObj(config) if err != nil { impl.logger.Errorw("error in converting deployment config DTO to db object", "appId", config.AppId, "envId", config.EnvironmentId) return nil, err @@ -103,7 +104,7 @@ func (impl *DeploymentConfigServiceImpl) CreateOrUpdateConfig(tx *pg.Tx, config return nil, err } } - newObj, err := ConvertDeploymentConfigDbObjToDTO(newDBObj) + newObj, err := adapter.ConvertDeploymentConfigDbObjToDTO(newDBObj) if err != nil { impl.logger.Errorw("error in converting deployment config DTO to db object", "appId", config.AppId, "envId", config.EnvironmentId) return nil, err @@ -157,7 +158,7 @@ func (impl *DeploymentConfigServiceImpl) getAppLevelConfigForDevtronApps(appId i return nil, err } } else { - appLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj) + appLevelConfig, err = adapter.ConvertDeploymentConfigDbObjToDTO(appLevelConfigDbObj) if err != nil { impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) return nil, err @@ -219,7 +220,7 @@ func (impl *DeploymentConfigServiceImpl) getEnvLevelDataForDevtronApps(appId, en } else { // case: deployment config is migrated but release config is absent - appAndEnvLevelConfig, err = ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfigDBObj) + appAndEnvLevelConfig, err = adapter.ConvertDeploymentConfigDbObjToDTO(appAndEnvLevelConfigDBObj) if err != nil { impl.logger.Errorw("error in converting deployment config db object", "appId", appId, "envId", envId, "err", err) return nil, err @@ -466,7 +467,7 @@ func (impl *DeploymentConfigServiceImpl) getConfigForHelmApps(appId int, envId i return nil, err } } else { - helmDeploymentConfig, err = ConvertDeploymentConfigDbObjToDTO(config) + helmDeploymentConfig, err = adapter.ConvertDeploymentConfigDbObjToDTO(config) if err != nil { impl.logger.Errorw("error in converting helm deployment config dbObj to DTO", "appId", appId, "envId", envId, "err", err) return nil, err @@ -497,7 +498,7 @@ func (impl *DeploymentConfigServiceImpl) GetConfigEvenIfInactive(appId, envId in impl.logger.Errorw("error in getting deployment config by appId and envId", "appId", appId, "envId", envId, "err", err) return nil, err } - config, err := ConvertDeploymentConfigDbObjToDTO(dbConfig) + config, err := adapter.ConvertDeploymentConfigDbObjToDTO(dbConfig) if err != nil { impl.logger.Errorw("error in converting deployment config db obj to dto", "appId", appId, "envId", envId, "err", err) return nil, err @@ -602,7 +603,7 @@ func (impl *DeploymentConfigServiceImpl) UpdateRepoUrlForAppAndEnvId(repoURL str return err } - config, err := ConvertDeploymentConfigDbObjToDTO(dbObj) + config, err := adapter.ConvertDeploymentConfigDbObjToDTO(dbObj) if err != nil { impl.logger.Errorw("error in converting deployment config to DTO", "appId", appId, "envId", envId, "err", err) return err @@ -654,7 +655,7 @@ func (impl *DeploymentConfigServiceImpl) GetAllConfigsWithCustomGitOpsURL() ([]* } var configs []*bean.DeploymentConfig for _, dbConfig := range dbConfigs { - config, err := ConvertDeploymentConfigDbObjToDTO(dbConfig) + config, err := adapter.ConvertDeploymentConfigDbObjToDTO(dbConfig) if err != nil { impl.logger.Error("error in converting dbObj to dto", "err", err) return nil, err