Skip to content

Commit 59b6b16

Browse files
kartik-579kripanshdevtronpawan-59
authored
Oss sync (#181)
* feat: Approval node scripts (#3345) * approval node scripts * go template with missing key handling * approver param added * reverted TPrintf func * approver param type change * script number updated * script version update * script number updated * enhancement: made revision history limit configurable for helm upgrade (#3353) * made revision history limit configurable for helm upgrade * review changes * updated fieldName * renamed constS * added deployment_strategy_ref_mapping_removal (#3362) * task: changes for kubelink update application requests (#3359) * changes for kubelink - update application requests * added bean.go --------- Co-authored-by: kripanshdevtron <[email protected]> Co-authored-by: Pawan Kumar <[email protected]>
1 parent c85d8d7 commit 59b6b16

File tree

9 files changed

+94
-65
lines changed

9 files changed

+94
-65
lines changed

api/helm-app/HelmAppRestHandler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (handler *HelmAppRestHandlerImpl) DeleteApplication(w http.ResponseWriter,
313313
}
314314

315315
func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter, r *http.Request) {
316-
request := &openapi.UpdateReleaseRequest{}
316+
request := &UpdateApplicationRequestDto{}
317317
decoder := json.NewDecoder(r.Body)
318318
err := decoder.Decode(request)
319319
if err != nil {
@@ -336,9 +336,9 @@ func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter,
336336
return
337337
}
338338
//RBAC enforcer Ends
339-
339+
request.SourceAppType = SOURCE_EXTERNAL_HELM_APP
340340
// update application externally
341-
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request, API_CALLER_EXTERNAL_HELM_APP)
341+
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request)
342342
if err != nil {
343343
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
344344
return

api/helm-app/HelmAppService.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ import (
3636
"time"
3737
)
3838

39-
const (
40-
DEFAULT_CLUSTER = "default_cluster"
41-
DEFAULT_CLUSTER_ID = 1
42-
API_CALLER_DEVTRON_APP ApiCallerAppType = "devtron-app"
43-
API_CALLER_HELM_APP ApiCallerAppType = "helm-app"
44-
API_CALLER_EXTERNAL_HELM_APP ApiCallerAppType = "external-helm-app"
45-
API_CALLER_UNKNOWN ApiCallerAppType = "unknown"
46-
)
47-
48-
type ApiCallerAppType string
49-
5039
type HelmAppService interface {
5140
ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool)
5241
GetApplicationDetail(ctx context.Context, app *AppIdentifier) (*AppDetail, error)
@@ -60,18 +49,18 @@ type HelmAppService interface {
6049
GetValuesYaml(ctx context.Context, app *AppIdentifier) (*ReleaseInfo, error)
6150
GetDesiredManifest(ctx context.Context, app *AppIdentifier, resource *openapi.ResourceIdentifier) (*openapi.DesiredManifestResponse, error)
6251
DeleteApplication(ctx context.Context, app *AppIdentifier) (*openapi.UninstallReleaseResponse, error)
63-
UpdateApplication(ctx context.Context, app *AppIdentifier, request *openapi.UpdateReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error)
52+
UpdateApplication(ctx context.Context, app *AppIdentifier, request *UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error)
6453
GetDeploymentDetail(ctx context.Context, app *AppIdentifier, version int32) (*openapi.HelmAppDeploymentManifestDetail, error)
6554
InstallRelease(ctx context.Context, clusterId int, installReleaseRequest *InstallReleaseRequest) (*InstallReleaseResponse, error)
66-
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, updateReleaseRequest *InstallReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error)
55+
UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, request *UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error)
6756
IsReleaseInstalled(ctx context.Context, app *AppIdentifier) (bool, error)
6857
RollbackRelease(ctx context.Context, app *AppIdentifier, version int32) (bool, error)
6958
GetClusterConf(clusterId int) (*ClusterConfig, error)
7059
GetDevtronHelmAppIdentifier() *AppIdentifier
7160
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *AppIdentifier, chartRepository *ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
7261
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
7362
GetNotes(ctx context.Context, request *InstallReleaseRequest) (string, error)
74-
GetRevisionHistoryMaxValue(appType ApiCallerAppType) int32
63+
GetRevisionHistoryMaxValue(appType SourceAppType) int32
7564
}
7665

