Skip to content

Commit 0e67f5b

Browse files
authored
chore: code restructuring (#6476)
* chore: Update Chart type at Base Level refactoring * chore: code restructuring * chore: code restructuring * chore: code restructuring * soft delete support for pipeline_strategy * chore: review comments incorporated * oss ent refactoring * updated pr feedbacks
1 parent c22a646 commit 0e67f5b

35 files changed

+667
-509
lines changed

api/restHandler/CoreAppRestHandler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1847,11 +1847,11 @@ func (handler CoreAppRestHandlerImpl) createEnvDeploymentTemplate(appId int, use
18471847
templateRequest := bean3.TemplateRequest{
18481848
AppId: appId,
18491849
ChartRefId: chartRefId,
1850-
ValuesOverride: []byte("{}"),
1850+
ValuesOverride: util.GetEmptyJSON(),
18511851
UserId: userId,
18521852
IsAppMetricsEnabled: deploymentTemplateOverride.ShowAppMetrics,
18531853
}
1854-
newChartEntry, err := handler.chartService.CreateChartFromEnvOverride(templateRequest, context.Background())
1854+
newChartEntry, err := handler.chartService.CreateChartFromEnvOverride(context.Background(), templateRequest)
18551855
if err != nil {
18561856
handler.logger.Errorw("service err, CreateChartFromEnvOverride", "err", err, "appId", appId, "envId", envId, "chartRefId", chartRefId)
18571857
return err

api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go

+103-163
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2020-2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package configure
18+
19+
type DevtronAppDeploymentConfigRestHandlerEnt interface {
20+
}

api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
read5 "github.com/devtron-labs/devtron/pkg/chart/read"
3131
repository2 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
3232
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics"
33-
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate"
3433
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef"
34+
validator2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/validator"
3535
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning"
3636
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/read"
3737
read3 "github.com/devtron-labs/devtron/pkg/team/read"
@@ -108,7 +108,7 @@ type PipelineConfigRestHandlerImpl struct {
108108
ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository
109109
ciHandler pipeline.CiHandler
110110
Logger *zap.SugaredLogger
111-
deploymentTemplateValidationService deploymentTemplate.DeploymentTemplateValidationService
111+
deploymentTemplateValidationService validator2.DeploymentTemplateValidationService
112112
chartService chart.ChartService
113113
devtronAppGitOpConfigService gitOpsConfig.DevtronAppGitOpConfigService
114114
propertiesConfigService pipeline.PropertiesConfigService
@@ -141,7 +141,7 @@ type PipelineConfigRestHandlerImpl struct {
141141
}
142142

143143
func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger *zap.SugaredLogger,
144-
deploymentTemplateValidationService deploymentTemplate.DeploymentTemplateValidationService,
144+
deploymentTemplateValidationService validator2.DeploymentTemplateValidationService,
145145
chartService chart.ChartService,
146146
devtronAppGitOpConfigService gitOpsConfig.DevtronAppGitOpConfigService,
147147
propertiesConfigService pipeline.PropertiesConfigService,

internal/sql/repository/chartConfig/PipelineConfigRepository.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type PipelineConfigRepository interface {
4242
FindByStrategyAndPipelineId(strategy chartRepoRepository.DeploymentStrategy, pipelineId int) (pipelineStrategy *PipelineStrategy, err error)
4343
GetAllStrategyByPipelineId(pipelineId int) ([]*PipelineStrategy, error)
4444
GetDefaultStrategyByPipelineId(pipelineId int) (pipelineStrategy *PipelineStrategy, err error)
45-
Delete(pipelineStrategy *PipelineStrategy, tx *pg.Tx) error
45+
MarkAsDeleted(pipelineStrategy *PipelineStrategy, userId int32, tx *pg.Tx) error
4646
GetAllStrategyByPipelineIds(pipelineIds []int) ([]*PipelineStrategy, error)
4747
}
4848

@@ -59,33 +59,41 @@ func (impl PipelineConfigRepositoryImpl) Save(pipelineStrategy *PipelineStrategy
5959
}
6060

6161
func (impl PipelineConfigRepositoryImpl) Update(pipelineStrategy *PipelineStrategy, tx *pg.Tx) error {
62-
_, err := impl.dbConnection.Model(pipelineStrategy).WherePK().UpdateNotNull()
62+
_, err := tx.Model(pipelineStrategy).WherePK().UpdateNotNull()
6363
return err
6464
}
6565

6666
func (impl PipelineConfigRepositoryImpl) FindById(id int) (pipelineStrategy *PipelineStrategy, err error) {
6767
pipelineStrategy = &PipelineStrategy{}
6868
err = impl.dbConnection.Model(pipelineStrategy).
69-
Where("id = ?", id).Select()
69+
Where("id = ?", id).
70+
Where("deleted = ?", false).
71+
Select()
7072
return pipelineStrategy, err
7173
}
7274

7375
func (impl PipelineConfigRepositoryImpl) FindByStrategy(strategy chartRepoRepository.DeploymentStrategy) (pipelineStrategy *PipelineStrategy, err error) {
7476
pipelineStrategy = &PipelineStrategy{}
7577
err = impl.dbConnection.Model(pipelineStrategy).
76-
Where("strategy = ?", strategy).Select()
78+
Where("strategy = ?", strategy).
79+
Where("deleted = ?", false).
80+
Select()
7781
return pipelineStrategy, err
7882
}
7983

8084
func (impl PipelineConfigRepositoryImpl) FindByStrategyAndPipelineId(strategy chartRepoRepository.DeploymentStrategy, pipelineId int) (pipelineStrategy *PipelineStrategy, err error) {
8185
pipelineStrategy = &PipelineStrategy{}
8286
err = impl.dbConnection.Model(pipelineStrategy).
8387
Where("strategy = ?", strategy).
84-
Where("pipeline_id = ?", pipelineId).Select()
88+
Where("pipeline_id = ?", pipelineId).
89+
Where("deleted = ?", false).
90+
Select()
8591
return pipelineStrategy, err
8692
}
8793

88-
// it will return for multiple pipeline config for pipeline, per pipeline single pipeline config(blue green, canary)
94+
// GetAllStrategyByPipelineId -
95+
// it will return for multiple pipeline strategies for a pipeline
96+
// per pipeline single pipeline strategy (BLUE_GREEN, CANARY, ROLLING, RECREATE) can be there
8997
func (impl PipelineConfigRepositoryImpl) GetAllStrategyByPipelineId(pipelineId int) ([]*PipelineStrategy, error) {
9098
var pipelineStrategies []*PipelineStrategy
9199
err := impl.dbConnection.
@@ -99,7 +107,8 @@ func (impl PipelineConfigRepositoryImpl) GetAllStrategyByPipelineId(pipelineId i
99107
return pipelineStrategies, err
100108
}
101109

102-
// it will return single latest pipeline config for requested pipeline
110+
// GetDefaultStrategyByPipelineId -
111+
// it will return single latest pipeline strategy for the requested pipeline
103112
func (impl PipelineConfigRepositoryImpl) GetDefaultStrategyByPipelineId(pipelineId int) (pipelineStrategy *PipelineStrategy, err error) {
104113
pipelineStrategy = &PipelineStrategy{}
105114
err = impl.dbConnection.
@@ -114,8 +123,12 @@ func (impl PipelineConfigRepositoryImpl) GetDefaultStrategyByPipelineId(pipeline
114123
return pipelineStrategy, err
115124
}
116125

117-
func (impl PipelineConfigRepositoryImpl) Delete(pipelineStrategy *PipelineStrategy, tx *pg.Tx) error {
118-
return tx.Delete(pipelineStrategy)
126+
// MarkAsDeleted -
127+
// it will soft-delete the pipeline strategy from the database
128+
func (impl PipelineConfigRepositoryImpl) MarkAsDeleted(pipelineStrategy *PipelineStrategy, userId int32, tx *pg.Tx) error {
129+
pipelineStrategy.Deleted = true
130+
pipelineStrategy.UpdateAuditLog(userId)
131+
return impl.Update(pipelineStrategy, tx)
119132
}
120133

121134
func (impl PipelineConfigRepositoryImpl) GetAllStrategyByPipelineIds(pipelineIds []int) ([]*PipelineStrategy, error) {

internal/sql/repository/chartConfig/mocks/PipelineConfigRepository.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/util/ChartTemplateService.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type ChartCreateResponse struct {
6363
}
6464

6565
type ChartTemplateService interface {
66-
FetchValuesFromReferenceChart(chartMetaData *chart.Metadata, refChartLocation string, templateName string, userId int32, pipelineStrategyPath string) (*ChartValues, error)
66+
FetchValuesFromReferenceChart(chartMetaData *chart.Metadata, refChartLocation string, pipelineStrategyPath string) (*ChartValues, error)
6767
GetChartVersion(location string) (string, error)
6868
BuildChart(ctx context.Context, chartMetaData *chart.Metadata, referenceTemplatePath string) (string, error)
6969
BuildChartProxyForHelmApps(chartCreateRequest *ChartCreateRequest) (chartCreateResponse *ChartCreateResponse, err error)
@@ -116,7 +116,7 @@ func (impl ChartTemplateServiceImpl) GetChartVersion(location string) (string, e
116116
return chartContent.Version, nil
117117
}
118118

119-
func (impl ChartTemplateServiceImpl) FetchValuesFromReferenceChart(chartMetaData *chart.Metadata, refChartLocation string, templateName string, userId int32, pipelineStrategyPath string) (*ChartValues, error) {
119+
func (impl ChartTemplateServiceImpl) FetchValuesFromReferenceChart(chartMetaData *chart.Metadata, refChartLocation string, pipelineStrategyPath string) (*ChartValues, error) {
120120
chartMetaData.APIVersion = "v1" // ensure always v1
121121
dir := impl.GetDir()
122122
chartDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)

pkg/app/AppService.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ type AppServiceImpl struct {
128128

129129
type AppService interface {
130130
UpdateReleaseStatus(request *bean.ReleaseStatusUpdateRequest) (bool, error)
131-
GetConfigMapAndSecretJson(appId int, envId int, pipelineId int) ([]byte, error)
131+
// Deprecated: GetConfigMapAndSecretJson
132+
GetConfigMapAndSecretJson(appId int, envId int) ([]byte, error)
132133
UpdateCdWorkflowRunnerByACDObject(app *v1alpha1.Application, cdWfrId int, updateTimedOutStatus bool) error
133134
UpdateDeploymentStatusForGitOpsPipelines(app *v1alpha1.Application, applicationClusterId int, statusTime time.Time, isAppStore bool) (bool, bool, *chartConfig.PipelineOverride, error)
134135
WriteCDSuccessEvent(appId int, envId int, override *chartConfig.PipelineOverride)
@@ -807,15 +808,14 @@ func (impl *AppServiceImpl) CreateGitOpsRepo(app *app.App, targetRevision string
807808
return gitOpsRepoName, chartGitAttr, nil
808809
}
809810

810-
// depricated
811-
// TODO remove this method
812-
func (impl *AppServiceImpl) GetConfigMapAndSecretJson(appId int, envId int, pipelineId int) ([]byte, error) {
811+
// GetConfigMapAndSecretJson TODO remove this method
812+
func (impl *AppServiceImpl) GetConfigMapAndSecretJson(appId int, envId int) ([]byte, error) {
813813
var configMapJson string
814814
var secretDataJson string
815-
merged := []byte("{}")
815+
merged := globalUtil.GetEmptyJSON()
816816
configMapA, err := impl.configMapRepository.GetByAppIdAppLevel(appId)
817817
if err != nil && pg.ErrNoRows != err {
818-
return []byte("{}"), err
818+
return merged, err
819819
}
820820
if configMapA != nil && configMapA.Id > 0 {
821821
configMapJson = configMapA.ConfigMapData
@@ -828,17 +828,17 @@ func (impl *AppServiceImpl) GetConfigMapAndSecretJson(appId int, envId int, pipe
828828
}
829829
config, err := impl.mergeUtil.JsonPatch([]byte(configMapJson), []byte(secretDataJson))
830830
if err != nil {
831-
return []byte("{}"), err
831+
return merged, err
832832
}
833833
merged, err = impl.mergeUtil.JsonPatch(merged, config)
834834
if err != nil {
835-
return []byte("{}"), err
835+
return merged, err
836836
}
837837
}
838838

839839
configMapE, err := impl.configMapRepository.GetByAppIdAndEnvIdEnvLevel(appId, envId)
840840
if err != nil && pg.ErrNoRows != err {
841-
return []byte("{}"), err
841+
return globalUtil.GetEmptyJSON(), err
842842
}
843843
if configMapE != nil && configMapE.Id > 0 {
844844
configMapJson = configMapE.ConfigMapData
@@ -851,11 +851,11 @@ func (impl *AppServiceImpl) GetConfigMapAndSecretJson(appId int, envId int, pipe
851851
}
852852
config, err := impl.mergeUtil.JsonPatch([]byte(configMapJson), []byte(secretDataJson))
853853
if err != nil {
854-
return []byte("{}"), err
854+
return merged, err
855855
}
856856
merged, err = impl.mergeUtil.JsonPatch(merged, config)
857857
if err != nil {
858-
return []byte("{}"), err
858+
return merged, err
859859
}
860860
}
861861

pkg/appClone/AppCloneService.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/config"
4040
"github.com/devtron-labs/devtron/pkg/pipeline"
4141
bean3 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
42+
globalUtil "github.com/devtron-labs/devtron/util"
4243
"github.com/go-pg/pg"
4344
"go.uber.org/zap"
4445
"net/http"
@@ -528,12 +529,12 @@ func (impl *AppCloneServiceImpl) createEnvOverride(oldAppId, newAppId int, userI
528529
templateRequest := bean5.TemplateRequest{
529530
AppId: newAppId,
530531
ChartRefId: envPropertiesReq.ChartRefId,
531-
ValuesOverride: []byte("{}"),
532+
ValuesOverride: globalUtil.GetEmptyJSON(),
532533
UserId: userId,
533534
IsBasicViewLocked: envPropertiesReq.IsBasicViewLocked,
534535
CurrentViewEditor: envPropertiesReq.CurrentViewEditor,
535536
}
536-
_, err = impl.chartService.CreateChartFromEnvOverride(templateRequest, ctx)
537+
_, err = impl.chartService.CreateChartFromEnvOverride(ctx, templateRequest)
537538
if err != nil {
538539
impl.logger.Error(err)
539540
return nil, nil

pkg/appClone/batch/Deployment_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func Test_transformStrategy(t *testing.T) {
110110
},
111111
bean.Strategy{
112112
DeploymentTemplate: "RECREATE",
113-
Config: []byte("{}"),
113+
Config: globalUtil.GetEmptyJSON(),
114114
Default: false,
115115
}},
116116
wantErr: false,

0 commit comments

Comments
 (0)