Skip to content

Commit 53c4152

Browse files
authored
Merge branch 'develop' into image-scan
2 parents 69ebc4f + 6cfab58 commit 53c4152

File tree

21 files changed

+415
-321
lines changed

21 files changed

+415
-321
lines changed

api/argoApplication/wire_argoApplication.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ package argoApplication
1919
import (
2020
"github.com/devtron-labs/devtron/pkg/argoApplication"
2121
"github.com/devtron-labs/devtron/pkg/argoApplication/read"
22+
"github.com/devtron-labs/devtron/pkg/argoApplication/read/config"
2223
"github.com/google/wire"
2324
)
2425

2526
var ArgoApplicationWireSetFull = wire.NewSet(
2627
read.NewArgoApplicationReadServiceImpl,
2728
wire.Bind(new(read.ArgoApplicationReadService), new(*read.ArgoApplicationReadServiceImpl)),
2829

30+
config.NewArgoApplicationConfigServiceImpl,
31+
wire.Bind(new(config.ArgoApplicationConfigService), new(*config.ArgoApplicationConfigServiceImpl)),
32+
2933
argoApplication.NewArgoApplicationServiceExtendedServiceImpl,
3034
wire.Bind(new(argoApplication.ArgoApplicationService), new(*argoApplication.ArgoApplicationServiceExtendedImpl)),
3135

@@ -40,6 +44,9 @@ var ArgoApplicationWireSetEA = wire.NewSet(
4044
read.NewArgoApplicationReadServiceImpl,
4145
wire.Bind(new(read.ArgoApplicationReadService), new(*read.ArgoApplicationReadServiceImpl)),
4246

47+
config.NewArgoApplicationConfigServiceImpl,
48+
wire.Bind(new(config.ArgoApplicationConfigService), new(*config.ArgoApplicationConfigServiceImpl)),
49+
4350
argoApplication.NewArgoApplicationServiceImpl,
4451
wire.Bind(new(argoApplication.ArgoApplicationService), new(*argoApplication.ArgoApplicationServiceImpl)),
4552

api/helm-app/service/HelmAppService.go

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
2727
"github.com/devtron-labs/devtron/api/helm-app/models"
2828
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
29+
"github.com/devtron-labs/devtron/api/helm-app/service/read"
2930
"github.com/devtron-labs/devtron/internal/constants"
3031
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
3132
"github.com/go-pg/pg"
@@ -82,7 +83,6 @@ type HelmAppService interface {
8283
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, request *bean.UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error)
8384
IsReleaseInstalled(ctx context.Context, app *helmBean.AppIdentifier) (bool, error)
8485
RollbackRelease(ctx context.Context, app *helmBean.AppIdentifier, version int32) (bool, error)
85-
GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error)
8686
GetDevtronHelmAppIdentifier() *helmBean.AppIdentifier
8787
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *helmBean.AppIdentifier, chartRepository *gRPC.ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
8888
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
@@ -109,6 +109,7 @@ type HelmAppServiceImpl struct {
109109
clusterRepository clusterRepository.ClusterRepository
110110
K8sUtil *k8s.K8sServiceImpl
111111
helmReleaseConfig *HelmReleaseConfig
112+
helmAppReadService read.HelmAppReadService
112113
}
113114

114115
func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.ClusterService,
@@ -118,7 +119,8 @@ func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.Clu
118119
environmentService cluster.EnvironmentService, pipelineRepository pipelineConfig.PipelineRepository,
119120
installedAppRepository repository.InstalledAppRepository, appRepository app.AppRepository,
120121
clusterRepository clusterRepository.ClusterRepository, K8sUtil *k8s.K8sServiceImpl,
121-
helmReleaseConfig *HelmReleaseConfig) *HelmAppServiceImpl {
122+
helmReleaseConfig *HelmReleaseConfig,
123+
helmAppReadService read.HelmAppReadService) *HelmAppServiceImpl {
122124
return &HelmAppServiceImpl{
123125
logger: Logger,
124126
clusterService: clusterService,
@@ -135,6 +137,7 @@ func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.Clu
135137
clusterRepository: clusterRepository,
136138
K8sUtil: K8sUtil,
137139
helmReleaseConfig: helmReleaseConfig,
140+
helmAppReadService: helmAppReadService,
138141
}
139142
}
140143

