Skip to content

Commit 2d09f1f

Browse files
committed
Merge branch 'develop' into create-cm-on-cluster-action-oss
# Conflicts: # go.mod # go.sum # vendor/modules.txt
2 parents 976f93b + a4309c4 commit 2d09f1f

File tree

29 files changed

+230
-133
lines changed

29 files changed

+230
-133
lines changed

api/helm-app/gRPC/applicationClient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (impl *HelmAppClientImpl) getConnection() (*grpc.ClientConn, error) {
107107
grpc.MaxCallRecvMsgSize(impl.grpcConfig.KubelinkMaxSendMsgSize*1024*1024), // GRPC Request size
108108
grpc.MaxCallSendMsgSize(impl.grpcConfig.KubelinkMaxRecvMsgSize*1024*1024), // GRPC Response size
109109
),
110-
grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
110+
grpc.WithDefaultServiceConfig(impl.grpcConfig.KubelinkGRPCServiceConfig),
111111
)
112112
endpoint := fmt.Sprintf("dns:///%s", impl.helmClientConfig.Url)
113113
conn, err := grpc.DialContext(ctx, endpoint, opts...)

api/restHandler/BatchOperationRestHandler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"errors"
2323
"net/http"
2424

25+
"github.com/devtron-labs/common-lib/async"
2526
"github.com/devtron-labs/devtron/api/restHandler/common"
2627
"github.com/devtron-labs/devtron/pkg/apis/devtron/v1"
2728
"github.com/devtron-labs/devtron/pkg/apis/devtron/v1/validation"
@@ -44,17 +45,19 @@ type BatchOperationRestHandlerImpl struct {
4445
teamService team.TeamService
4546
logger *zap.SugaredLogger
4647
enforcerUtil rbac.EnforcerUtil
48+
asyncRunnable *async.Runnable
4749
}
4850

4951
func NewBatchOperationRestHandlerImpl(userAuthService user.UserService, enforcer casbin.Enforcer, workflowAction batch.WorkflowAction,
50-
teamService team.TeamService, logger *zap.SugaredLogger, enforcerUtil rbac.EnforcerUtil) *BatchOperationRestHandlerImpl {
52+
teamService team.TeamService, logger *zap.SugaredLogger, enforcerUtil rbac.EnforcerUtil, asyncRunnable *async.Runnable) *BatchOperationRestHandlerImpl {
5153
return &BatchOperationRestHandlerImpl{
5254
userAuthService: userAuthService,
5355
enforcer: enforcer,
5456
workflowAction: workflowAction,
5557
teamService: teamService,
5658
logger: logger,
5759
enforcerUtil: enforcerUtil,
60+
asyncRunnable: asyncRunnable,
5861
}
5962
}
6063

