Skip to content

Commit da02302

Browse files
authored
Merge branch 'develop' into fix-webhook-unreachable-cd-delet
2 parents 7489684 + 943d18f commit da02302

Some content is hidden

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

45 files changed

+1578
-913
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/NotificationRestHandler.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const (
5151
)
5252

5353
type NotificationRestHandler interface {
54-
SaveNotificationSettings(w http.ResponseWriter, r *http.Request)
5554
SaveNotificationSettingsV2(w http.ResponseWriter, r *http.Request)
5655
UpdateNotificationSettings(w http.ResponseWriter, r *http.Request)
5756
SaveNotificationChannelConfig(w http.ResponseWriter, r *http.Request)
@@ -118,66 +117,6 @@ func NewNotificationRestHandlerImpl(dockerRegistryConfig pipeline.DockerRegistry
118117
}
119118
}
120119

121-
// SaveNotificationSettings will be deprecated in future
122-
func (impl NotificationRestHandlerImpl) SaveNotificationSettings(w http.ResponseWriter, r *http.Request) {
123-
userId, err := impl.userAuthService.GetLoggedInUser(r)
124-
if userId == 0 || err != nil {
125-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
126-
return
127-
}
128-
var notificationSetting beans.NotificationRequest
129-
err = json.NewDecoder(r.Body).Decode(&notificationSetting)
130-
if err != nil {
131-
impl.logger.Errorw("request err, SaveNotificationSettings", "err", err, "payload", notificationSetting)
132-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
133-
return
134-
}
135-
impl.logger.Infow("request payload, SaveNotificationSettings", "err", err, "payload", notificationSetting)
136-
err = impl.validator.Struct(notificationSetting)
137-
if err != nil {
138-
impl.logger.Errorw("validation err, SaveNotificationSettings", "err", err, "payload", notificationSetting)
139-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
140-
return
141-
}
142-
143-
//RBAC
144-
token := r.Header.Get("token")
145-
if isSuperAdmin := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !isSuperAdmin {
146-
common.WriteJsonResp(w, err, nil, http.StatusForbidden)
147-
return
148-
}
149-
//RBAC
150-
151-
providers := notificationSetting.Providers
152-
153-
if len(providers) != 0 {
154-
for _, provider := range providers {
155-
if provider.Destination == util.SMTP || provider.Destination == util.SES {
156-
if provider.Recipient == "" {
157-
userEmail, err := impl.userAuthService.GetEmailById(int32(provider.ConfigId))
158-
if err != nil {
159-
impl.logger.Errorw("service err, SaveNotificationSettings", "err", err, "payload", notificationSetting)
160-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
161-
return
162-
}
163-
provider.Recipient = userEmail
164-
}
165-
// get default configID for SES and SMTP
166-
provider.ConfigId = notificationSetting.SesConfigId
167-
}
168-
}
169-
}
170-
171-
res, err := impl.notificationService.CreateOrUpdateNotificationSettings(&notificationSetting, userId)
172-
if err != nil {
173-
impl.logger.Errorw("service err, SaveNotificationSettings", "err", err, "payload", notificationSetting)
174-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
175-
return
176-
}
177-
w.Header().Set("Content-Type", "application/json")
178-
common.WriteJsonResp(w, nil, res, http.StatusOK)
179-
}
180-
181120
func (impl NotificationRestHandlerImpl) SaveNotificationSettingsV2(w http.ResponseWriter, r *http.Request) {
182121
userId, err := impl.userAuthService.GetLoggedInUser(r)
183122
if userId == 0 || 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)

api/router/NotificationRouter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func NewNotificationRouterImpl(notificationRestHandler restHandler.NotificationR
3232
return &NotificationRouterImpl{notificationRestHandler: notificationRestHandler}
3333
}
3434
func (impl NotificationRouterImpl) InitNotificationRegRouter(configRouter *mux.Router) {
35-
// to maintain backward compatibility, will be deprecated in future
35+
// do not remove it, this path is used in devtcl cli
3636
configRouter.Path("").
37-
HandlerFunc(impl.notificationRestHandler.SaveNotificationSettings).
37+
HandlerFunc(impl.notificationRestHandler.SaveNotificationSettingsV2).
3838
Methods("POST")
3939
// new router to save notification settings
4040
configRouter.Path("/v2").

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/events/EventBuilder.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ func (impl *EventSimpleFactoryImpl) BuildExtraCIData(event Event, material *buil
206206
payload.TriggeredBy = user.EmailId
207207
event.Payload = payload
208208
}
209+
210+
// fetching all the envs which are directly or indirectly linked with the ci pipeline
211+
if event.PipelineId > 0 {
212+
// Get the pipeline to check if it's external
213+
ciPipeline, err := impl.ciPipelineRepository.FindById(event.PipelineId)
214+
if err != nil {
215+
impl.logger.Errorw("error in getting ci pipeline", "pipelineId", event.PipelineId, "err", err)
216+
} else {
217+
envs, err := impl.envRepository.FindEnvLinkedWithCiPipelines(ciPipeline.IsExternal, []int{event.PipelineId})
218+
if err != nil {
219+
impl.logger.Errorw("error in finding environments linked with ci pipeline", "pipelineId", event.PipelineId, "err", err)
220+
} else {
221+
event.EnvIdsForCiPipeline = make([]int, 0, len(envs))
222+
for _, env := range envs {
223+
event.EnvIdsForCiPipeline = append(event.EnvIdsForCiPipeline, env.Id)
224+
}
225+
}
226+
}
227+
}
228+
209229
return event
210230
}
211231

0 commit comments

Comments
 (0)