Skip to content

Commit ce56413

Browse files
authored
Merge pull request #6647 from devtron-labs/release-candidate-v0.37.0-main-sync-4jun-2
sync: Release candidate v0.37.0 main sync
2 parents a4a3d01 + 1128acb commit ce56413

16 files changed

+101
-53
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ require (
307307

308308
replace (
309309
github.com/argoproj/argo-workflows/v3 v3.5.13 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
310-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250602065932-06089729a1c2
311-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250602065932-06089729a1c2
310+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250604112749-a4fc904430f9
311+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250604112749-a4fc904430f9
312312
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
313313
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
314314
k8s.io/api => k8s.io/api v0.29.7

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
829829
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
830830
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
831831
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
832-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250602065932-06089729a1c2 h1:X0pXpqQrEEt+aXck0WTTokdNs0RfTVufotoATL10shw=
833-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250602065932-06089729a1c2/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250602065932-06089729a1c2 h1:1uzqPQQvbQVyip6UU/YN8pYwjQOD8K8rEmql7HrrsBk=
835-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250602065932-06089729a1c2/go.mod h1:HQVUnQI7WHwVq89Bib/18xJqM89S1+xI0O7REctMMrA=
832+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250604112749-a4fc904430f9 h1:OFZ1AMLSm428qw/IXXUK4sKcsIiUbmYTxhBZBzouau0=
833+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250604112749-a4fc904430f9/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250604112749-a4fc904430f9 h1:VVTeMCYeQqPVxP+f5nKhY/C24n7RwbxZQgfQTQijZPs=
835+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250604112749-a4fc904430f9/go.mod h1:HQVUnQI7WHwVq89Bib/18xJqM89S1+xI0O7REctMMrA=
836836
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
837837
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
838838
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=

internal/sql/repository/pipelineConfig/CiTemplateOverrideRepository.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
repository2 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
2222
"github.com/devtron-labs/devtron/pkg/sql"
2323
"github.com/go-pg/pg"
24+
"github.com/go-pg/pg/orm"
2425
"go.uber.org/zap"
2526
)
2627

@@ -47,6 +48,7 @@ type CiTemplateOverrideRepository interface {
4748
FindByAppId(appId int) ([]*CiTemplateOverride, error)
4849
FindByCiPipelineIds(ciPipelineIds []int) ([]*CiTemplateOverride, error)
4950
FindByCiPipelineId(ciPipelineId int) (*CiTemplateOverride, error)
51+
FindIfTemplateOverrideExistsByCiPipelineIdsAndGitMaterialId(ciPipelineIds []int, gitMaterialId int) (bool, error)
5052
}
5153

5254
type CiTemplateOverrideRepositoryImpl struct {
@@ -125,3 +127,22 @@ func (repo *CiTemplateOverrideRepositoryImpl) FindByCiPipelineId(ciPipelineId in
125127
}
126128
return ciTemplateOverride, nil
127129
}
130+
131+
func (repo *CiTemplateOverrideRepositoryImpl) FindIfTemplateOverrideExistsByCiPipelineIdsAndGitMaterialId(ciPipelineIds []int, gitMaterialId int) (bool, error) {
132+
if len(ciPipelineIds) == 0 {
133+
return false, nil
134+
}
135+
count, err := repo.dbConnection.Model((*CiTemplateOverride)(nil)).
136+
Where("ci_pipeline_id in (?)", pg.In(ciPipelineIds)).
137+
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
138+
return q.Where("git_material_id = ?", gitMaterialId).WhereOr("build_context_git_material_id = ?", gitMaterialId), nil
139+
}).
140+
Where("active = ?", true).
141+
Count()
142+
if err != nil {
143+
repo.logger.Errorw("error in checking if template override exists", "ciPipelineIds", ciPipelineIds, "gitMaterialId", gitMaterialId, "err", err)
144+
return false, err
145+
}
146+
return count > 0, nil
147+
148+
}