@@ -191,7 +194,7 @@ func (impl *HelmAppServiceImpl) ListHelmApplications(ctx context.Context, cluste
191194
}
192195

193196
func (impl *HelmAppServiceImpl) HibernateApplication(ctx context.Context, app *helmBean.AppIdentifier, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error) {
194-
conf, err := impl.GetClusterConf(app.ClusterId)
197+
conf, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
195198
if err != nil {
196199

197200
impl.logger.Errorw("HibernateApplication", "error in getting cluster config", "err", err, "clusterId", app.ClusterId)
@@ -210,7 +213,7 @@ func (impl *HelmAppServiceImpl) HibernateApplication(ctx context.Context, app *h
210213

211214
func (impl *HelmAppServiceImpl) UnHibernateApplication(ctx context.Context, app *helmBean.AppIdentifier, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error) {
212215

213-
conf, err := impl.GetClusterConf(app.ClusterId)
216+
conf, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
214217
if err != nil {
215218
impl.logger.Errorw("UnHibernateApplication", "error in getting cluster config", "err", err, "clusterId", app.ClusterId)
216219
return nil, err
@@ -227,27 +230,6 @@ func (impl *HelmAppServiceImpl) UnHibernateApplication(ctx context.Context, app
227230
return response, nil
228231
}
229232

230-
func (impl *HelmAppServiceImpl) GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error) {
231-
cluster, err := impl.clusterService.FindById(clusterId)
232-
if err != nil {
233-
impl.logger.Errorw("error in fetching cluster detail", "err", err)
234-
return nil, err
235-
}
236-
config := &gRPC.ClusterConfig{
237-
ApiServerUrl: cluster.ServerUrl,
238-
Token: cluster.Config[commonBean.BearerToken],
239-
ClusterId: int32(cluster.Id),
240-
ClusterName: cluster.ClusterName,
241-
InsecureSkipTLSVerify: cluster.InsecureSkipTLSVerify,
242-
}
243-
if cluster.InsecureSkipTLSVerify == false {
244-
config.KeyData = cluster.Config[commonBean.TlsKey]
245-
config.CertData = cluster.Config[commonBean.CertData]
246-
config.CaData = cluster.Config[commonBean.CertificateAuthorityData]
247-
}
248-
return config, nil
249-
}
250-
251233
func (impl *HelmAppServiceImpl) GetApplicationDetail(ctx context.Context, app *helmBean.AppIdentifier) (*gRPC.AppDetail, error) {
252234
return impl.getApplicationDetail(ctx, app, nil)
253235
}
@@ -261,7 +243,7 @@ func (impl *HelmAppServiceImpl) GetApplicationDetailWithFilter(ctx context.Conte
261243
}
262244

263245
func (impl *HelmAppServiceImpl) getApplicationDetail(ctx context.Context, app *helmBean.AppIdentifier, resourceTreeFilter *gRPC.ResourceTreeFilter) (*gRPC.AppDetail, error) {
264-
config, err := impl.GetClusterConf(app.ClusterId)
246+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
265247
if err != nil {
266248
impl.logger.Errorw("error in fetching cluster detail", "err", err)
267249
return nil, err
@@ -301,7 +283,7 @@ func (impl *HelmAppServiceImpl) GetResourceTreeForExternalResources(ctx context.
301283
var config *gRPC.ClusterConfig
302284
var err error
303285
if clusterId > 0 {
304-
config, err = impl.GetClusterConf(clusterId)
286+
config, err = impl.helmAppReadService.GetClusterConf(clusterId)
305287
if err != nil {
306288
impl.logger.Errorw("error in fetching cluster detail", "err", err)
307289
return nil, err
@@ -317,7 +299,7 @@ func (impl *HelmAppServiceImpl) GetResourceTreeForExternalResources(ctx context.
317299
}
318300

319301
func (impl *HelmAppServiceImpl) getApplicationAndReleaseStatus(ctx context.Context, app *helmBean.AppIdentifier) (*gRPC.AppStatus, error) {
320-
config, err := impl.GetClusterConf(app.ClusterId)
302+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
321303
if err != nil {
322304
impl.logger.Errorw("error in fetching cluster detail", "err", err)
323305
return nil, err
@@ -336,7 +318,7 @@ func (impl *HelmAppServiceImpl) getApplicationAndReleaseStatus(ctx context.Conte
336318
}
337319

338320
func (impl *HelmAppServiceImpl) GetDeploymentHistory(ctx context.Context, app *helmBean.AppIdentifier) (*gRPC.HelmAppDeploymentHistory, error) {
339-
config, err := impl.GetClusterConf(app.ClusterId)
321+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
340322
if err != nil {
341323
impl.logger.Errorw("error in fetching cluster detail", "err", err)
342324
return nil, err
@@ -358,7 +340,7 @@ func (impl *HelmAppServiceImpl) GetDeploymentHistory(ctx context.Context, app *h
358340
}
359341

360342
func (impl *HelmAppServiceImpl) GetValuesYaml(ctx context.Context, app *helmBean.AppIdentifier) (*gRPC.ReleaseInfo, error) {
361-
config, err := impl.GetClusterConf(app.ClusterId)
343+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
362344
if err != nil {
363345
impl.logger.Errorw("error in fetching cluster detail", "err", err)
364346
return nil, err
@@ -373,7 +355,7 @@ func (impl *HelmAppServiceImpl) GetValuesYaml(ctx context.Context, app *helmBean
373355
}
374356

375357
func (impl *HelmAppServiceImpl) GetDesiredManifest(ctx context.Context, app *helmBean.AppIdentifier, resource *openapi.ResourceIdentifier) (*openapi.DesiredManifestResponse, error) {
376-
config, err := impl.GetClusterConf(app.ClusterId)
358+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
377359
if err != nil {
378360
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
379361
return nil, err
@@ -561,7 +543,7 @@ func (impl *HelmAppServiceImpl) DeleteDBLinkedHelmApplication(ctx context.Contex
561543
}
562544

563545
func (impl *HelmAppServiceImpl) DeleteApplication(ctx context.Context, app *helmBean.AppIdentifier) (*openapi.UninstallReleaseResponse, error) {
564-
config, err := impl.GetClusterConf(app.ClusterId)
546+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
565547
if err != nil {
566548
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
567549
return nil, err
@@ -624,7 +606,7 @@ func (impl *HelmAppServiceImpl) checkIfNsExists(namespace string, clusterBean *c
624606
}
625607

626608
func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *helmBean.AppIdentifier, request *bean.UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error) {
627-
config, err := impl.GetClusterConf(app.ClusterId)
609+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
628610
if err != nil {
629611
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
630612
return nil, err
@@ -653,7 +635,7 @@ func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *helm
653635
}
654636

655637
func (impl *HelmAppServiceImpl) GetDeploymentDetail(ctx context.Context, app *helmBean.AppIdentifier, version int32) (*openapi.HelmAppDeploymentManifestDetail, error) {
656-
config, err := impl.GetClusterConf(app.ClusterId)
638+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
657639
if err != nil {
658640
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
659641
return nil, err
@@ -683,7 +665,7 @@ func (impl *HelmAppServiceImpl) GetDeploymentDetail(ctx context.Context, app *he
683665
}
684666

685667
func (impl *HelmAppServiceImpl) InstallRelease(ctx context.Context, clusterId int, installReleaseRequest *gRPC.InstallReleaseRequest) (*gRPC.InstallReleaseResponse, error) {
686-
config, err := impl.GetClusterConf(clusterId)
668+
config, err := impl.helmAppReadService.GetClusterConf(clusterId)
687669
if err != nil {
688670
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
689671
return nil, err
@@ -702,7 +684,7 @@ func (impl *HelmAppServiceImpl) InstallRelease(ctx context.Context, clusterId in
702684

703685
func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfo(ctx context.Context, clusterId int,
704686
request *bean.UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error) {
705-
config, err := impl.GetClusterConf(clusterId)
687+
config, err := impl.helmAppReadService.GetClusterConf(clusterId)
706688
if err != nil {
707689
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
708690
return nil, err
@@ -724,7 +706,7 @@ func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfo(ctx context.Conte
724706
}
725707

726708
func (impl *HelmAppServiceImpl) IsReleaseInstalled(ctx context.Context, app *helmBean.AppIdentifier) (bool, error) {
727-
config, err := impl.GetClusterConf(app.ClusterId)
709+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
728710
if err != nil {
729711
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
730712
return false, err
@@ -746,7 +728,7 @@ func (impl *HelmAppServiceImpl) IsReleaseInstalled(ctx context.Context, app *hel
746728
}
747729

748730
func (impl *HelmAppServiceImpl) RollbackRelease(ctx context.Context, app *helmBean.AppIdentifier, version int32) (bool, error) {
749-
config, err := impl.GetClusterConf(app.ClusterId)
731+
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
750732
if err != nil {
751733
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
752734
return false, err
@@ -979,7 +961,7 @@ func (impl *HelmAppServiceImpl) TemplateChart(ctx context.Context, templateChart
979961
RegistryCredential: registryCredential,
980962
}
981963

982-
config, err := impl.GetClusterConf(clusterId)
964+
config, err := impl.helmAppReadService.GetClusterConf(clusterId)
983965
if err != nil {
984966
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
985967
return nil, err
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package read
2+
3+
import (
4+
"github.com/devtron-labs/common-lib/utils/k8s/commonBean"
5+
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
6+
"github.com/devtron-labs/devtron/pkg/cluster"
7+
"go.uber.org/zap"
8+
)
9+
10+
type HelmAppReadServiceImpl struct {
11+
logger *zap.SugaredLogger
12+
clusterService cluster.ClusterService
13+
}
14+
15+
type HelmAppReadService interface {
16+
GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error)
17+
}
18+
19+
func NewHelmAppReadServiceImpl(logger *zap.SugaredLogger,
20+
clusterService cluster.ClusterService,
21+
) *HelmAppReadServiceImpl {
22+
return &HelmAppReadServiceImpl{
23+
clusterService: clusterService,
24+
logger: logger,
25+
}
26+
}
27+
28+
func (impl *HelmAppReadServiceImpl) GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error) {
29+
cluster, err := impl.clusterService.FindById(clusterId)
30+
if err != nil {
31+
impl.logger.Errorw("error in fetching cluster detail", "err", err)
32+
return nil, err
33+
}
34+
config := &gRPC.ClusterConfig{
35+
ApiServerUrl: cluster.ServerUrl,
36+
Token: cluster.Config[commonBean.BearerToken],
37+
ClusterId: int32(cluster.Id),
38+
ClusterName: cluster.ClusterName,
39+
InsecureSkipTLSVerify: cluster.InsecureSkipTLSVerify,
40+
}
41+
if cluster.InsecureSkipTLSVerify == false {
42+
config.KeyData = cluster.Config[commonBean.TlsKey]
43+
config.CertData = cluster.Config[commonBean.CertData]
44+
config.CaData = cluster.Config[commonBean.CertificateAuthorityData]
45+
}
46+
return config, nil
47+
}

api/helm-app/wire_helmApp.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
grpcUtil "github.com/devtron-labs/common-lib/utils/grpc"
2121
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
2222
"github.com/devtron-labs/devtron/api/helm-app/service"
23+
"github.com/devtron-labs/devtron/api/helm-app/service/read"
2324
"github.com/devtron-labs/devtron/util/rbac"
2425
"github.com/google/wire"
2526
)
@@ -31,6 +32,8 @@ var HelmAppWireSet = wire.NewSet(
3132
service.GetHelmReleaseConfig,
3233
service.NewHelmAppServiceImpl,
3334
wire.Bind(new(service.HelmAppService), new(*service.HelmAppServiceImpl)),
35+
read.NewHelmAppReadServiceImpl,
36+
wire.Bind(new(read.HelmAppReadService), new(*read.HelmAppReadServiceImpl)),
3437
NewHelmAppRestHandlerImpl,
3538
wire.Bind(new(HelmAppRestHandler), new(*HelmAppRestHandlerImpl)),
3639
NewHelmAppRouterImpl,

api/restHandler/app/appList/AppListingRestHandler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
k8sObjectUtils "github.com/devtron-labs/common-lib/utils/k8sObjectsUtil"
2929
"github.com/devtron-labs/devtron/api/bean"
3030
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
31-
client "github.com/devtron-labs/devtron/api/helm-app/service"
31+
"github.com/devtron-labs/devtron/api/helm-app/service/read"
3232
"github.com/devtron-labs/devtron/api/restHandler/common"
3333
util3 "github.com/devtron-labs/devtron/api/util"
3434
"github.com/devtron-labs/devtron/client/argocdServer/application"
@@ -100,7 +100,7 @@ type AppListingRestHandlerImpl struct {
100100
userService user.UserService
101101
// TODO fix me next
102102
helmAppClient gRPC.HelmAppClient // TODO refactoring: use HelmAppService
103-
helmAppService client.HelmAppService
103+
helmAppReadService read.HelmAppReadService
104104
argoUserService argo.ArgoUserService
105105
k8sCommonService k8s.K8sCommonService
106106
installedAppService FullMode.InstalledAppDBExtendedService
@@ -136,7 +136,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
136136
pipeline pipeline.PipelineBuilder,
137137
logger *zap.SugaredLogger, enforcerUtil rbac.EnforcerUtil,
138138
deploymentGroupService deploymentGroup.DeploymentGroupService, userService user.UserService,
139-
helmAppClient gRPC.HelmAppClient, helmAppService client.HelmAppService,
139+
helmAppClient gRPC.HelmAppClient, helmAppReadService read.HelmAppReadService,
140140
argoUserService argo.ArgoUserService, k8sCommonService k8s.K8sCommonService,
141141
installedAppService FullMode.InstalledAppDBExtendedService,
142142
installedAppResourceService resource.InstalledAppResourceService,
@@ -159,7 +159,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
159159
deploymentGroupService: deploymentGroupService,
160160
userService: userService,
161161
helmAppClient: helmAppClient,
162-
helmAppService: helmAppService,
162+
helmAppReadService: helmAppReadService,
163163
argoUserService: argoUserService,
164164
k8sCommonService: k8sCommonService,
165165
installedAppService: installedAppService,
@@ -1024,7 +1024,7 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter
10241024
}()
10251025

10261026
} else if len(cdPipeline.DeploymentAppName) > 0 && cdPipeline.EnvironmentId > 0 && util.IsHelmApp(deploymentConfig.DeploymentAppType) {
1027-
config, err := handler.helmAppService.GetClusterConf(cdPipeline.Environment.ClusterId)
1027+
config, err := handler.helmAppReadService.GetClusterConf(cdPipeline.Environment.ClusterId)
10281028
if err != nil {
10291029
handler.logger.Errorw("error in fetching cluster detail", "err", err)
10301030
}

0 commit comments

Comments
 (0)