Skip to content

Commit fba905e

Browse files
committed
handle nil pipeline strategy in case of custom chart
1 parent 596b86b commit fba905e

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

api/restHandler/DeploymentConfigurationRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.Resp
103103
//RBAC END
104104
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*")
105105
userHasAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, object)
106-
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
106+
ctx, _ := context.WithTimeout(r.Context(), 60*time.Second)
107107
ctx = util2.SetSuperAdminInContext(ctx, isSuperAdmin)
108-
defer cancel()
108+
109109
res, err := handler.deploymentConfigurationService.GetAllConfigData(ctx, configDataQueryParams, userHasAdminAccess)
110110
if err != nil {
111111
handler.logger.Errorw("service err, GetAllConfigData ", "err", err)

pkg/configDiff/DeploymentConfigurationService.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
repository6 "github.com/devtron-labs/devtron/pkg/variables/repository"
2828
util2 "github.com/devtron-labs/devtron/util"
2929
"github.com/go-pg/pg"
30+
"github.com/juju/errors"
3031
"go.uber.org/zap"
3132
"net/http"
3233
)
@@ -190,18 +191,20 @@ func (impl *DeploymentConfigurationServiceImpl) getDeploymentHistoryConfig(ctx c
190191

191192
func (impl *DeploymentConfigurationServiceImpl) getPipelineStrategyConfigHistory(ctx context.Context, configDataQueryParams *bean2.ConfigDataQueryParams) (*bean2.DeploymentAndCmCsConfig, error) {
192193
pipelineStrategyJson := json.RawMessage{}
194+
pipelineConfig := bean2.NewDeploymentAndCmCsConfig()
193195
pipelineStrategyHistory, err := impl.pipelineStrategyHistoryRepository.GetHistoryByPipelineIdAndWfrId(ctx, configDataQueryParams.PipelineId, configDataQueryParams.WfrId)
194-
if err != nil {
196+
if err != nil && !util.IsErrNoRows(err) {
195197
impl.logger.Errorw("error in checking if history exists for pipelineId and wfrId", "pipelineId", configDataQueryParams.PipelineId, "wfrId", configDataQueryParams.WfrId, "err", err)
196198
return nil, err
199+
} else if util.IsErrNoRows(err) {
200+
return pipelineConfig, nil
197201
}
198202
err = pipelineStrategyJson.UnmarshalJSON([]byte(pipelineStrategyHistory.Config))
199203
if err != nil {
200204
impl.logger.Errorw("getDeploymentTemplateForEnvLevel, error in unmarshalling string pipelineStrategyHistory data into json Raw message", "pipelineStrategyHistoryConfig", pipelineStrategyHistory.Config, "err", err)
201205
return nil, err
202206
}
203-
pipelineConfig := bean2.NewDeploymentAndCmCsConfig().
204-
WithConfigData(pipelineStrategyJson).
207+
pipelineConfig.WithConfigData(pipelineStrategyJson).
205208
WithResourceType(bean.PipelineStrategy).
206209
WithPipelineStrategyMetadata(pipelineStrategyHistory.PipelineTriggerType, string(pipelineStrategyHistory.Strategy))
207210
return pipelineConfig, nil
@@ -640,9 +643,11 @@ func (impl *DeploymentConfigurationServiceImpl) getPublishedPipelineStrategyConf
640643
return nil, err
641644
}
642645
pipelineStrategy, err := impl.deploymentConfigService.GetLatestPipelineStrategyConfig(pipeline)
643-
if err != nil {
646+
if err != nil && !errors.IsNotFound(err) {
644647
impl.logger.Errorw("error in GetLatestPipelineStrategyConfig", "pipelineId", pipeline.Id, "err", err)
645648
return nil, err
649+
} else if errors.IsNotFound(err) {
650+
return pipelineConfig, nil
646651
}
647652
err = pipelineStrategyJson.UnmarshalJSON([]byte(pipelineStrategy.CodeEditorValue.Value))
648653
if err != nil {

pkg/generateManifest/DeploymentTemplateService.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ func (impl DeploymentTemplateServiceImpl) fetchResolvedTemplateForPublishedEnvs(
335335
impl.Logger.Errorw("error in getting overridden values", "err", err)
336336
return nil, err
337337
}
338-
_, _, version, _, err := impl.chartRefService.GetRefChart(override.EnvironmentConfig.ChartRefId)
338+
// handle here for chart ref id in case
339+
chartRefId := override.EnvironmentConfig.ChartRefId
340+
if chartRefId == 0 {
341+
chartRefId = override.GlobalChartRefId
342+
}
343+
_, _, version, _, err := impl.chartRefService.GetRefChart(chartRefId)
339344
if err != nil {
340345
impl.Logger.Errorw("error in getting chart ref by chartRefId ", "chartRefId", request.ChartRefId, "err", err)
341346
return nil, err

0 commit comments

Comments
 (0)