|
6 | 6 | "fmt" |
7 | 7 | "github.com/devtron-labs/devtron/api/connector" |
8 | 8 | openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient" |
| 9 | + openapi2 "github.com/devtron-labs/devtron/api/openapi/openapiClient" |
9 | 10 | "github.com/devtron-labs/devtron/client/k8s/application" |
| 11 | + appStoreDiscoverRepository "github.com/devtron-labs/devtron/pkg/appStore/discover/repository" |
10 | 12 | "github.com/devtron-labs/devtron/pkg/cluster" |
11 | 13 | serverBean "github.com/devtron-labs/devtron/pkg/server/bean" |
12 | 14 | serverEnvConfig "github.com/devtron-labs/devtron/pkg/server/config" |
@@ -47,31 +49,37 @@ type HelmAppService interface { |
47 | 49 | GetClusterConf(clusterId int) (*ClusterConfig, error) |
48 | 50 | GetDevtronHelmAppIdentifier() *AppIdentifier |
49 | 51 | UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *AppIdentifier, chartRepository *ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error) |
| 52 | + TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error) |
50 | 53 | } |
51 | 54 |
|
52 | 55 | type HelmAppServiceImpl struct { |
53 | | - logger *zap.SugaredLogger |
54 | | - clusterService cluster.ClusterService |
55 | | - helmAppClient HelmAppClient |
56 | | - pump connector.Pump |
57 | | - enforcerUtil rbac.EnforcerUtilHelm |
58 | | - serverDataStore *serverDataStore.ServerDataStore |
59 | | - serverEnvConfig *serverEnvConfig.ServerEnvConfig |
| 56 | + logger *zap.SugaredLogger |
| 57 | + clusterService cluster.ClusterService |
| 58 | + helmAppClient HelmAppClient |
| 59 | + pump connector.Pump |
| 60 | + enforcerUtil rbac.EnforcerUtilHelm |
| 61 | + serverDataStore *serverDataStore.ServerDataStore |
| 62 | + serverEnvConfig *serverEnvConfig.ServerEnvConfig |
| 63 | + appStoreApplicationVersionRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository |
| 64 | + environmentService cluster.EnvironmentService |
60 | 65 | } |
61 | 66 |
|
62 | 67 | func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, |
63 | 68 | clusterService cluster.ClusterService, |
64 | 69 | helmAppClient HelmAppClient, |
65 | 70 | pump connector.Pump, enforcerUtil rbac.EnforcerUtilHelm, serverDataStore *serverDataStore.ServerDataStore, |
66 | | - serverEnvConfig *serverEnvConfig.ServerEnvConfig) *HelmAppServiceImpl { |
| 71 | + serverEnvConfig *serverEnvConfig.ServerEnvConfig, appStoreApplicationVersionRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository, |
| 72 | + environmentService cluster.EnvironmentService) *HelmAppServiceImpl { |
67 | 73 | return &HelmAppServiceImpl{ |
68 | | - logger: Logger, |
69 | | - clusterService: clusterService, |
70 | | - helmAppClient: helmAppClient, |
71 | | - pump: pump, |
72 | | - enforcerUtil: enforcerUtil, |
73 | | - serverDataStore: serverDataStore, |
74 | | - serverEnvConfig: serverEnvConfig, |
| 74 | + logger: Logger, |
| 75 | + clusterService: clusterService, |
| 76 | + helmAppClient: helmAppClient, |
| 77 | + pump: pump, |
| 78 | + enforcerUtil: enforcerUtil, |
| 79 | + serverDataStore: serverDataStore, |
| 80 | + serverEnvConfig: serverEnvConfig, |
| 81 | + appStoreApplicationVersionRepository: appStoreApplicationVersionRepository, |
| 82 | + environmentService: environmentService, |
75 | 83 | } |
76 | 84 | } |
77 | 85 |
|
@@ -575,6 +583,65 @@ func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfoWithExtraValues(ct |
575 | 583 | return response, nil |
576 | 584 | } |
577 | 585 |
|
| 586 | +func (impl *HelmAppServiceImpl) TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error) { |
| 587 | + appStoreApplicationVersionId := int(*templateChartRequest.AppStoreApplicationVersionId) |
| 588 | + environmentId := int(*templateChartRequest.EnvironmentId) |
| 589 | + appStoreAppVersion, err := impl.appStoreApplicationVersionRepository.FindById(appStoreApplicationVersionId) |
| 590 | + if err != nil { |
| 591 | + impl.logger.Errorw("Error in fetching app-store application version", "appStoreApplicationVersionId", appStoreApplicationVersionId, "err", err) |
| 592 | + return nil, err |
| 593 | + } |
| 594 | + |
| 595 | + if environmentId > 0 { |
| 596 | + environment, err := impl.environmentService.FindById(environmentId) |
| 597 | + if err != nil { |
| 598 | + impl.logger.Errorw("Error in fetching environment", "environmentId", environmentId, "err", err) |
| 599 | + return nil, err |
| 600 | + } |
| 601 | + templateChartRequest.Namespace = &environment.Namespace |
| 602 | + clusterIdI32 := int32(environment.ClusterId) |
| 603 | + templateChartRequest.ClusterId = &clusterIdI32 |
| 604 | + } |
| 605 | + |
| 606 | + clusterId := int(*templateChartRequest.ClusterId) |
| 607 | + |
| 608 | + installReleaseRequest := &InstallReleaseRequest{ |
| 609 | + ChartName: appStoreAppVersion.Name, |
| 610 | + ChartVersion: appStoreAppVersion.Version, |
| 611 | + ValuesYaml: *templateChartRequest.ValuesYaml, |
| 612 | + ChartRepository: &ChartRepository{ |
| 613 | + Name: appStoreAppVersion.AppStore.ChartRepo.Name, |
| 614 | + Url: appStoreAppVersion.AppStore.ChartRepo.Url, |
| 615 | + Username: appStoreAppVersion.AppStore.ChartRepo.UserName, |
| 616 | + Password: appStoreAppVersion.AppStore.ChartRepo.Password, |
| 617 | + }, |
| 618 | + ReleaseIdentifier: &ReleaseIdentifier{ |
| 619 | + ReleaseNamespace: *templateChartRequest.Namespace, |
| 620 | + ReleaseName: *templateChartRequest.ReleaseName, |
| 621 | + }, |
| 622 | + } |
| 623 | + |
| 624 | + config, err := impl.GetClusterConf(clusterId) |
| 625 | + if err != nil { |
| 626 | + impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err) |
| 627 | + return nil, err |
| 628 | + } |
| 629 | + |
| 630 | + installReleaseRequest.ReleaseIdentifier.ClusterConfig = config |
| 631 | + |
| 632 | + templateChartResponse, err := impl.helmAppClient.TemplateChart(ctx, installReleaseRequest) |
| 633 | + if err != nil { |
| 634 | + impl.logger.Errorw("error in templating chart", "err", err) |
| 635 | + return nil, err |
| 636 | + } |
| 637 | + |
| 638 | + response := &openapi2.TemplateChartResponse{ |
| 639 | + Manifest: &templateChartResponse.GeneratedManifest, |
| 640 | + } |
| 641 | + |
| 642 | + return response, nil |
| 643 | +} |
| 644 | + |
578 | 645 | type AppIdentifier struct { |
579 | 646 | ClusterId int `json:"clusterId"` |
580 | 647 | Namespace string `json:"namespace"` |
|
0 commit comments