Skip to content

Commit c740276

Browse files
authored
Merge branch 'develop' into chart-service-refactoring
2 parents 3041db5 + 17d7fde commit c740276

File tree

44 files changed

+481
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+481
-364
lines changed

Wire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ func InitializeApp() (*App, error) {
303303
pipeline.NewCiMaterialConfigServiceImpl,
304304
wire.Bind(new(pipeline.CiMaterialConfigService), new(*pipeline.CiMaterialConfigServiceImpl)),
305305

306+
app.NewDeploymentEventHandlerImpl,
307+
wire.Bind(new(app.DeploymentEventHandler), new(*app.DeploymentEventHandlerImpl)),
308+
306309
pipeline.NewAppArtifactManagerImpl,
307310
wire.Bind(new(pipeline.AppArtifactManager), new(*pipeline.AppArtifactManagerImpl)),
308311
pipeline.NewDevtronAppCMCSServiceImpl,

api/bean/AppView/AppView.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type GenericNoteResponseBean struct {
6464
Description string `json:"description"`
6565
UpdatedBy string `json:"updatedBy"`
6666
UpdatedOn time.Time `json:"updatedOn"`
67+
CreatedBy string `json:"createdBy"`
6768
}
6869

6970
type JobContainer struct {
@@ -100,6 +101,7 @@ type JobListingContainer struct {
100101
LastTriggeredEnvironmentName string `sql:"last_triggered_environment_name" json:"lastTriggeredEnvironmentName"`
101102
LastTriggeredEnvironmentId int `sql:"last_triggered_environment_id" json:"lastEnvironmentId"`
102103
ProjectId int `sql:"team_id" json:"projectId"`
104+
CreatedBy int32 `sql:"created_by" json:"createdBy"`
103105
}
104106

105107
type CiPipelineLastSucceededTime struct {

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ func (handler *K8sApplicationRestHandlerImpl) CreateEphemeralContainer(w http.Re
10251025
return
10261026
}
10271027
request.UserId = userId
1028+
request.ExternalArgoAppIdentifier = resourceRequestBean.ExternalArgoAppIdentifier
1029+
10281030
err = handler.k8sApplicationService.CreatePodEphemeralContainers(&request)
10291031
if err != nil {
10301032
handler.logger.Errorw("error occurred in creating ephemeral container", "err", err, "requestPayload", request)
@@ -1073,6 +1075,7 @@ func (handler *K8sApplicationRestHandlerImpl) DeleteEphemeralContainer(w http.Re
10731075
return
10741076
}
10751077
request.UserId = userId
1078+
request.ExternalArgoAppIdentifier = resourceRequestBean.ExternalArgoAppIdentifier
10761079
_, err = handler.k8sApplicationService.TerminatePodEphemeralContainer(request)
10771080
if err != nil {
10781081
handler.logger.Errorw("error occurred in terminating ephemeral container", "err", err, "requestPayload", request)
@@ -1156,6 +1159,7 @@ func (handler *K8sApplicationRestHandlerImpl) verifyRbacForAppRequests(token str
11561159
handler.logger.Errorw("error in decoding appId", "err", err, "appId", request.AppId)
11571160
return false, err
11581161
}
1162+
request.ExternalArgoAppIdentifier = argoAppIdentifier
11591163
request.ClusterId = argoAppIdentifier.ClusterId
11601164
request.ExternalArgoApplicationName = argoAppIdentifier.AppName
11611165
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), argoAppIdentifier, request.K8sRequest)

api/restHandler/app/pipeline/AutoCompleteRestHandler.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package pipeline
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"github.com/devtron-labs/devtron/pkg/auth/user"
2324
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider/read"
@@ -93,6 +94,24 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
9394
v := r.URL.Query()
9495
teamId := v.Get("teamId")
9596
appName := v.Get("appName")
97+
offset := 0
98+
size := 0 // default value is 0, it means if not provided in query param it will fetch all
99+
sizeStr := v.Get("size")
100+
if sizeStr != "" {
101+
size, err = strconv.Atoi(sizeStr)
102+
if err != nil || size < 0 {
103+
common.WriteJsonResp(w, errors.New("invalid size"), nil, http.StatusBadRequest)
104+
return
105+
}
106+
}
107+
offsetStr := v.Get("offset")
108+
if offsetStr != "" {
109+
offset, err = strconv.Atoi(offsetStr)
110+
if err != nil || offset < 0 {
111+
common.WriteJsonResp(w, errors.New("invalid offset"), nil, http.StatusBadRequest)
112+
return
113+
}
114+
}
96115
appTypeParam := v.Get("appType")
97116
var appType int
98117
if appTypeParam != "" {
@@ -131,6 +150,7 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
131150
}
132151
}
133152
if isActionUserSuperAdmin {
153+
apps = handler.getPaginatedResultsForApps(offset, size, apps)
134154
common.WriteJsonResp(w, err, apps, http.StatusOK)
135155
return
136156
}
@@ -161,6 +181,7 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
161181
}
162182
span.End()
163183
// RBAC
184+
accessedApps = handler.getPaginatedResultsForApps(offset, size, accessedApps)
164185
common.WriteJsonResp(w, err, accessedApps, http.StatusOK)
165186
}
166187

