Skip to content

Commit 45fe19f

Browse files
authored
feat: Async ArgoCd App refresh operation (#5448)
* feat: Async ArgoCd app refresh operation * feat: updated async wrapper * common-lib: beta version * fix: EA mode build issue * chore: refactoring and renaming * common-lib version * chore: updated common-lib version * chore: updated logging * chore: updated common-lib version * fix: gorountine context handling
1 parent 055612a commit 45fe19f

File tree

18 files changed

+215
-30
lines changed

18 files changed

+215
-30
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=

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

util/reflectUtil/ReflectUtil.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package reflectUtil
2+
3+
import "reflect"
4+
5+
func IsNullableValue(field reflect.Value) bool {
6+
kind := field.Kind()
7+
switch kind {
8+
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer,
9+
reflect.Interface, reflect.Slice:
10+
return true
11+
default: //other types can not be nil
12+
return false
13+
}
14+
}

vendor/github.com/devtron-labs/common-lib/async/async.go

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/devtron-labs/common-lib/constants/constants.go

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

vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/devtron-labs/common-lib/utils/runTime/GetCallerFrames.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)