(appId int, chartRefId int, newAppOverride map[string]interface{}, userId int32, ctx context.Context)
| 858 | } |
| 859 | |
| 860 | func (impl *ChartServiceImpl) UpgradeForApp(appId int, chartRefId int, newAppOverride map[string]interface{}, userId int32, ctx context.Context) (bool, error) { |
| 861 | |
| 862 | currentChart, err := impl.chartReadService.FindLatestChartForAppByAppId(appId) |
| 863 | if err != nil && pg.ErrNoRows != err { |
| 864 | impl.logger.Error(err) |
| 865 | return false, err |
| 866 | } |
| 867 | if pg.ErrNoRows == err { |
| 868 | impl.logger.Errorw("no chart configured for this app", "appId", appId) |
| 869 | return false, fmt.Errorf("no chart configured for this app, skip it for upgrade") |
| 870 | } |
| 871 | |
| 872 | templateRequest := bean3.TemplateRequest{} |
| 873 | templateRequest.ChartRefId = chartRefId |
| 874 | templateRequest.AppId = appId |
| 875 | templateRequest.ChartRepositoryId = currentChart.ChartRepositoryId |
| 876 | templateRequest.DefaultAppOverride = newAppOverride["defaultAppOverride"].(json.RawMessage) |
| 877 | templateRequest.ValuesOverride = currentChart.DefaultAppOverride |
| 878 | templateRequest.UserId = userId |
| 879 | templateRequest.IsBasicViewLocked = currentChart.IsBasicViewLocked |
| 880 | templateRequest.CurrentViewEditor = currentChart.CurrentViewEditor |
| 881 | upgradedChartReq, err := impl.Create(templateRequest, ctx) |
| 882 | if err != nil { |
| 883 | return false, err |
| 884 | } |
| 885 | if upgradedChartReq == nil || upgradedChartReq.Id == 0 { |
| 886 | impl.logger.Infow("unable to upgrade app", "appId", appId) |
| 887 | return false, fmt.Errorf("unable to upgrade app, got no error on creating chart but unable to complete") |
| 888 | } |
| 889 | updatedChart, err := impl.chartRepository.FindById(upgradedChartReq.Id) |
| 890 | if err != nil { |
| 891 | return false, err |
| 892 | } |
| 893 | |
| 894 | //STEP 2 - env upgrade |
| 895 | impl.logger.Debugw("creating env and pipeline config for app", "appId", appId) |
| 896 | //step 1 |
| 897 | envOverrides, err := impl.envConfigOverrideReadService.GetEnvConfigByChartId(currentChart.Id) |
| 898 | if err != nil && envOverrides == nil { |
| 899 | return false, err |
| 900 | } |
| 901 | for _, envOverride := range envOverrides { |
| 902 | |
| 903 | //STEP 4 = create environment config |
| 904 | env, err := impl.environmentRepository.FindById(envOverride.TargetEnvironment) |
| 905 | if err != nil { |
| 906 | return false, err |
| 907 | } |
| 908 | envOverrideNew := &chartConfig.EnvConfigOverride{ |
| 909 | Active: true, |
| 910 | ManualReviewed: true, |
| 911 | Status: models.CHARTSTATUS_SUCCESS, |
| 912 | EnvOverrideValues: string(envOverride.EnvOverrideValues), |
| 913 | TargetEnvironment: envOverride.TargetEnvironment, |
| 914 | ChartId: updatedChart.Id, |
| 915 | AuditLog: sql.AuditLog{UpdatedBy: userId, UpdatedOn: time.Now(), CreatedOn: time.Now(), CreatedBy: userId}, |
| 916 | Namespace: env.Namespace, |
| 917 | Latest: true, |
nothing calls this directly
no test coverage detected