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
6 changes: 3 additions & 3 deletions api/helm-app/HelmAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (handler *HelmAppRestHandlerImpl) DeleteApplication(w http.ResponseWriter,
}

func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter, r *http.Request) {
request := &openapi.UpdateReleaseRequest{}
request := &UpdateApplicationRequestDto{}
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(request)
if err != nil {
Expand All @@ -336,9 +336,9 @@ func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter,
return
}
//RBAC enforcer Ends

request.SourceAppType = SOURCE_EXTERNAL_HELM_APP
// update application externally
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request, API_CALLER_EXTERNAL_HELM_APP)
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand Down
57 changes: 25 additions & 32 deletions api/helm-app/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ import (
"time"
)

const (
DEFAULT_CLUSTER = "default_cluster"
DEFAULT_CLUSTER_ID = 1
API_CALLER_DEVTRON_APP ApiCallerAppType = "devtron-app"
API_CALLER_HELM_APP ApiCallerAppType = "helm-app"
API_CALLER_EXTERNAL_HELM_APP ApiCallerAppType = "external-helm-app"
API_CALLER_UNKNOWN ApiCallerAppType = "unknown"
)

type ApiCallerAppType string

type HelmAppService interface {
ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool)
GetApplicationDetail(ctx context.Context, app *AppIdentifier) (*AppDetail, error)
Expand All @@ -60,18 +49,18 @@ type HelmAppService interface {
GetValuesYaml(ctx context.Context, app *AppIdentifier) (*ReleaseInfo, error)
GetDesiredManifest(ctx context.Context, app *AppIdentifier, resource *openapi.ResourceIdentifier) (*openapi.DesiredManifestResponse, error)
DeleteApplication(ctx context.Context, app *AppIdentifier) (*openapi.UninstallReleaseResponse, error)
UpdateApplication(ctx context.Context, app *AppIdentifier, request *openapi.UpdateReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error)
UpdateApplication(ctx context.Context, app *AppIdentifier, request *UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error)
GetDeploymentDetail(ctx context.Context, app *AppIdentifier, version int32) (*openapi.HelmAppDeploymentManifestDetail, error)
InstallRelease(ctx context.Context, clusterId int, installReleaseRequest *InstallReleaseRequest) (*InstallReleaseResponse, error)
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, updateReleaseRequest *InstallReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error)
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, request *UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error)
IsReleaseInstalled(ctx context.Context, app *AppIdentifier) (bool, error)
RollbackRelease(ctx context.Context, app *AppIdentifier, version int32) (bool, error)
GetClusterConf(clusterId int) (*ClusterConfig, error)
GetDevtronHelmAppIdentifier() *AppIdentifier
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *AppIdentifier, chartRepository *ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
GetNotes(ctx context.Context, request *InstallReleaseRequest) (string, error)
GetRevisionHistoryMaxValue(appType ApiCallerAppType) int32
GetRevisionHistoryMaxValue(appType SourceAppType) int32
}

type HelmAppServiceImpl struct {
Expand Down Expand Up @@ -439,7 +428,7 @@ func (impl *HelmAppServiceImpl) DeleteApplication(ctx context.Context, app *AppI
return response, nil
}

func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *AppIdentifier, request *openapi.UpdateReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error) {
func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *AppIdentifier, request *UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error) {
config, err := impl.GetClusterConf(app.ClusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "clusterId", app.ClusterId, "err", err)
Expand All @@ -453,7 +442,7 @@ func (impl *HelmAppServiceImpl) UpdateApplication(ctx context.Context, app *AppI
ReleaseNamespace: app.Namespace,
},
ValuesYaml: request.GetValuesYaml(),
HistoryMax: impl.GetRevisionHistoryMaxValue(apiCallerAppType),
HistoryMax: impl.GetRevisionHistoryMaxValue(request.SourceAppType),
}

updateApplicationResponse, err := impl.helmAppClient.UpdateApplication(ctx, req)
Expand Down Expand Up @@ -517,16 +506,16 @@ func (impl *HelmAppServiceImpl) InstallRelease(ctx context.Context, clusterId in
}