7766
type HelmAppServiceImpl struct {
@@ -439,7 +428,7 @@ func (impl *HelmAppServiceImpl) DeleteApplication(ctx context.Context, app *AppI
439428
return response, nil
440429
}
441430

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

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

519508
func (impl *HelmAppServiceImpl) UpdateApplicationWithChartInfo(ctx context.Context, clusterId int,
520-
updateReleaseRequest *InstallReleaseRequest, apiCallerAppType ApiCallerAppType) (*openapi.UpdateReleaseResponse, error) {
509+
request *UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error) {
521510
config, err := impl.GetClusterConf(clusterId)
522511
if err != nil {
523512
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
524513
return nil, err
525514
}
526-
updateReleaseRequest.HistoryMax = impl.GetRevisionHistoryMaxValue(apiCallerAppType)
527-
updateReleaseRequest.ReleaseIdentifier.ClusterConfig = config
515+
request.HistoryMax = impl.GetRevisionHistoryMaxValue(request.SourceAppType)
516+
request.ReleaseIdentifier.ClusterConfig = config
528517

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

670659
// update in helm
671-
updateReleaseRequest := &InstallReleaseRequest{
672-
ReleaseIdentifier: &ReleaseIdentifier{
673-
ReleaseName: appIdentifier.ReleaseName,
674-
ReleaseNamespace: appIdentifier.Namespace,
660+
661+
updateReleaseRequest := &UpdateApplicationWithChartInfoRequestDto{
662+
InstallReleaseRequest: &InstallReleaseRequest{
663+
ReleaseIdentifier: &ReleaseIdentifier{
664+
ReleaseName: appIdentifier.ReleaseName,
665+
ReleaseNamespace: appIdentifier.Namespace,
666+
},
667+
ChartName: releaseInfo.DeployedAppDetail.ChartName,
668+
ValuesYaml: string(mergedValuesYamlByteArr),
669+
ChartRepository: chartRepository,
675670
},
676-
ChartName: releaseInfo.DeployedAppDetail.ChartName,
677-
ValuesYaml: string(mergedValuesYamlByteArr),
678-
ChartRepository: chartRepository,
671+
SourceAppType: SOURCE_UNKNOWN,
679672
}
680673
if !useLatestChartVersion {
681674
updateReleaseRequest.ChartVersion = releaseInfo.DeployedAppDetail.ChartVersion
682675
}
683676

684-
updateResponse, err := impl.UpdateApplicationWithChartInfo(ctx, appIdentifier.ClusterId, updateReleaseRequest, API_CALLER_UNKNOWN)
677+
updateResponse, err := impl.UpdateApplicationWithChartInfo(ctx, appIdentifier.ClusterId, updateReleaseRequest)
685678
if err != nil {
686679
impl.logger.Errorw("error in upgrading release", "err", err)
687680
return nil, err
@@ -885,13 +878,13 @@ func (impl *HelmAppServiceImpl) appListRespProtoTransformer(deployedApps *Deploy
885878
return appList
886879
}
887880

888-
func (impl *HelmAppServiceImpl) GetRevisionHistoryMaxValue(appType ApiCallerAppType) int32 {
881+
func (impl *HelmAppServiceImpl) GetRevisionHistoryMaxValue(appType SourceAppType) int32 {
889882
switch appType {
890-
case API_CALLER_DEVTRON_APP:
883+
case SOURCE_DEVTRON_APP:
891884
return int32(impl.helmReleaseConfig.RevisionHistoryLimitDevtronApp)
892-
case API_CALLER_HELM_APP:
885+
case SOURCE_HELM_APP:
893886
return int32(impl.helmReleaseConfig.RevisionHistoryLimitHelmApp)
894-
case API_CALLER_EXTERNAL_HELM_APP:
887+
case SOURCE_EXTERNAL_HELM_APP:
895888
return int32(impl.helmReleaseConfig.RevisionHistoryLimitExternalHelmApp)
896889
default:
897890
return 0

api/helm-app/bean.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package client
2+
3+
import openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"
4+
5+
const (
6+
DEFAULT_CLUSTER = "default_cluster"
7+
DEFAULT_CLUSTER_ID = 1
8+
SOURCE_DEVTRON_APP SourceAppType = "devtron-app"
9+
SOURCE_HELM_APP SourceAppType = "helm-app"
10+
SOURCE_EXTERNAL_HELM_APP SourceAppType = "external-helm-app"
11+
SOURCE_UNKNOWN SourceAppType = "unknown"
12+
)
13+
14+
type SourceAppType string
15+
16+
type UpdateApplicationRequestDto struct {
17+
*openapi.UpdateReleaseRequest
18+
SourceAppType SourceAppType `json:"-"`
19+
}
20+
21+
type UpdateApplicationWithChartInfoRequestDto struct {
22+
*InstallReleaseRequest
23+
SourceAppType SourceAppType `json:"-"`
24+
}

pkg/app/AppService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ func (impl *AppServiceImpl) createHelmAppForCdPipeline(overrideRequest *bean.Val
24772477
req := &client2.UpgradeReleaseRequest{
24782478
ReleaseIdentifier: releaseIdentifier,
24792479
ValuesYaml: mergeAndSave,
2480-
HistoryMax: impl.helmAppService.GetRevisionHistoryMaxValue(client2.API_CALLER_DEVTRON_APP),
2480+
HistoryMax: impl.helmAppService.GetRevisionHistoryMaxValue(client2.SOURCE_DEVTRON_APP),
24812481
}
24822482

24832483
updateApplicationResponse, err := impl.helmAppClient.UpdateApplication(ctx, req)

pkg/appStore/deployment/service/AppStoreDeploymentService.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -894,22 +894,25 @@ func (impl AppStoreDeploymentServiceImpl) linkHelmApplicationToChartStore(instal
894894

895895
// STEP-2 update APP with chart info
896896
chartRepoInfo := appStoreAppVersion.AppStore.ChartRepo
897-
updateReleaseRequest := &client.InstallReleaseRequest{
898-
ValuesYaml: installAppVersionRequest.ValuesOverrideYaml,
899-
ChartName: appStoreAppVersion.Name,
900-
ChartVersion: appStoreAppVersion.Version,
901-
ReleaseIdentifier: &client.ReleaseIdentifier{
902-
ReleaseNamespace: installAppVersionRequest.Namespace,
903-
ReleaseName: installAppVersionRequest.AppName,
904-
},
905-
ChartRepository: &client.ChartRepository{
906-
Name: chartRepoInfo.Name,
907-
Url: chartRepoInfo.Url,
908-
Username: chartRepoInfo.UserName,
909-
Password: chartRepoInfo.Password,
897+
updateReleaseRequest := &client.UpdateApplicationWithChartInfoRequestDto{
898+
InstallReleaseRequest: &client.InstallReleaseRequest{
899+
ValuesYaml: installAppVersionRequest.ValuesOverrideYaml,
900+
ChartName: appStoreAppVersion.Name,
901+
ChartVersion: appStoreAppVersion.Version,
902+
ReleaseIdentifier: &client.ReleaseIdentifier{
903+
ReleaseNamespace: installAppVersionRequest.Namespace,
904+
ReleaseName: installAppVersionRequest.AppName,
905+
},
906+
ChartRepository: &client.ChartRepository{
907+
Name: chartRepoInfo.Name,
908+
Url: chartRepoInfo.Url,
909+
Username: chartRepoInfo.UserName,
910+
Password: chartRepoInfo.Password,
911+
},
910912
},
913+
SourceAppType: client.SOURCE_HELM_APP,
911914
}
912-
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installAppVersionRequest.ClusterId, updateReleaseRequest, client.API_CALLER_HELM_APP)
915+
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installAppVersionRequest.ClusterId, updateReleaseRequest)
913916
if err != nil {
914917
return nil, err
915918
}

pkg/appStore/deployment/tool/AppStoreDeploymentHelmService.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,25 @@ func (impl *AppStoreDeploymentHelmServiceImpl) updateApplicationWithChartInfo(ct
269269

270270
chartRepo := appStoreApplicationVersion.AppStore.ChartRepo
271271

272-
updateReleaseRequest := &client.InstallReleaseRequest{
273-
ValuesYaml: valuesOverrideYaml,
274-
ReleaseIdentifier: &client.ReleaseIdentifier{
275-
ReleaseNamespace: installedApp.Environment.Namespace,
276-
ReleaseName: installedApp.App.AppName,
277-
},
278-
ChartName: appStoreApplicationVersion.Name,
279-
ChartVersion: appStoreApplicationVersion.Version,
280-
ChartRepository: &client.ChartRepository{
281-
Name: chartRepo.Name,
282-
Url: chartRepo.Url,
283-
Username: chartRepo.UserName,
284-
Password: chartRepo.Password,
272+
updateReleaseRequest := &client.UpdateApplicationWithChartInfoRequestDto{
273+
InstallReleaseRequest: &client.InstallReleaseRequest{
274+
ValuesYaml: valuesOverrideYaml,
275+
ReleaseIdentifier: &client.ReleaseIdentifier{
276+
ReleaseNamespace: installedApp.Environment.Namespace,
277+
ReleaseName: installedApp.App.AppName,
278+
},
279+
ChartName: appStoreApplicationVersion.Name,
280+
ChartVersion: appStoreApplicationVersion.Version,
281+
ChartRepository: &client.ChartRepository{
282+
Name: chartRepo.Name,
283+
Url: chartRepo.Url,
284+
Username: chartRepo.UserName,
285+
Password: chartRepo.Password,
286+
},
285287
},
288+
SourceAppType: client.SOURCE_HELM_APP,
286289
}
287-
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installedApp.Environment.ClusterId, updateReleaseRequest, client.API_CALLER_HELM_APP)
290+
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installedApp.Environment.ClusterId, updateReleaseRequest)
288291
if err != nil {
289292
impl.Logger.Errorw("error in updating helm application", "err", err)
290293
return err

pkg/webhook/helm/WebhookHelmService.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ func (impl WebhookHelmServiceImpl) CreateOrUpdateHelmApplication(ctx context.Con
135135
},
136136
}
137137
if isInstalled {
138-
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, clusterId, installReleaseRequest, client.API_CALLER_HELM_APP)
138+
updateReleaseRequest := &client.UpdateApplicationWithChartInfoRequestDto{
139+
InstallReleaseRequest: installReleaseRequest,
140+
SourceAppType: client.SOURCE_HELM_APP,
141+
}
142+
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, clusterId, updateReleaseRequest)
139143
if err != nil {
140144
impl.logger.Errorw("Error in updating helm release", "appIdentifier", appIdentifier, "err", err)
141145
return nil, common.InternalServerError, err.Error(), http.StatusInternalServerError
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UPDATE global_strategy_metadata_chart_ref_mapping SET active=true WHERE chart_ref_id in(SELECT id FROM chart_ref WHERE location LIKE '%deployment-chart_%') AND global_strategy_metadata_id=(SELECT id FROM global_strategy_metadata WHERE name='RECREATE');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UPDATE global_strategy_metadata_chart_ref_mapping SET active=false WHERE chart_ref_id in(SELECT id FROM chart_ref WHERE location LIKE '%deployment-chart_%') AND global_strategy_metadata_id=(SELECT id FROM global_strategy_metadata WHERE name='RECREATE');

0 commit comments

Comments
 (0)