internal/sql/repository/pipelineConfig/PipelineRepository.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type PipelineRepository interface {
118118
FindActiveByInFilter(envId int, appIdIncludes []int) (pipelines []*Pipeline, err error)
119119
FindActivePipelineAppIdsByInFilter(envId int, appIdIncludes []int) ([]int, error)
120120
FindActiveByNotFilter(envId int, appIdExcludes []int) (pipelines []*Pipeline, err error)
121-
FindAllPipelinesByChartsOverrideAndAppIdAndChartId(chartOverridden bool, appId int, chartId int) (pipelines []*Pipeline, err error)
121+
FindAllPipelinesWithoutOverriddenCharts(appId int) (pipelineIds []int, err error)
122122
FindActiveByAppIdAndPipelineId(appId int, pipelineId int) ([]*Pipeline, error)
123123
FindActiveByAppIdAndEnvId(appId int, envId int) (*Pipeline, error)
124124
SetDeploymentAppCreatedInPipeline(deploymentAppCreated bool, pipelineId int, userId int32) error
@@ -578,19 +578,16 @@ func (impl *PipelineRepositoryImpl) FindActiveByNotFilter(envId int, appIdExclud
578578
return pipelines, err
579579
}
580580

581-
func (impl *PipelineRepositoryImpl) FindAllPipelinesByChartsOverrideAndAppIdAndChartId(hasConfigOverridden bool, appId int, chartId int) (pipelines []*Pipeline, err error) {
582-
err = impl.dbConnection.Model(&pipelines).
583-
Column("pipeline.*").
584-
Join("inner join charts on pipeline.app_id = charts.app_id").
585-
Join("inner join chart_env_config_override ceco on charts.id = ceco.chart_id").
586-
Where("pipeline.app_id = ?", appId).
587-
Where("charts.id = ?", chartId).
588-
Where("ceco.is_override = ?", hasConfigOverridden).
589-
Where("pipeline.deleted = ?", false).
590-
Where("ceco.active = ?", true).
591-
Where("charts.active = ?", true).
592-
Select()
593-
return pipelines, err
581+
func (impl *PipelineRepositoryImpl) FindAllPipelinesWithoutOverriddenCharts(appId int) (pipelineIds []int, err error) {
582+
err = impl.dbConnection.Model().Table("pipeline").Column("pipeline.id").
583+
Where("pipeline.deleted = ?", false).Where("pipeline.app_id = ?", appId).
584+
Where(`pipeline.environment_id NOT IN (
585+
SELECT ceco.target_environment FROM chart_env_config_override ceco
586+
INNER JOIN charts ON charts.id = ceco.chart_id
587+
WHERE charts.app_id = ? AND charts.active = ? AND ceco.is_override = ?
588+
AND ceco.active = ? AND ceco.latest = ?)`, appId, true, true, true, true).
589+
Select(&pipelineIds)
590+
return pipelineIds, err
594591
}
595592

596593
func (impl *PipelineRepositoryImpl) FindActiveByAppIdAndPipelineId(appId int, pipelineId int) ([]*Pipeline, error) {

pkg/appWorkflow/AppWorkflowService.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ func (impl AppWorkflowServiceImpl) FindAppWorkflowsByEnvironmentId(request resou
607607
}
608608
appResults, envResults := request.CheckAuthBatch(token, appObjectArr, envObjectArr)
609609
for _, pipeline := range pipelines {
610+
if _, ok := objects[pipeline.Id]; !ok {
611+
impl.Logger.Warnw("pipeline not found in objects map", "pipelineId", pipeline.Id)
612+
continue
613+
}
610614
appObject := objects[pipeline.Id][0]
611615
envObject := objects[pipeline.Id][1]
612616
if !(appResults[appObject] && envResults[envObject]) {

pkg/build/pipeline/CiTemplateReadService.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type CiTemplateReadService interface {
1818
GetAppliedDockerConfigForCiPipeline(ciPipelineId, appId int, isOverridden bool) (*types.DockerArtifactStoreBean, error)
1919
GetBaseDockerConfigForCiPipeline(appId int) (*types.DockerArtifactStoreBean, error)
2020
FindByAppIds(appIds []int) (map[int]*bean.CiTemplateBean, error)
21+
CheckIfTemplateOverrideExists(ciPipelineIds []int, gitMaterialId int) (bool, error)
2122
}
2223

2324
type CiTemplateReadServiceImpl struct {
@@ -181,3 +182,7 @@ func (impl *CiTemplateReadServiceImpl) FindByAppIds(appIds []int) (map[int]*bean
181182
}
182183
return ciTemplateMap, nil
183184
}
185+
186+
func (impl *CiTemplateReadServiceImpl) CheckIfTemplateOverrideExists(ciPipelineIds []int, gitMaterialId int) (bool, error) {
187+
return impl.CiTemplateOverrideRepository.FindIfTemplateOverrideExistsByCiPipelineIdsAndGitMaterialId(ciPipelineIds, gitMaterialId)
188+
}

pkg/bulkAction/service/BulkUpdateService.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,13 @@ func (impl BulkUpdateServiceImpl) BulkDeploy(request *bean4.BulkApplicationForEn
13361336
pResponse[pipelineKey] = false
13371337
response[appKey] = pResponse
13381338
}
1339+
if _, ok := objects[pipeline.Id]; !ok {
1340+
//if user unauthorized, skip items
1341+
pipelineResponse := response[appKey]
1342+
pipelineResponse[pipelineKey] = false
1343+
response[appKey] = pipelineResponse
1344+
continue
1345+
}
13391346
appObject := objects[pipeline.Id][0]
13401347
envObject := objects[pipeline.Id][1]
13411348
if !(appResults[appObject] && envResults[envObject]) {

pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateHistoryService.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ func NewDeploymentTemplateHistoryServiceImpl(logger *zap.SugaredLogger, deployme
7070

7171
func (impl DeploymentTemplateHistoryServiceImpl) CreateDeploymentTemplateHistoryFromGlobalTemplate(chart *chartRepoRepository.Chart, tx *pg.Tx, IsAppMetricsEnabled bool) (err error) {
7272
//getting all pipelines without overridden charts
73-
pipelines, err := impl.pipelineRepository.FindAllPipelinesByChartsOverrideAndAppIdAndChartId(false, chart.AppId, chart.Id)
73+
pipelineIds, err := impl.pipelineRepository.FindAllPipelinesWithoutOverriddenCharts(chart.AppId)
7474
if err != nil && err != pg.ErrNoRows {
7575
impl.logger.Errorw("err in getting pipelines, CreateDeploymentTemplateHistoryFromGlobalTemplate", "err", err, "chart", chart)
7676
return err
7777
}
78+
/*
79+
When creating base template entry, we also create entries for all pipeline whose env template is not overridden;
80+
as the change in base template will also impact them. Earlier we used to create individual entries for all pipelines
81+
but due to performance impact we are now saving the impacted pipelineIds in the base template entry itself (column pipeline_ids).
82+
*/
7883
chartRefDto, err := impl.chartRefService.FindById(chart.ChartRefId)
7984
if err != nil {
8085
impl.logger.Errorw("err in getting chartRef, CreateDeploymentTemplateHistoryFromGlobalTemplate", "err", err, "chart", chart)
@@ -89,6 +94,7 @@ func (impl DeploymentTemplateHistoryServiceImpl) CreateDeploymentTemplateHistory
8994
TemplateName: chartRefDto.Name,
9095
TemplateVersion: chartRefDto.Version,
9196
IsAppMetricsEnabled: IsAppMetricsEnabled,
97+
PipelineIds: pipelineIds,
9298
AuditLog: sql.AuditLog{
9399
CreatedOn: chart.CreatedOn,
94100
CreatedBy: chart.CreatedBy,
@@ -106,34 +112,6 @@ func (impl DeploymentTemplateHistoryServiceImpl) CreateDeploymentTemplateHistory
106112
impl.logger.Errorw("err in creating history entry for deployment template", "err", err, "history", historyModel)
107113
return err
108114
}
109-
for _, pipeline := range pipelines {
110-
historyModel := &repository.DeploymentTemplateHistory{
111-
AppId: chart.AppId,
112-
PipelineId: pipeline.Id,
113-
ImageDescriptorTemplate: chart.ImageDescriptorTemplate,
114-
Template: chart.GlobalOverride,
115-
Deployed: false,
116-
TemplateName: chartRefDto.Name,
117-
TemplateVersion: chartRefDto.Version,
118-
IsAppMetricsEnabled: IsAppMetricsEnabled,
119-
AuditLog: sql.AuditLog{
120-
CreatedOn: chart.CreatedOn,
121-
CreatedBy: chart.CreatedBy,
122-
UpdatedOn: chart.UpdatedOn,
123-
UpdatedBy: chart.UpdatedBy,
124-
},
125-
}
126-
//creating new entry
127-
if tx != nil {
128-
_, err = impl.deploymentTemplateHistoryRepository.CreateHistoryWithTxn(historyModel, tx)
129-
} else {
130-
_, err = impl.deploymentTemplateHistoryRepository.CreateHistory(historyModel)
131-
}
132-
if err != nil {
133-
impl.logger.Errorw("err in creating history entry for deployment template", "err", err, "history", historyModel)
134-
return err
135-
}
136-
}
137115
return err
138116
}
139117

pkg/pipeline/CdHandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou
883883
}
884884
appResults, envResults := request.CheckAuthBatch(token, appObjectArr, envObjectArr)
885885
for _, pipeline := range cdPipelines {
886+
if _, ok := objects[pipeline.Id]; !ok {
887+
impl.Logger.Warnw("skipping pipeline as no object found for it", "pipelineId", pipeline.Id)
888+
continue
889+
}
886890
appObject := objects[pipeline.Id][0]
887891
envObject := objects[pipeline.Id][1]
888892
if !(appResults[appObject] && envResults[envObject]) {

pkg/pipeline/CiMaterialConfigService.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"github.com/devtron-labs/devtron/internal/sql/constants"
2222
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
23+
util2 "github.com/devtron-labs/devtron/internal/util"
2324
"github.com/devtron-labs/devtron/pkg/bean"
2425
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read"
2526
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
@@ -29,6 +30,7 @@ import (
2930
"github.com/go-pg/pg"
3031
"github.com/juju/errors"
3132
"go.uber.org/zap"
33+
"net/http"
3234
"strings"
3335
"time"
3436
)
@@ -123,6 +125,20 @@ func (impl *CiMaterialConfigServiceImpl) DeleteMaterial(request *bean.UpdateMate
123125
return fmt.Errorf("cannot delete git material, is being used in docker config")
124126
}
125127
}
128+
overriddenPipelineIds := make([]int, 0, len(pipelines))
129+
for _, dbPipeline := range pipelines {
130+
if dbPipeline.IsDockerConfigOverridden {
131+
overriddenPipelineIds = append(overriddenPipelineIds, dbPipeline.Id)
132+
}
133+
}
134+
exist, err := impl.ciTemplateService.CheckIfTemplateOverrideExists(overriddenPipelineIds, request.Material.Id)
135+
if err != nil {
136+
impl.logger.Errorw("error in checking if template override exists", "pipelineIds", overriddenPipelineIds, "gitMaterialId", request.Material.Id, "err", err)
137+
return err
138+
}
139+
if exist {
140+
return util2.GetApiErrorAdapter(http.StatusBadRequest, "400", "cannot delete git material, is being used in overridden ci template", "cannot delete git material, is being used in overridden ci template")
141+
}
126142
}
127143
existingMaterial, err := impl.gitMaterialReadService.FindById(request.Material.Id)
128144
if err != nil {

0 commit comments

Comments
 (0)