Skip to content

Commit 877c9c6

Browse files
Merge branch 'main' into rbac-anomolies-ci-patch-oss
2 parents a4483fd + 5c20f35 commit 877c9c6

File tree

23 files changed

+326
-67
lines changed

23 files changed

+326
-67
lines changed

Wire.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import (
112112
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deploymentTypeChange"
113113
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource"
114114
"github.com/devtron-labs/devtron/pkg/appWorkflow"
115+
"github.com/devtron-labs/devtron/pkg/asyncProvider"
115116
"github.com/devtron-labs/devtron/pkg/attributes"
116117
"github.com/devtron-labs/devtron/pkg/build"
117118
"github.com/devtron-labs/devtron/pkg/bulkAction"
@@ -229,6 +230,10 @@ func InitializeApp() (*App, error) {
229230
wire.Bind(new(router.PProfRouter), new(*router.PProfRouterImpl)),
230231
// ---- pprof end ----
231232

233+
// ---- goroutine async wrapper service start ----
234+
asyncProvider.WireSet,
235+
// ---- goroutine async wrapper service end ----
236+
232237
sql.NewTransactionUtilImpl,
233238
wire.Bind(new(sql.TransactionWrapper), new(*sql.TransactionUtilImpl)),
234239

WiringNilCheck.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"fmt"
21+
"github.com/devtron-labs/devtron/util/reflectUtil"
2122
"log"
2223
"os"
2324
"reflect"
@@ -81,14 +82,7 @@ func checkNilFields(obj interface{}, nilObjMap map[string]bool) {
8182
}
8283

8384
func canFieldTypeBeNil(field reflect.Value) bool {
84-
kind := field.Kind()
85-
switch kind {
86-
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer,
87-
reflect.Interface, reflect.Slice:
88-
return true
89-
default: //other types can not be nil
90-
return false
91-
}
85+
return reflectUtil.IsNullableValue(field)
9286
}
9387

9488
func canSkipFieldStructCheck(fieldName, valName string) bool {

client/argocdServer/ArgoClientWrapperService.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
2525
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
2626
"github.com/caarlos0/env"
27+
"github.com/devtron-labs/common-lib/async"
2728
"github.com/devtron-labs/devtron/client/argocdServer/adapter"
2829
"github.com/devtron-labs/devtron/client/argocdServer/application"
2930
"github.com/devtron-labs/devtron/client/argocdServer/bean"
@@ -104,25 +105,29 @@ type ArgoClientWrapperServiceImpl struct {
104105
repositoryService repository.ServiceClient
105106
gitOpsConfigReadService config.GitOpsConfigReadService
106107
gitOperationService git.GitOperationService
108+
asyncRunnable *async.Runnable
107109
}
108110

109111
func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient application.ServiceClient,
110112
ACDConfig *ACDConfig, repositoryService repository.ServiceClient, gitOpsConfigReadService config.GitOpsConfigReadService,
111-
gitOperationService git.GitOperationService) *ArgoClientWrapperServiceImpl {
113+
gitOperationService git.GitOperationService, asyncRunnable *async.Runnable) *ArgoClientWrapperServiceImpl {
112114
return &ArgoClientWrapperServiceImpl{
113115
logger: logger,
114116
acdClient: acdClient,
115117
ACDConfig: ACDConfig,
116118
repositoryService: repositoryService,
117119
gitOpsConfigReadService: gitOpsConfigReadService,
118120
gitOperationService: gitOperationService,
121+
asyncRunnable: asyncRunnable,
119122
}
120123
}
121124

122-
func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(context context.Context, argoAppName string) error {
125+
func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(ctx context.Context, argoAppName string) error {
126+
newCtx, span := otel.Tracer("orchestrator").Start(ctx, "ArgoClientWrapperServiceImpl.GetArgoAppWithNormalRefresh")
127+
defer span.End()
123128
refreshType := bean.RefreshTypeNormal
124129
impl.logger.Debugw("trying to normal refresh application through get ", "argoAppName", argoAppName)
125-
_, err := impl.acdClient.Get(context, &application2.ApplicationQuery{Name: &argoAppName, Refresh: &refreshType})
130+
_, err := impl.acdClient.Get(newCtx, &application2.ApplicationQuery{Name: &argoAppName, Refresh: &refreshType})
126131
if err != nil {
127132
internalMsg := fmt.Sprintf("%s, err:- %s", constants.CannotGetAppWithRefreshErrMsg, err.Error())
128133
clientCode, _ := util.GetClientDetailedError(err)
@@ -177,10 +182,15 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres
177182
}
178183
impl.logger.Infow("ArgoCd sync completed", "argoAppName", argoAppName)
179184
}
180-
refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName)
181-
if refreshErr != nil {
182-
impl.logger.Errorw("error in refreshing argo app", "err", refreshErr)
185+
186+
runnableFunc := func() {
187+
// running ArgoCd app refresh in asynchronous mode
188+
refreshErr := impl.GetArgoAppWithNormalRefresh(context.Background(), argoAppName)
189+
if refreshErr != nil {
190+
impl.logger.Errorw("error in refreshing argo app", "argoAppName", argoAppName, "err", refreshErr)
191+
}
183192
}
193+
impl.asyncRunnable.Execute(runnableFunc)
184194
return nil
185195
}
186196

client/argocdServer/application/Application.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ func (c ServiceClientImpl) Patch(ctxt context.Context, query *application.Applic
8282
return resp, err
8383
}
8484

85-
func (c ServiceClientImpl) Get(ctxt context.Context, query *application.ApplicationQuery) (*v1alpha1.Application, error) {
86-
ctx, cancel := context.WithTimeout(ctxt, argoApplication.TimeoutFast)
87-
defer cancel()
88-
token, ok := ctxt.Value("token").(string)
85+
func (c ServiceClientImpl) Get(ctx context.Context, query *application.ApplicationQuery) (*v1alpha1.Application, error) {
86+
token, ok := ctx.Value("token").(string)
8987
if !ok {
9088
return nil, errors.New("Unauthorized")
9189
}
90+
newCtx, cancel := context.WithTimeout(ctx, argoApplication.TimeoutFast)
91+
defer cancel()
9292
conn := c.argoCDConnectionManager.GetConnection(token)
9393
defer util.Close(conn, c.logger)
9494
asc := application.NewApplicationServiceClient(conn)
95-
resp, err := asc.Get(ctx, query)
95+
resp, err := asc.Get(newCtx, query)
9696
return resp, err
9797
}
9898

env_gen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
| NATS_MSG_BUFFER_SIZE | -1 | |
190190
| NATS_MSG_MAX_AGE | 86400 | |
191191
| NATS_MSG_PROCESSING_BATCH_SIZE | 1 | |
192+
| NATS_MSG_REPLICAS | 0 | |
192193
| NATS_SERVER_HOST | nats://devtron-nats.devtroncd:4222 | |
193194
| NOTIFICATION_MEDIUM | rest | |
194195
| ORCH_HOST | http://devtroncd-orchestrator-service-prod.devtroncd/webhook/msg/nats | |
@@ -210,7 +211,6 @@
210211
| PRE_CI_CACHE_PATH | /devtroncd-cache | |
211212
| PROPAGATE_EXTRA_LABELS | false | |
212213
| PROXY_SERVICE_CONFIG | {} | |
213-
| REPLICAS | 0 | |
214214
| REQ_CI_CPU | 0.5 | |
215215
| REQ_CI_MEM | 3G | |
216216
| RESOURCE_LIST_FOR_REPLICAS | Deployment,Rollout,StatefulSet,ReplicaSet | |

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/davecgh/go-spew v1.1.1
2323
github.com/deckarep/golang-set v1.8.0
2424
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1
25-
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160
25+
github.com/devtron-labs/common-lib v0.0.23
2626
github.com/devtron-labs/go-bitbucket v0.9.60-beta
2727
github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1
2828
github.com/evanphx/json-patch v5.7.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
197197
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
198198
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY=
199199
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc=
200-
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160 h1:9iumIJmRId91aUcyPkxPb6nvjhHuYDoAgomNSG6OIdE=
201-
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
200+
github.com/devtron-labs/common-lib v0.0.23 h1:3n9VgJALanjHrb/t0nSaLbLJcJa7sdsdyFf2leE+cN0=
201+
github.com/devtron-labs/common-lib v0.0.23/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
202202
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
203203
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
204204
github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM=

internal/sql/repository/appWorkflow/AppWorkflowRepository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type AppWorkflowRepository interface {
4444
FindWFAllMappingByWorkflowId(workflowId int) ([]*AppWorkflowMapping, error)
4545
FindWFCIMappingByCIPipelineId(ciPipelineId int) ([]*AppWorkflowMapping, error)
4646
FindWFCDMappingByCIPipelineId(ciPipelineId int) ([]*AppWorkflowMapping, error)
47+
FindWFCDMappingsByWorkflowId(appWorkflowId int) ([]*AppWorkflowMapping, error)
4748
FindWFCDMappingByCDPipelineId(cdPipelineId int) (*AppWorkflowMapping, error)
4849
GetParentDetailsByPipelineId(pipelineId int) (*AppWorkflowMapping, error)
4950
DeleteAppWorkflowMapping(appWorkflow *AppWorkflowMapping, tx *pg.Tx) error
@@ -273,6 +274,17 @@ func (impl AppWorkflowRepositoryImpl) FindWFCIMappingByCIPipelineId(ciPipelineId
273274
return appWorkflowsMapping, err
274275
}
275276

277+
func (impl AppWorkflowRepositoryImpl) FindWFCDMappingsByWorkflowId(appWorkflowId int) ([]*AppWorkflowMapping, error) {
278+
var appWorkflowsMapping []*AppWorkflowMapping
279+
280+
err := impl.dbConnection.Model(&appWorkflowsMapping).
281+
Where("app_workflow_id = ?", appWorkflowId).
282+
Where("type = ?", CDPIPELINE).
283+
Where("active = ?", true).
284+
Select()
285+
return appWorkflowsMapping, err
286+
}
287+
276288
func (impl AppWorkflowRepositoryImpl) FindWFCDMappingByCIPipelineId(ciPipelineId int) ([]*AppWorkflowMapping, error) {
277289
var appWorkflowsMapping []*AppWorkflowMapping
278290

internal/sql/repository/pipelineConfig/PipelineRepository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type PipelineRepository interface {
122122
FindAppAndEnvironmentAndProjectByPipelineIds(pipelineIds []int) (pipelines []*Pipeline, err error)
123123
FilterDeploymentDeleteRequestedPipelineIds(cdPipelineIds []int) (map[int]bool, error)
124124
FindDeploymentTypeByPipelineIds(cdPipelineIds []int) (map[int]DeploymentObject, error)
125+
UpdateCiPipelineId(tx *pg.Tx, pipelineIds []int, ciPipelineId int) error
125126
UpdateOldCiPipelineIdToNewCiPipelineId(tx *pg.Tx, oldCiPipelineId, newCiPipelineId int) error
126127
// FindWithEnvironmentByCiIds Possibility of duplicate environment names when filtered by unique pipeline ids
127128
FindWithEnvironmentByCiIds(ctx context.Context, cIPipelineIds []int) ([]*Pipeline, error)
@@ -770,6 +771,17 @@ func (impl PipelineRepositoryImpl) UpdateOldCiPipelineIdToNewCiPipelineId(tx *pg
770771
Where("deleted = ?", false).Update()
771772
return err
772773
}
774+
775+
func (impl PipelineRepositoryImpl) UpdateCiPipelineId(tx *pg.Tx, pipelineIds []int, ciPipelineId int) error {
776+
if len(pipelineIds) == 0 {
777+
return nil
778+
}
779+
_, err := tx.Model((*Pipeline)(nil)).Set("ci_pipeline_id = ?", ciPipelineId).
780+
Where("id IN (?) ", pg.In(pipelineIds)).
781+
Where("deleted = ?", false).Update()
782+
return err
783+
}
784+
773785
func (impl PipelineRepositoryImpl) FindWithEnvironmentByCiIds(ctx context.Context, cIPipelineIds []int) ([]*Pipeline, error) {
774786
_, span := otel.Tracer("orchestrator").Start(ctx, "FindWithEnvironmentByCiIds")
775787
defer span.End()

pkg/appStore/installedApp/service/EAMode/EAModeDeploymentService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ type EAModeDeploymentService interface {
5151
GetDeploymentHistory(ctx context.Context, installedApp *appStoreBean.InstallAppVersionDTO) (*gRPC.HelmAppDeploymentHistory, error)
5252
GetDeploymentHistoryInfo(ctx context.Context, installedApp *appStoreBean.InstallAppVersionDTO, version int32) (*openapi.HelmAppDeploymentManifestDetail, error)
5353
UpgradeDeployment(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ChartGitAttribute *commonBean.ChartGitAttribute, installedAppVersionHistoryId int, ctx context.Context) error
54-
GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error)
5554
}
5655

5756
type EAModeDeploymentServiceImpl struct {
@@ -442,6 +441,7 @@ func (impl *EAModeDeploymentServiceImpl) GetChartBytesForParticularDeployment(in
442441
func (impl *EAModeDeploymentServiceImpl) DeleteACD(acdAppName string, ctx context.Context, isNonCascade bool) error {
443442
return errors.New("this is not implemented")
444443
}
444+
445445
func (impl *EAModeDeploymentServiceImpl) GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error) {
446446
return "", errors.New("this is not implemented")
447447
}

pkg/asyncProvider/AsyncProvider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package asyncProvider
2+
3+
import (
4+
"github.com/devtron-labs/common-lib/async"
5+
"github.com/devtron-labs/common-lib/constants"
6+
"go.uber.org/zap"
7+
)
8+
9+
func NewAsyncRunnable(logger *zap.SugaredLogger) *async.Runnable {
10+
return async.NewAsyncRunnable(logger, constants.Orchestrator)
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package asyncProvider
2+
3+
import (
4+
"github.com/google/wire"
5+
)
6+
7+
var WireSet = wire.NewSet(
8+
NewAsyncRunnable,
9+
)

pkg/bean/app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ type CiPipeline struct {
141141
EnableCustomTag bool `json:"enableCustomTag"`
142142
}
143143

144+
func (ciPipeline *CiPipeline) IsLinkedCi() bool {
145+
return ciPipeline.IsExternal
146+
}
147+
144148
type DockerConfigOverride struct {
145149
DockerRegistry string `json:"dockerRegistry,omitempty"`
146150
DockerRepository string `json:"dockerRepository,omitempty"`

pkg/deployment/trigger/devtronApps/TriggerService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(ctx context.Context, pipeline
11701170
impl.logger.Infow("received payload, updateArgoPipeline", "appId", pipeline.AppId, "pipelineName", pipeline.Name, "envId", envOverride.TargetEnvironment, "argoAppName", argoAppName)
11711171
argoApplication, err := impl.argoClientWrapperService.GetArgoAppByName(newCtx, argoAppName)
11721172
if err != nil {
1173-
impl.logger.Errorw("no argo app exists", "app", argoAppName, "pipeline", pipeline.Name)
1173+
impl.logger.Errorw("unable to get ArgoCd app", "app", argoAppName, "pipeline", pipeline.Name, "err", err)
11741174
return false, err
11751175
}
11761176
//if status, ok:=status.FromError(err);ok{

0 commit comments

Comments
 (0)