func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfo(ctx context.Context, clusterId int,
updateReleaseRequest *InstallReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error) {
request *UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error) {
config, err := impl.GetClusterConf(clusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
return nil, err
}
updateReleaseRequest.HistoryMax = impl.GetRevisionHistoryMaxValue(apiCallerAppType)
updateReleaseRequest.ReleaseIdentifier.ClusterConfig = config
request.HistoryMax = impl.GetRevisionHistoryMaxValue(request.SourceAppType)
request.ReleaseIdentifier.ClusterConfig = config

updateReleaseResponse, err := impl.helmAppClient.UpdateApplicationWithChartInfo(ctx, updateReleaseRequest)
updateReleaseResponse, err := impl.helmAppClient.UpdateApplicationWithChartInfo(ctx, request.InstallReleaseRequest)
if err != nil {
impl.logger.Errorw("error in installing release", "err", err)
return nil, err
Expand Down Expand Up @@ -668,20 +657,24 @@ func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfoWithExtraValues(ct
}

// update in helm
updateReleaseRequest := &InstallReleaseRequest{
ReleaseIdentifier: &ReleaseIdentifier{
ReleaseName: appIdentifier.ReleaseName,
ReleaseNamespace: appIdentifier.Namespace,

updateReleaseRequest := &UpdateApplicationWithChartInfoRequestDto{
InstallReleaseRequest: &InstallReleaseRequest{
ReleaseIdentifier: &ReleaseIdentifier{
ReleaseName: appIdentifier.ReleaseName,
ReleaseNamespace: appIdentifier.Namespace,
},
ChartName: releaseInfo.DeployedAppDetail.ChartName,
ValuesYaml: string(mergedValuesYamlByteArr),
ChartRepository: chartRepository,
},
ChartName: releaseInfo.DeployedAppDetail.ChartName,
ValuesYaml: string(mergedValuesYamlByteArr),
ChartRepository: chartRepository,
SourceAppType: SOURCE_UNKNOWN,
}
if !useLatestChartVersion {
updateReleaseRequest.ChartVersion = releaseInfo.DeployedAppDetail.ChartVersion
}

updateResponse, err := impl.UpdateApplicationWithChartInfo(ctx, appIdentifier.ClusterId, updateReleaseRequest, API_CALLER_UNKNOWN)
updateResponse, err := impl.UpdateApplicationWithChartInfo(ctx, appIdentifier.ClusterId, updateReleaseRequest)
if err != nil {
impl.logger.Errorw("error in upgrading release", "err", err)
return nil, err
Expand Down Expand Up @@ -885,13 +878,13 @@ func (impl *HelmAppServiceImpl) appListRespProtoTransformer(deployedApps *Deploy
return appList
}

func (impl *HelmAppServiceImpl) GetRevisionHistoryMaxValue(appType ApiCallerAppType) int32 {
func (impl *HelmAppServiceImpl) GetRevisionHistoryMaxValue(appType SourceAppType) int32 {
switch appType {
case API_CALLER_DEVTRON_APP:
case SOURCE_DEVTRON_APP:
return int32(impl.helmReleaseConfig.RevisionHistoryLimitDevtronApp)
case API_CALLER_HELM_APP:
case SOURCE_HELM_APP:
return int32(impl.helmReleaseConfig.RevisionHistoryLimitHelmApp)
case API_CALLER_EXTERNAL_HELM_APP:
case SOURCE_EXTERNAL_HELM_APP:
return int32(impl.helmReleaseConfig.RevisionHistoryLimitExternalHelmApp)
default:
return 0
Expand Down
24 changes: 24 additions & 0 deletions api/helm-app/bean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package client

import openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"

const (
DEFAULT_CLUSTER = "default_cluster"
DEFAULT_CLUSTER_ID = 1
SOURCE_DEVTRON_APP SourceAppType = "devtron-app"
SOURCE_HELM_APP SourceAppType = "helm-app"
SOURCE_EXTERNAL_HELM_APP SourceAppType = "external-helm-app"
SOURCE_UNKNOWN SourceAppType = "unknown"
)

type SourceAppType string

type UpdateApplicationRequestDto struct {
*openapi.UpdateReleaseRequest
SourceAppType SourceAppType `json:"-"`
}

type UpdateApplicationWithChartInfoRequestDto struct {
*InstallReleaseRequest
SourceAppType SourceAppType `json:"-"`
}
2 changes: 1 addition & 1 deletion pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ func (impl *AppServiceImpl) createHelmAppForCdPipeline(overrideRequest *bean.Val
req := &client2.UpgradeReleaseRequest{
ReleaseIdentifier: releaseIdentifier,
ValuesYaml: mergeAndSave,
HistoryMax: impl.helmAppService.GetRevisionHistoryMaxValue(client2.API_CALLER_DEVTRON_APP),
HistoryMax: impl.helmAppService.GetRevisionHistoryMaxValue(client2.SOURCE_DEVTRON_APP),
}

updateApplicationResponse, err := impl.helmAppClient.UpdateApplication(ctx, req)
Expand Down
31 changes: 17 additions & 14 deletions pkg/appStore/deployment/service/AppStoreDeploymentService.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,22 +894,25 @@ func (impl AppStoreDeploymentServiceImpl) linkHelmApplicationToChartStore(instal

// STEP-2 update APP with chart info
chartRepoInfo := appStoreAppVersion.AppStore.ChartRepo
updateReleaseRequest := &client.InstallReleaseRequest{
ValuesYaml: installAppVersionRequest.ValuesOverrideYaml,
ChartName: appStoreAppVersion.Name,
ChartVersion: appStoreAppVersion.Version,
ReleaseIdentifier: &client.ReleaseIdentifier{
ReleaseNamespace: installAppVersionRequest.Namespace,
ReleaseName: installAppVersionRequest.AppName,
},
ChartRepository: &client.ChartRepository{
Name: chartRepoInfo.Name,
Url: chartRepoInfo.Url,
Username: chartRepoInfo.UserName,
Password: chartRepoInfo.Password,
updateReleaseRequest := &client.UpdateApplicationWithChartInfoRequestDto{
InstallReleaseRequest: &client.InstallReleaseRequest{
ValuesYaml: installAppVersionRequest.ValuesOverrideYaml,
ChartName: appStoreAppVersion.Name,
ChartVersion: appStoreAppVersion.Version,
ReleaseIdentifier: &client.ReleaseIdentifier{
ReleaseNamespace: installAppVersionRequest.Namespace,
ReleaseName: installAppVersionRequest.AppName,
},
ChartRepository: &client.ChartRepository{
Name: chartRepoInfo.Name,
Url: chartRepoInfo.Url,
Username: chartRepoInfo.UserName,
Password: chartRepoInfo.Password,
},
},
SourceAppType: client.SOURCE_HELM_APP,
}
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installAppVersionRequest.ClusterId, updateReleaseRequest, client.API_CALLER_HELM_APP)
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installAppVersionRequest.ClusterId, updateReleaseRequest)
if err != nil {
return nil, err
}
Expand Down
31 changes: 17 additions & 14 deletions pkg/appStore/deployment/tool/AppStoreDeploymentHelmService.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,25 @@ func (impl *AppStoreDeploymentHelmServiceImpl) updateApplicationWithChartInfo(ct

chartRepo := appStoreApplicationVersion.AppStore.ChartRepo

updateReleaseRequest := &client.InstallReleaseRequest{
ValuesYaml: valuesOverrideYaml,
ReleaseIdentifier: &client.ReleaseIdentifier{
ReleaseNamespace: installedApp.Environment.Namespace,
ReleaseName: installedApp.App.AppName,
},
ChartName: appStoreApplicationVersion.Name,
ChartVersion: appStoreApplicationVersion.Version,
ChartRepository: &client.ChartRepository{
Name: chartRepo.Name,
Url: chartRepo.Url,
Username: chartRepo.UserName,
Password: chartRepo.Password,
updateReleaseRequest := &client.UpdateApplicationWithChartInfoRequestDto{
InstallReleaseRequest: &client.InstallReleaseRequest{
ValuesYaml: valuesOverrideYaml,
ReleaseIdentifier: &client.ReleaseIdentifier{
ReleaseNamespace: installedApp.Environment.Namespace,
ReleaseName: installedApp.App.AppName,
},
ChartName: appStoreApplicationVersion.Name,
ChartVersion: appStoreApplicationVersion.Version,
ChartRepository: &client.ChartRepository{
Name: chartRepo.Name,
Url: chartRepo.Url,
Username: chartRepo.UserName,
Password: chartRepo.Password,
},
},
SourceAppType: client.SOURCE_HELM_APP,
}
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installedApp.Environment.ClusterId, updateReleaseRequest, client.API_CALLER_HELM_APP)
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installedApp.Environment.ClusterId, updateReleaseRequest)
if err != nil {
impl.Logger.Errorw("error in updating helm application", "err", err)
return err
Expand Down
6 changes: 5 additions & 1 deletion pkg/webhook/helm/WebhookHelmService.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func (impl WebhookHelmServiceImpl) CreateOrUpdateHelmApplication(ctx context.Con
},
}
if isInstalled {
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, clusterId, installReleaseRequest, client.API_CALLER_HELM_APP)
updateReleaseRequest := &client.UpdateApplicationWithChartInfoRequestDto{
InstallReleaseRequest: installReleaseRequest,
SourceAppType: client.SOURCE_HELM_APP,
}
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, clusterId, updateReleaseRequest)
if err != nil {
impl.logger.Errorw("Error in updating helm release", "appIdentifier", appIdentifier, "err", err)
return nil, common.InternalServerError, err.Error(), http.StatusInternalServerError
Expand Down