@@ -290,3 +311,14 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) TeamListAutocomplete(w http
290311

291312
common.WriteJsonResp(w, err, result, http.StatusOK)
292313
}
314+
315+
func (handler DevtronAppAutoCompleteRestHandlerImpl) getPaginatedResultsForApps(offset int, size int, apps []*pipeline.AppBean) []*pipeline.AppBean {
316+
if size > 0 {
317+
if offset+size <= len(apps) {
318+
apps = apps[offset : offset+size]
319+
} else {
320+
apps = apps[offset:]
321+
}
322+
}
323+
return apps
324+
}

cmd/external-app/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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-20250526125952-d9add5acd6a4
311-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250526125952-d9add5acd6a4
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
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-20250526125952-d9add5acd6a4 h1:oN526uO6xFroV22CvVAgnXHd8rXoIdTdQQ5qjBQ3tDE=
833-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250526125952-d9add5acd6a4/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250526125952-d9add5acd6a4 h1:6IITdigvNJgWhEQ1T0KlzsYwT18G67H32ggBM0prxpk=
835-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250526125952-d9add5acd6a4/go.mod h1:HQVUnQI7WHwVq89Bib/18xJqM89S1+xI0O7REctMMrA=
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=
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/helper/AppListingRepositoryQueryBuilder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const (
7373
func (impl AppListingRepositoryQueryBuilder) BuildJobListingQuery(appIDs []int, statuses []string, environmentIds []int, sortOrder string) (string, []interface{}) {
7474
var queryParams []interface{}
7575
query := `select ci_pipeline.name as ci_pipeline_name,ci_pipeline.id as ci_pipeline_id,app.id as job_id,app.display_name
76-
as job_name, app.app_name,app.description,app.team_id,cwr.started_on,cwr.status,cem.environment_id,cwr.environment_id as last_triggered_environment_id from app left join ci_pipeline on
76+
as job_name, app.app_name,app.description,app.created_by,app.team_id,cwr.started_on,cwr.status,cem.environment_id,cwr.environment_id as last_triggered_environment_id from app left join ci_pipeline on
7777
app.id = ci_pipeline.app_id and ci_pipeline.active=true left join (select cw.ci_pipeline_id, cw.status, cw.started_on, cw.environment_id
7878
from ci_workflow cw inner join (select ci_pipeline_id, MAX(started_on) max_started_on from ci_workflow group by ci_pipeline_id )
7979
cws on cw.ci_pipeline_id = cws.ci_pipeline_id

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) {

0 commit comments

Comments
 (0)