Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/argoApplication/wire_argoApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ package argoApplication
import (
"github.com/devtron-labs/devtron/pkg/argoApplication"
"github.com/devtron-labs/devtron/pkg/argoApplication/read"
"github.com/devtron-labs/devtron/pkg/argoApplication/read/config"
"github.com/google/wire"
)

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

config.NewArgoApplicationConfigServiceImpl,
wire.Bind(new(config.ArgoApplicationConfigService), new(*config.ArgoApplicationConfigServiceImpl)),

argoApplication.NewArgoApplicationServiceExtendedServiceImpl,
wire.Bind(new(argoApplication.ArgoApplicationService), new(*argoApplication.ArgoApplicationServiceExtendedImpl)),

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

config.NewArgoApplicationConfigServiceImpl,
wire.Bind(new(config.ArgoApplicationConfigService), new(*config.ArgoApplicationConfigServiceImpl)),

argoApplication.NewArgoApplicationServiceImpl,
wire.Bind(new(argoApplication.ArgoApplicationService), new(*argoApplication.ArgoApplicationServiceImpl)),

Expand Down
60 changes: 21 additions & 39 deletions api/helm-app/service/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/api/helm-app/models"
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
"github.com/devtron-labs/devtron/api/helm-app/service/read"
"github.com/devtron-labs/devtron/internal/constants"
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
"github.com/go-pg/pg"
Expand Down Expand Up @@ -82,7 +83,6 @@ type HelmAppService interface {
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, request *bean.UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error)
IsReleaseInstalled(ctx context.Context, app *helmBean.AppIdentifier) (bool, error)
RollbackRelease(ctx context.Context, app *helmBean.AppIdentifier, version int32) (bool, error)
GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error)
GetDevtronHelmAppIdentifier() *helmBean.AppIdentifier
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *helmBean.AppIdentifier, chartRepository *gRPC.ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
Expand All @@ -109,6 +109,7 @@ type HelmAppServiceImpl struct {
clusterRepository clusterRepository.ClusterRepository
K8sUtil *k8s.K8sServiceImpl
helmReleaseConfig *HelmReleaseConfig
helmAppReadService read.HelmAppReadService
}

func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.ClusterService,
Expand All @@ -118,7 +119,8 @@ func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.Clu
environmentService cluster.EnvironmentService, pipelineRepository pipelineConfig.PipelineRepository,
installedAppRepository repository.InstalledAppRepository, appRepository app.AppRepository,
clusterRepository clusterRepository.ClusterRepository, K8sUtil *k8s.K8sServiceImpl,
helmReleaseConfig *HelmReleaseConfig) *HelmAppServiceImpl {
helmReleaseConfig *HelmReleaseConfig,
helmAppReadService read.HelmAppReadService) *HelmAppServiceImpl {
return &HelmAppServiceImpl{
logger: Logger,
clusterService: clusterService,
Expand All @@ -135,6 +137,7 @@ func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.Clu
clusterRepository: clusterRepository,
K8sUtil: K8sUtil,
helmReleaseConfig: helmReleaseConfig,
helmAppReadService: helmAppReadService,
}
}

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

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

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

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

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

func (impl *HelmAppServiceImpl) GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error) {
cluster, err := impl.clusterService.FindById(clusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return nil, err
}
config := &gRPC.ClusterConfig{
ApiServerUrl: cluster.ServerUrl,
Token: cluster.Config[commonBean.BearerToken],
ClusterId: int32(cluster.Id),
ClusterName: cluster.ClusterName,
InsecureSkipTLSVerify: cluster.InsecureSkipTLSVerify,
}
if cluster.InsecureSkipTLSVerify == false {
config.KeyData = cluster.Config[commonBean.TlsKey]
config.CertData = cluster.Config[commonBean.CertData]
config.CaData = cluster.Config[commonBean.CertificateAuthorityData]
}
return config, nil
}

func (impl *HelmAppServiceImpl) GetApplicationDetail(ctx context.Context, app *helmBean.AppIdentifier) (*gRPC.AppDetail, error) {
return impl.getApplicationDetail(ctx, app, nil)
}
Expand All @@ -261,7 +243,7 @@ func (impl *HelmAppServiceImpl) GetApplicationDetailWithFilter(ctx context.Conte
}