@@ -104,13 +107,14 @@ func (handler BatchOperationRestHandlerImpl) Operate(w http.ResponseWriter, r *h
104107

105108
ctx, cancel := context.WithCancel(r.Context())
106109
if cn, ok := w.(http.CloseNotifier); ok {
107-
go func(done <-chan struct{}, closed <-chan bool) {
110+
runnableFunc := func(done <-chan struct{}, closed <-chan bool) {
108111
select {
109112
case <-done:
110113
case <-closed:
111114
cancel()
112115
}
113-
}(ctx.Done(), cn.CloseNotify())
116+
}
117+
handler.asyncRunnable.Execute(func() { runnableFunc(ctx.Done(), cn.CloseNotify()) })
114118
}
115119
err = handler.workflowAction.Execute(&workflow, emptyProps, r.Context())
116120
if err != nil {

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,16 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildLogs(w http.ResponseWriter
10851085
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
10861086
return
10871087
}
1088+
followLogs := true
1089+
if ok := r.URL.Query().Has("followLogs"); ok {
1090+
followLogsStr := r.URL.Query().Get("followLogs")
1091+
follow, err := strconv.ParseBool(followLogsStr)
1092+
if err != nil {
1093+
common.WriteJsonResp(w, err, "followLogs is not a valid bool", http.StatusBadRequest)
1094+
return
1095+
}
1096+
followLogs = follow
1097+
}
10881098

10891099
workflowId, err := strconv.Atoi(vars["workflowId"])
10901100
if err != nil {
@@ -1116,7 +1126,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildLogs(w http.ResponseWriter
11161126
return
11171127
}
11181128
}
1119-
logsReader, cleanUp, err := handler.ciHandlerService.GetRunningWorkflowLogs(workflowId)
1129+
logsReader, cleanUp, err := handler.ciHandlerService.GetRunningWorkflowLogs(workflowId, followLogs)
11201130
if err != nil {
11211131
handler.Logger.Errorw("service err, GetBuildLogs", "err", err, "pipelineId", pipelineId, "workflowId", workflowId, "lastEventId", lastEventId)
11221132
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,16 @@ func (handler *PipelineConfigRestHandlerImpl) GetPrePostDeploymentLogs(w http.Re
16091609
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
16101610
return
16111611
}
1612+
followLogs := true
1613+
if ok := r.URL.Query().Has("followLogs"); ok {
1614+
followLogsStr := r.URL.Query().Get("followLogs")
1615+
follow, err := strconv.ParseBool(followLogsStr)
1616+
if err != nil {
1617+
common.WriteJsonResp(w, err, "followLogs is not a valid bool", http.StatusBadRequest)
1618+
return
1619+
}
1620+
followLogs = follow
1621+
}
16121622
handler.Logger.Infow("request payload, GetPrePostDeploymentLogs", "err", err, "appId", appId, "environmentId", environmentId, "pipelineId", pipelineId, "workflowId", workflowId)
16131623

16141624
// RBAC CHECK
@@ -1619,7 +1629,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetPrePostDeploymentLogs(w http.Re
16191629
}
16201630
// RBAC CHECK
16211631

1622-
logsReader, cleanUp, err := handler.cdHandlerService.GetRunningWorkflowLogs(environmentId, pipelineId, workflowId)
1632+
logsReader, cleanUp, err := handler.cdHandlerService.GetRunningWorkflowLogs(environmentId, pipelineId, workflowId, followLogs)
16231633
if err != nil {
16241634
handler.Logger.Errorw("service err, GetPrePostDeploymentLogs", "err", err, "appId", appId, "environmentId", environmentId, "pipelineId", pipelineId, "workflowId", workflowId)
16251635
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

client/argocdServer/connection/Connection.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"github.com/argoproj/argo-cd/v2/pkg/apiclient/account"
2323
"github.com/argoproj/argo-cd/v2/util/settings"
24+
"github.com/devtron-labs/common-lib/async"
2425
"github.com/devtron-labs/common-lib/utils/k8s"
2526
"github.com/devtron-labs/devtron/client/argocdServer/bean"
2627
config2 "github.com/devtron-labs/devtron/client/argocdServer/config"
@@ -81,6 +82,7 @@ type ArgoCDConnectionManagerImpl struct {
8182
gitOpsConfigReadService config.GitOpsConfigReadService
8283
runTimeConfig *k8s.RuntimeConfig
8384
argoCDConfigGetter config2.ArgoCDConfigGetter
85+
asyncRunnable *async.Runnable
8486
}
8587

8688
func NewArgoCDConnectionManagerImpl(Logger *zap.SugaredLogger,
@@ -92,7 +94,8 @@ func NewArgoCDConnectionManagerImpl(Logger *zap.SugaredLogger,
9294
versionService version.VersionService,
9395
gitOpsConfigReadService config.GitOpsConfigReadService,
9496
runTimeConfig *k8s.RuntimeConfig,
95-
argoCDConfigGetter config2.ArgoCDConfigGetter) (*ArgoCDConnectionManagerImpl, error) {
97+
argoCDConfigGetter config2.ArgoCDConfigGetter,
98+
asyncRunnable *async.Runnable) (*ArgoCDConnectionManagerImpl, error) {
9699
argoUserServiceImpl := &ArgoCDConnectionManagerImpl{
97100
logger: Logger,
98101
settingsManager: settingsManager,
@@ -105,13 +108,17 @@ func NewArgoCDConnectionManagerImpl(Logger *zap.SugaredLogger,
105108
gitOpsConfigReadService: gitOpsConfigReadService,
106109
runTimeConfig: runTimeConfig,
107110
argoCDConfigGetter: argoCDConfigGetter,
111+
asyncRunnable: asyncRunnable,
108112
}
109113
if !runTimeConfig.LocalDevMode {
110114
grpcConfig, err := argoCDConfigGetter.GetGRPCConfig()
111115
if err != nil {
112116
Logger.Errorw("error in GetAllGRPCConfigs", "error", err)
113117
}
114-
go argoUserServiceImpl.ValidateGitOpsAndGetOrUpdateArgoCdUserDetail(grpcConfig)
118+
runnableFunc := func() {
119+
argoUserServiceImpl.ValidateGitOpsAndGetOrUpdateArgoCdUserDetail(grpcConfig)
120+
}
121+
asyncRunnable.Execute(runnableFunc)
115122
}
116123
return argoUserServiceImpl, nil
117124
}

client/gitSensor/GitSensorClient.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ func NewGitSensorClient(logger *zap.SugaredLogger, config *ClientConfig) (*Clien
8181

8282
// CATEGORY=INFRA_SETUP
8383
type ClientConfig struct {
84-
Url string `env:"GIT_SENSOR_URL" envDefault:"127.0.0.1:7070" description:"git-sensor micro-service url "`
85-
Protocol string `env:"GIT_SENSOR_PROTOCOL" envDefault:"REST" description:"Protocol to connect with git-sensor micro-service"`
86-
Timeout int `env:"GIT_SENSOR_TIMEOUT" envDefault:"0" description:"Timeout for getting response from the git-sensor"` // in seconds
84+
Url string `env:"GIT_SENSOR_URL" envDefault:"127.0.0.1:7070" description:"git-sensor micro-service url "`
85+
Protocol string `env:"GIT_SENSOR_PROTOCOL" envDefault:"REST" description:"Protocol to connect with git-sensor micro-service"`
86+
Timeout int `env:"GIT_SENSOR_TIMEOUT" envDefault:"0" description:"Timeout for getting response from the git-sensor"` // in seconds
87+
ServiceConfig string `env:"GIT_SENSOR_SERVICE_CONFIG" envDefault:"{\"loadBalancingPolicy\":\"pick_first\"}" description:"git-sensor grpc service config"`
8788
}
8889

8990
func GetConfig() (*ClientConfig, error) {

client/gitSensor/GitSensorGrpcClient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (client *GrpcApiClientImpl) getConnection() (*grpc.ClientConn, error) {
9090
grpc.WithChainUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor, otelgrpc.UnaryClientInterceptor()),
9191
grpc.WithBlock(),
9292
grpc.WithTransportCredentials(insecure.NewCredentials()),
93-
grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
93+
grpc.WithDefaultServiceConfig(client.config.ServiceConfig),
9494
)
9595
endpoint := fmt.Sprintf("dns:///%s", client.config.Url)
9696

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.

internal/sql/repository/appWorkflow/AppWorkflowRepository.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type AppWorkflowRepository interface {
3232
FindByIds(ids []int) (*AppWorkflow, error)
3333
FindByAppId(appId int) (appWorkflow []*AppWorkflow, err error)
3434
FindByAppIds(appIds []int) (appWorkflow []*AppWorkflow, err error)
35-
DeleteAppWorkflow(appWorkflow *AppWorkflow, tx *pg.Tx) error
35+
DeleteAppWorkflowAndAllMappings(appWorkflow *AppWorkflow, tx *pg.Tx) error
3636

3737
SaveAppWorkflowMapping(wf *AppWorkflowMapping, tx *pg.Tx) (*AppWorkflowMapping, error)
3838
FindByWorkflowId(workflowId int) ([]*AppWorkflowMapping, error)
@@ -164,26 +164,21 @@ func (impl AppWorkflowRepositoryImpl) FindByIds(ids []int) (*AppWorkflow, error)
164164
return appWorkflow, err
165165
}
166166

167-
func (impl AppWorkflowRepositoryImpl) DeleteAppWorkflow(appWorkflow *AppWorkflow, tx *pg.Tx) error {
168-
appWorkflowMappings, err := impl.FindWFCIMappingByWorkflowId(appWorkflow.Id)
169-
if err != nil && pg.ErrNoRows != err {
170-
impl.Logger.Errorw("err", err)
171-
return err
172-
}
173-
if len(appWorkflowMappings) > 0 {
174-
for _, item := range appWorkflowMappings {
175-
err = impl.DeleteAppWorkflowMapping(item, tx)
176-
if err != nil {
177-
impl.Logger.Errorw("err", err)
178-
return err
179-
}
167+
func (impl AppWorkflowRepositoryImpl) DeleteAppWorkflowAndAllMappings(appWorkflow *AppWorkflow, tx *pg.Tx) error {
168+
// Delete app workflow mapping
169+
mapping, err := impl.FindWFAllMappingByWorkflowId(appWorkflow.Id)
170+
for _, item := range mapping {
171+
err := impl.DeleteAppWorkflowMapping(item, tx)
172+
if err != nil {
173+
impl.Logger.Errorw("error in deleting workflow mapping", "err", err)
174+
return err
180175
}
181176
}
182177

183178
appWorkflow.Active = false
184-
err = impl.dbConnection.Update(appWorkflow)
179+
err = tx.Update(appWorkflow)
185180
if err != nil {
186-
impl.Logger.Errorw("err", err)
181+
impl.Logger.Errorw("error in deleting app workflow", "appWorkflow", appWorkflow, "err", err)
187182
return err
188183
}
189184
return nil

pkg/app/AppService.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"net/url"
24+
"strconv"
25+
"time"
26+
2327
health2 "github.com/argoproj/gitops-engine/pkg/health"
2428
argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean"
2529
"github.com/devtron-labs/devtron/internal/sql/models"
@@ -40,12 +44,10 @@ import (
4044
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read"
4145
bean4 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
4246
"github.com/devtron-labs/devtron/pkg/workflow/cd"
43-
"net/url"
44-
"strconv"
45-
"time"
4647

4748
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
4849
"github.com/caarlos0/env"
50+
"github.com/devtron-labs/common-lib/async"
4951
k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean"
5052
"github.com/devtron-labs/common-lib/utils/k8s/health"
5153
"github.com/devtron-labs/devtron/api/bean"
@@ -124,6 +126,7 @@ type AppServiceImpl struct {
124126
deploymentConfigService common2.DeploymentConfigService
125127
envConfigOverrideReadService read.EnvConfigOverrideService
126128
cdWorkflowRunnerService cd.CdWorkflowRunnerService
129+
asyncRunnable *async.Runnable
127130
}
128131

129132
type AppService interface {
@@ -164,7 +167,8 @@ func NewAppService(
164167
appListingService AppListingService,
165168
deploymentConfigService common2.DeploymentConfigService,
166169
envConfigOverrideReadService read.EnvConfigOverrideService,
167-
cdWorkflowRunnerService cd.CdWorkflowRunnerService) *AppServiceImpl {
170+
cdWorkflowRunnerService cd.CdWorkflowRunnerService,
171+
asyncRunnable *async.Runnable) *AppServiceImpl {
168172
appServiceImpl := &AppServiceImpl{
169173
mergeUtil: mergeUtil,
170174
pipelineOverrideRepository: pipelineOverrideRepository,
@@ -195,6 +199,7 @@ func NewAppService(
195199
deploymentConfigService: deploymentConfigService,
196200
envConfigOverrideReadService: envConfigOverrideReadService,
197201
cdWorkflowRunnerService: cdWorkflowRunnerService,
202+
asyncRunnable: asyncRunnable,
198203
}
199204
return appServiceImpl
200205
}
@@ -320,7 +325,7 @@ func (impl *AppServiceImpl) UpdateDeploymentStatusForGitOpsPipelines(app *v1alph
320325
}
321326
if isSucceeded {
322327
impl.logger.Infow("writing cd success event", "gitHash", gitHash, "pipelineOverride", pipelineOverride)
323-
go impl.WriteCDSuccessEvent(cdPipeline.AppId, cdPipeline.EnvironmentId, pipelineOverride)
328+
impl.asyncRunnable.Execute(func() { impl.WriteCDSuccessEvent(cdPipeline.AppId, cdPipeline.EnvironmentId, pipelineOverride) })
324329
}
325330
} else {
326331
impl.logger.Debugw("event received for older triggered revision", "gitHash", gitHash)

0 commit comments

Comments
 (0)