Skip to content

Commit 5272d9e

Browse files
kartik-579nishant-dAsh-exp
authored
chore: Refactoring deployment template GitOps (#4615)
* removed registerInArgo multiple impls * extracted app metrics code * migrated envLevel app metrics code to new service * chore: Removed unused jira and migration integration (#4498) * removed unsued jira integration * removed test-suite-code * db migration conf removal * chore: removed unused injection * chore: removed dead code * added: migration script --------- Co-authored-by: Ash-exp <[email protected]> * chore: App store dead code cleanup and restructuring (#4497) * moved chart-group in seperate code * removed unused dependency * removed dead code * extracted resource tree * moved notes * resource movement * removed unused code * removed unused dependency * commit methods * extracted status update * chore: clean up unused dead code * updated: EA mode docker file * updated: migration number --------- Co-authored-by: Ash-exp <[email protected]> * chart ref refactoring * removed infra metrics db calls * moved app metrics repositories from /internal to /pkg * moved: const and types to bean * removed: unused const * review comments * migrated some methods from chartService to chartRefService * added dt validation service interface * minor refactoring * moved validation method - 1 * wip * removed redundant appMetrics req obj * moved app metrics bindings to wireset * removed multiple dead code * remove redundant dependency * moved ChartGroup router and rest handler to respective folder * gitOps refactoring * moved gitClient code to a common wrapper service * review changes * wip * fix for unsupported charts * minor cleanup * renamed remote package to git * renamed gitOpsRemoteOpService If and impl * migrated usages of gitService to gitOperationService * shifted git service and all gitOps clients to pkg * gitops repository usages refactor * refactored gitOpsRepository usages * gitlab client creation refactoring * renamed util/ChartService * reverted renaming changes * reverted renaming changes * reverted renaming changes * wip * wip * removed typo * changes * changes --------- Co-authored-by: Nishant <[email protected]> Co-authored-by: Ash-exp <[email protected]>
1 parent 88328c2 commit 5272d9e

File tree

87 files changed

+3432
-3984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3432
-3984
lines changed

Wire.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import (
8787
"github.com/devtron-labs/devtron/pkg/appClone"
8888
"github.com/devtron-labs/devtron/pkg/appClone/batch"
8989
"github.com/devtron-labs/devtron/pkg/appStatus"
90-
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
9190
"github.com/devtron-labs/devtron/pkg/appStore/chartGroup"
9291
repository4 "github.com/devtron-labs/devtron/pkg/appStore/chartGroup/repository"
9392
appStoreDeploymentFullMode "github.com/devtron-labs/devtron/pkg/appStore/deployment/fullMode"
@@ -100,6 +99,8 @@ import (
10099
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
101100
"github.com/devtron-labs/devtron/pkg/commonService"
102101
delete2 "github.com/devtron-labs/devtron/pkg/delete"
102+
deployment2 "github.com/devtron-labs/devtron/pkg/deployment"
103+
git2 "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git"
103104
"github.com/devtron-labs/devtron/pkg/deploymentGroup"
104105
"github.com/devtron-labs/devtron/pkg/devtronResource"
105106
repository9 "github.com/devtron-labs/devtron/pkg/devtronResource/repository"
@@ -161,6 +162,8 @@ func InitializeApp() (*App, error) {
161162
apiToken.ApiTokenWireSet,
162163
webhookHelm.WebhookHelmWireSet,
163164
terminal.TerminalWireSet,
165+
deployment2.DeploymentWireSet,
166+
164167
// -------wireset end ----------
165168
//-------
166169
gitSensor.GetConfig,
@@ -174,10 +177,6 @@ func InitializeApp() (*App, error) {
174177
//sql.NewDbConnection,
175178
//app.GetACDAuthConfig,
176179
util3.GetACDAuthConfig,
177-
wire.Value(chartRepoRepository.RefChartDir("scripts/devtron-reference-helm-charts")),
178-
wire.Value(appStoreBean.RefChartProxyDir("scripts/devtron-reference-helm-charts")),
179-
wire.Value(chart.DefaultChart("reference-app-rolling")),
180-
wire.Value(util.ChartWorkingDir("/tmp/charts/")),
181180
connection.SettingsManager,
182181
//auth.GetConfig,
183182

@@ -265,8 +264,6 @@ func InitializeApp() (*App, error) {
265264

266265
util.NewChartTemplateServiceImpl,
267266
wire.Bind(new(util.ChartTemplateService), new(*util.ChartTemplateServiceImpl)),
268-
util.NewChartDeploymentServiceImpl,
269-
wire.Bind(new(util.ChartDeploymentService), new(*util.ChartDeploymentServiceImpl)),
270267

271268
//scoped variables start
272269
variables.NewScopedVariableServiceImpl,
@@ -335,8 +332,6 @@ func InitializeApp() (*App, error) {
335332
eClient.NewEventRESTClientImpl,
336333
wire.Bind(new(eClient.EventClient), new(*eClient.EventRESTClientImpl)),
337334

338-
util3.NewTokenCache,
339-
340335
eClient.NewEventSimpleFactoryImpl,
341336
wire.Bind(new(eClient.EventFactory), new(*eClient.EventSimpleFactoryImpl)),
342337

@@ -353,7 +348,7 @@ func InitializeApp() (*App, error) {
353348
wire.Bind(new(pipelineConfig.CiPipelineRepository), new(*pipelineConfig.CiPipelineRepositoryImpl)),
354349
pipelineConfig.NewCiPipelineMaterialRepositoryImpl,
355350
wire.Bind(new(pipelineConfig.CiPipelineMaterialRepository), new(*pipelineConfig.CiPipelineMaterialRepositoryImpl)),
356-
util.NewGitFactory,
351+
git2.NewGitFactory,
357352

358353
application.NewApplicationClientImpl,
359354
wire.Bind(new(application.ServiceClient), new(*application.ServiceClientImpl)),
@@ -527,11 +522,6 @@ func InitializeApp() (*App, error) {
527522

528523
restHandler.NewExternalCiRestHandlerImpl,
529524
wire.Bind(new(restHandler.ExternalCiRestHandler), new(*restHandler.ExternalCiRestHandlerImpl)),
530-
repository.NewAppLevelMetricsRepositoryImpl,
531-
wire.Bind(new(repository.AppLevelMetricsRepository), new(*repository.AppLevelMetricsRepositoryImpl)),
532-
533-
repository.NewEnvLevelAppMetricsRepositoryImpl,
534-
wire.Bind(new(repository.EnvLevelAppMetricsRepository), new(*repository.EnvLevelAppMetricsRepositoryImpl)),
535525

536526
grafana.GetGrafanaClientConfig,
537527
grafana.NewGrafanaClientImpl,
@@ -649,8 +639,6 @@ func InitializeApp() (*App, error) {
649639
wire.Bind(new(restHandler.GitOpsConfigRestHandler), new(*restHandler.GitOpsConfigRestHandlerImpl)),
650640
gitops.NewGitOpsConfigServiceImpl,
651641
wire.Bind(new(gitops.GitOpsConfigService), new(*gitops.GitOpsConfigServiceImpl)),
652-
repository.NewGitOpsConfigRepositoryImpl,
653-
wire.Bind(new(repository.GitOpsConfigRepository), new(*repository.GitOpsConfigRepositoryImpl)),
654642

655643
router.NewAttributesRouterImpl,
656644
wire.Bind(new(router.AttributesRouter), new(*router.AttributesRouterImpl)),
@@ -671,7 +659,7 @@ func InitializeApp() (*App, error) {
671659
scopedVariable.NewScopedVariableRestHandlerImpl,
672660
wire.Bind(new(scopedVariable.ScopedVariableRestHandler), new(*scopedVariable.ScopedVariableRestHandlerImpl)),
673661

674-
util.NewGitCliUtil,
662+
git2.NewGitCliUtil,
675663

676664
router.NewTelemetryRouterImpl,
677665
wire.Bind(new(router.TelemetryRouter), new(*router.TelemetryRouterImpl)),

api/chartRepo/ChartRepositoryRestHandler.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
3131
"github.com/devtron-labs/devtron/pkg/auth/user"
3232
"github.com/devtron-labs/devtron/pkg/chartRepo"
33-
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
3433
delete2 "github.com/devtron-labs/devtron/pkg/delete"
3534
"github.com/gorilla/mux"
3635
"go.uber.org/zap"
@@ -64,23 +63,19 @@ type ChartRepositoryRestHandlerImpl struct {
6463
enforcer casbin.Enforcer
6564
validator *validator.Validate
6665
deleteService delete2.DeleteService
67-
chartRefRepository chartRepoRepository.ChartRefRepository
68-
refChartDir chartRepoRepository.RefChartDir
6966
attributesService attributes.AttributesService
7067
}
7168

7269
func NewChartRepositoryRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService, chartRepositoryService chartRepo.ChartRepositoryService,
7370
enforcer casbin.Enforcer, validator *validator.Validate, deleteService delete2.DeleteService,
74-
chartRefRepository chartRepoRepository.ChartRefRepository, refChartDir chartRepoRepository.RefChartDir, attributesService attributes.AttributesService) *ChartRepositoryRestHandlerImpl {
71+
attributesService attributes.AttributesService) *ChartRepositoryRestHandlerImpl {
7572
return &ChartRepositoryRestHandlerImpl{
7673
Logger: Logger,
7774
chartRepositoryService: chartRepositoryService,
7875
userAuthService: userAuthService,
7976
enforcer: enforcer,
8077
validator: validator,
8178
deleteService: deleteService,
82-
chartRefRepository: chartRefRepository,
83-
refChartDir: refChartDir,
8479
attributesService: attributesService,
8580
}
8681
}

api/deployment/DeploymentConfigRestHandler.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package deployment
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef"
7+
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean"
68
"io/ioutil"
79
"net/http"
810
"os"
@@ -15,12 +17,10 @@ import (
1517
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
1618
"github.com/devtron-labs/devtron/pkg/auth/user"
1719
"github.com/devtron-labs/devtron/pkg/chart"
18-
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
1920
"github.com/devtron-labs/devtron/pkg/sql"
2021
"github.com/gorilla/mux"
2122
"github.com/juju/errors"
2223
"go.uber.org/zap"
23-
"gopkg.in/go-playground/validator.v9"
2424
)
2525

2626
type DeploymentConfigRestHandler interface {
@@ -31,13 +31,11 @@ type DeploymentConfigRestHandler interface {
3131
}
3232

3333
type DeploymentConfigRestHandlerImpl struct {
34-
Logger *zap.SugaredLogger
35-
userAuthService user.UserService
36-
enforcer casbin.Enforcer
37-
validator *validator.Validate
38-
refChartDir chartRepoRepository.RefChartDir
39-
chartService chart.ChartService
40-
chartRefRepository chartRepoRepository.ChartRefRepository
34+
Logger *zap.SugaredLogger
35+
userAuthService user.UserService
36+
enforcer casbin.Enforcer
37+
chartService chart.ChartService
38+
chartRefService chartRef.ChartRefService
4139
}
4240

4341
type DeploymentChartInfo struct {
@@ -49,16 +47,14 @@ type DeploymentChartInfo struct {
4947
Message string `json:"message"`
5048
}
5149

52-
func NewDeploymentConfigRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService, enforcer casbin.Enforcer, validator *validator.Validate,
53-
refChartDir chartRepoRepository.RefChartDir, chartService chart.ChartService, chartRefRepository chartRepoRepository.ChartRefRepository) *DeploymentConfigRestHandlerImpl {
50+
func NewDeploymentConfigRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService, enforcer casbin.Enforcer,
51+
chartService chart.ChartService, chartRefService chartRef.ChartRefService) *DeploymentConfigRestHandlerImpl {
5452
return &DeploymentConfigRestHandlerImpl{
55-
Logger: Logger,
56-
userAuthService: userAuthService,
57-
enforcer: enforcer,
58-
validator: validator,
59-
refChartDir: refChartDir,
60-
chartService: chartService,
61-
chartRefRepository: chartRefRepository,
53+
Logger: Logger,
54+
userAuthService: userAuthService,
55+
enforcer: enforcer,
56+
chartService: chartService,
57+
chartRefService: chartRefService,
6258
}
6359
}
6460

@@ -88,7 +84,7 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo
8884
return
8985
}
9086

91-
err = handler.chartService.ValidateUploadedFileFormat(fileHeader.Filename)
87+
err = handler.chartRefService.ValidateCustomChartUploadedFileFormat(fileHeader.Filename)
9288
if err != nil {
9389
handler.Logger.Errorw("request err, Unsupported format", "err", err, "payload", file)
9490
common.WriteJsonResp(w, errors.New("Unsupported format file is uploaded, please upload file with .tgz extension"), nil, http.StatusBadRequest)
@@ -102,7 +98,7 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo
10298
return
10399
}
104100

105-
chartInfo, err := handler.chartService.ExtractChartIfMissing(fileBytes, string(handler.refChartDir), "")
101+
chartInfo, err := handler.chartRefService.ExtractChartIfMissing(fileBytes, bean.RefChartDirPath, "")
106102

107103
if err != nil {
108104
if chartInfo != nil && chartInfo.TemporaryFolder != "" {
@@ -111,15 +107,15 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo
111107
handler.Logger.Errorw("error in deleting temp dir ", "err", err1)
112108
}
113109
}
114-
if err.Error() == chart.CHART_ALREADY_EXISTS_INTERNAL_ERROR || err.Error() == chart.CHART_NAME_RESERVED_INTERNAL_ERROR {
110+
if err.Error() == bean.ChartAlreadyExistsInternalError || err.Error() == bean.ChartNameReservedInternalError {
115111
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
116112
return
117113
}
118114
common.WriteJsonResp(w, fmt.Errorf(err.Error()), nil, http.StatusBadRequest)
119115
return
120116
}
121117

122-
chartRefs := &chartRepoRepository.ChartRef{
118+
chartRefs := &bean.CustomChartRefDto{
123119
Name: chartInfo.ChartName,
124120
Version: chartInfo.ChartVersion,
125121
Location: chartInfo.ChartLocation,
@@ -178,25 +174,25 @@ func (handler *DeploymentConfigRestHandlerImpl) SaveChart(w http.ResponseWriter,
178174
return
179175
}
180176

181-
location := filepath.Join(string(handler.refChartDir), request.FileId)
177+
location := filepath.Join(bean.RefChartDirPath, request.FileId)
182178
if request.Action == "Save" {
183179
file, err := ioutil.ReadFile(filepath.Join(location, "output.json"))
184180
if err != nil {
185181
handler.Logger.Errorw("Error reading output.json", "err", err)
186182
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
187183
return
188184
}
189-
chartRefs := &chartRepoRepository.ChartRef{}
190-
err = json.Unmarshal(file, &chartRefs)
185+
customChartRefDto := &bean.CustomChartRefDto{}
186+
err = json.Unmarshal(file, &customChartRefDto)
191187
if err != nil {
192188
handler.Logger.Errorw("unmarshall err", "err", err)
193189
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
194190
return
195191
}
196-
chartRefs.ChartDescription = request.Description
197-
err = handler.chartRefRepository.Save(chartRefs)
192+
customChartRefDto.ChartDescription = request.Description
193+
err = handler.chartRefService.SaveCustomChart(customChartRefDto)
198194
if err != nil {
199-
handler.Logger.Errorw("error in saving Chart", "err", err)
195+
handler.Logger.Errorw("error in saving Chart", "err", err, "request", customChartRefDto)
200196
common.WriteJsonResp(w, err, "Chart couldn't be saved", http.StatusInternalServerError)
201197
return
202198
}
@@ -234,7 +230,7 @@ func (handler *DeploymentConfigRestHandlerImpl) DownloadChart(w http.ResponseWri
234230
common.WriteJsonResp(w, fmt.Errorf("error in parsing chartRefId : %s must be integer", chartRefId), nil, http.StatusBadRequest)
235231
return
236232
}
237-
manifestByteArr, err := handler.chartService.GetCustomChartInBytes(chartRefId)
233+
manifestByteArr, err := handler.chartRefService.GetChartInBytes(chartRefId)
238234
if err != nil {
239235
handler.Logger.Errorw("error in converting chart to bytes", "err", err)
240236
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -258,7 +254,7 @@ func (handler *DeploymentConfigRestHandlerImpl) GetUploadedCharts(w http.Respons
258254
return
259255
}
260256

261-
charts, err := handler.chartService.FetchCustomChartsInfo()
257+
charts, err := handler.chartRefService.FetchCustomChartsInfo()
262258
if err != nil {
263259
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
264260
return

api/restHandler/BatchOperationRestHandler.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,3 @@ func validatePipeline(pipeline *v1.Pipeline, props v1.InheritedProps) error {
145145
}
146146
return nil
147147
}
148-
149-
func executePipeline(pipeline *v1.Pipeline, props v1.InheritedProps) error {
150-
if pipeline.Build == nil && pipeline.Deployment == nil {
151-
return nil
152-
} else if pipeline.Build != nil {
153-
pipeline.Build.UpdateMissingProps(props)
154-
return validation.ValidateBuild(pipeline.Build)
155-
} else if pipeline.Deployment != nil {
156-
//return batch.ExecuteDeployment(pipeline.Deployment, props)
157-
}
158-
return nil
159-
}

api/restHandler/ChartRefRestHandler.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ package restHandler
1919

2020
import (
2121
"github.com/devtron-labs/devtron/api/restHandler/common"
22-
"github.com/devtron-labs/devtron/pkg/chart"
22+
chartService "github.com/devtron-labs/devtron/pkg/chart"
23+
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef"
2324
"github.com/gorilla/mux"
2425
"go.uber.org/zap"
2526
"net/http"
@@ -33,17 +34,19 @@ type ChartRefRestHandler interface {
3334
}
3435

3536
type ChartRefRestHandlerImpl struct {
36-
chartService chart.ChartService
37-
logger *zap.SugaredLogger
37+
logger *zap.SugaredLogger
38+
chartRefService chartRef.ChartRefService
39+
chartService chartService.ChartService
3840
}
3941

40-
func NewChartRefRestHandlerImpl(chartService chart.ChartService, logger *zap.SugaredLogger) *ChartRefRestHandlerImpl {
41-
handler := &ChartRefRestHandlerImpl{chartService: chartService, logger: logger}
42+
func NewChartRefRestHandlerImpl(logger *zap.SugaredLogger, chartRefService chartRef.ChartRefService,
43+
chartService chartService.ChartService) *ChartRefRestHandlerImpl {
44+
handler := &ChartRefRestHandlerImpl{logger: logger, chartRefService: chartRefService, chartService: chartService}
4245
return handler
4346
}
4447

4548
func (handler ChartRefRestHandlerImpl) ChartRefAutocomplete(w http.ResponseWriter, r *http.Request) {
46-
result, err := handler.chartService.ChartRefAutocomplete()
49+
result, err := handler.chartRefService.ChartRefAutocomplete()
4750
if err != nil {
4851
handler.logger.Errorw("service err, ChartRefAutocomplete", "err", err)
4952
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

api/restHandler/CommonRestHanlder.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,29 @@ import (
2121
"net/http"
2222

2323
"github.com/devtron-labs/devtron/api/restHandler/common"
24-
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
2524
"github.com/devtron-labs/devtron/pkg/auth/user"
2625
"github.com/devtron-labs/devtron/pkg/commonService"
27-
"github.com/devtron-labs/devtron/pkg/gitops"
2826
"go.uber.org/zap"
29-
"gopkg.in/go-playground/validator.v9"
3027
)
3128

3229
type CommonRestHanlder interface {
3330
GlobalChecklist(w http.ResponseWriter, r *http.Request)
3431
}
3532

3633
type CommonRestHanlderImpl struct {
37-
logger *zap.SugaredLogger
38-
gitOpsConfigService gitops.GitOpsConfigService
39-
userAuthService user.UserService
40-
validator *validator.Validate
41-
enforcer casbin.Enforcer
42-
commonService commonService.CommonService
34+
logger *zap.SugaredLogger
35+
userAuthService user.UserService
36+
commonService commonService.CommonService
4337
}
4438

4539
func NewCommonRestHanlderImpl(
4640
logger *zap.SugaredLogger,
47-
gitOpsConfigService gitops.GitOpsConfigService, userAuthService user.UserService,
48-
validator *validator.Validate, enforcer casbin.Enforcer, commonService commonService.CommonService) *CommonRestHanlderImpl {
41+
userAuthService user.UserService,
42+
commonService commonService.CommonService) *CommonRestHanlderImpl {
4943
return &CommonRestHanlderImpl{
50-
logger: logger,
51-
gitOpsConfigService: gitOpsConfigService,
52-
userAuthService: userAuthService,
53-
validator: validator,
54-
enforcer: enforcer,
55-
commonService: commonService,
44+
logger: logger,
45+
userAuthService: userAuthService,
46+
commonService: commonService,
5647
}
5748
}
5849

0 commit comments

Comments
 (0)