func (impl *HelmAppServiceImpl) getApplicationDetail(ctx context.Context, app *helmBean.AppIdentifier, resourceTreeFilter *gRPC.ResourceTreeFilter) (*gRPC.AppDetail, error) {
config, err := impl.GetClusterConf(app.ClusterId)
config, err := impl.helmAppReadService.GetClusterConf(app.ClusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return nil, err
Expand Down Expand Up @@ -301,7 +283,7 @@ func (impl *HelmAppServiceImpl) GetResourceTreeForExternalResources(ctx context.
var config *gRPC.ClusterConfig
var err error
if clusterId > 0 {
config, err = impl.GetClusterConf(clusterId)
config, err = impl.helmAppReadService.GetClusterConf(clusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return nil, err
Expand All @@ -317,7 +299,7 @@ func (impl *HelmAppServiceImpl) GetResourceTreeForExternalResources(ctx context.
}

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

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

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

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

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

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

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

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

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

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

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

config, err := impl.GetClusterConf(clusterId)
config, err := impl.helmAppReadService.GetClusterConf(clusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
return nil, err
Expand Down
47 changes: 47 additions & 0 deletions api/helm-app/service/read/HelmAppReadService.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package read

import (
"github.com/devtron-labs/common-lib/utils/k8s/commonBean"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/pkg/cluster"
"go.uber.org/zap"
)

type HelmAppReadServiceImpl struct {
logger *zap.SugaredLogger
clusterService cluster.ClusterService
}

type HelmAppReadService interface {
GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error)
}

func NewHelmAppReadServiceImpl(logger *zap.SugaredLogger,
clusterService cluster.ClusterService,
) *HelmAppReadServiceImpl {
return &HelmAppReadServiceImpl{
clusterService: clusterService,
logger: logger,
}
}

func (impl *HelmAppReadServiceImpl) GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error) {
cluster, err := impl.clusterService.FindById(clusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return nil, err
}
config := &gRPC.ClusterConfig{
ApiServerUrl: cluster.ServerUrl,
Token: cluster.Config[commonBean.BearerToken],
ClusterId: int32(cluster.Id),
ClusterName: cluster.ClusterName,
InsecureSkipTLSVerify: cluster.InsecureSkipTLSVerify,
}
if cluster.InsecureSkipTLSVerify == false {
config.KeyData = cluster.Config[commonBean.TlsKey]
config.CertData = cluster.Config[commonBean.CertData]
config.CaData = cluster.Config[commonBean.CertificateAuthorityData]
}
return config, nil
}
3 changes: 3 additions & 0 deletions api/helm-app/wire_helmApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
grpcUtil "github.com/devtron-labs/common-lib/utils/grpc"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/api/helm-app/service/read"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/google/wire"
)
Expand All @@ -31,6 +32,8 @@ var HelmAppWireSet = wire.NewSet(
service.GetHelmReleaseConfig,
service.NewHelmAppServiceImpl,
wire.Bind(new(service.HelmAppService), new(*service.HelmAppServiceImpl)),
read.NewHelmAppReadServiceImpl,
wire.Bind(new(read.HelmAppReadService), new(*read.HelmAppReadServiceImpl)),
NewHelmAppRestHandlerImpl,
wire.Bind(new(HelmAppRestHandler), new(*HelmAppRestHandlerImpl)),
NewHelmAppRouterImpl,
Expand Down
10 changes: 5 additions & 5 deletions api/restHandler/app/appList/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
k8sObjectUtils "github.com/devtron-labs/common-lib/utils/k8sObjectsUtil"
"github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
client "github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/api/helm-app/service/read"
"github.com/devtron-labs/devtron/api/restHandler/common"
util3 "github.com/devtron-labs/devtron/api/util"
"github.com/devtron-labs/devtron/client/argocdServer/application"
Expand Down Expand Up @@ -100,7 +100,7 @@ type AppListingRestHandlerImpl struct {
userService user.UserService
// TODO fix me next
helmAppClient gRPC.HelmAppClient // TODO refactoring: use HelmAppService
helmAppService client.HelmAppService
helmAppReadService read.HelmAppReadService
argoUserService argo.ArgoUserService
k8sCommonService k8s.K8sCommonService
installedAppService FullMode.InstalledAppDBExtendedService
Expand Down Expand Up @@ -136,7 +136,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
pipeline pipeline.PipelineBuilder,
logger *zap.SugaredLogger, enforcerUtil rbac.EnforcerUtil,
deploymentGroupService deploymentGroup.DeploymentGroupService, userService user.UserService,
helmAppClient gRPC.HelmAppClient, helmAppService client.HelmAppService,
helmAppClient gRPC.HelmAppClient, helmAppReadService read.HelmAppReadService,
argoUserService argo.ArgoUserService, k8sCommonService k8s.K8sCommonService,
installedAppService FullMode.InstalledAppDBExtendedService,
installedAppResourceService resource.InstalledAppResourceService,
Expand All @@ -159,7 +159,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
deploymentGroupService: deploymentGroupService,
userService: userService,
helmAppClient: helmAppClient,
helmAppService: helmAppService,
helmAppReadService: helmAppReadService,
argoUserService: argoUserService,
k8sCommonService: k8sCommonService,
installedAppService: installedAppService,
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter
}()

} else if len(cdPipeline.DeploymentAppName) > 0 && cdPipeline.EnvironmentId > 0 && util.IsHelmApp(deploymentConfig.DeploymentAppType) {
config, err := handler.helmAppService.GetClusterConf(cdPipeline.Environment.ClusterId)
config, err := handler.helmAppReadService.GetClusterConf(cdPipeline.Environment.ClusterId)
if err != nil {
handler.logger.Errorw("error in fetching cluster detail", "err", err)
}
Expand Down
Loading