Skip to content

feat: Async ArgoCd App refresh operation #5448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import (
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deploymentTypeChange"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource"
"github.com/devtron-labs/devtron/pkg/appWorkflow"
"github.com/devtron-labs/devtron/pkg/asyncProvider"
"github.com/devtron-labs/devtron/pkg/attributes"
"github.com/devtron-labs/devtron/pkg/build"
"github.com/devtron-labs/devtron/pkg/bulkAction"
Expand Down Expand Up @@ -229,6 +230,10 @@ func InitializeApp() (*App, error) {
wire.Bind(new(router.PProfRouter), new(*router.PProfRouterImpl)),
// ---- pprof end ----

// ---- goroutine async wrapper service start ----
asyncProvider.WireSet,
// ---- goroutine async wrapper service end ----

sql.NewTransactionUtilImpl,
wire.Bind(new(sql.TransactionWrapper), new(*sql.TransactionUtilImpl)),

Expand Down
10 changes: 2 additions & 8 deletions WiringNilCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"fmt"
"github.com/devtron-labs/devtron/util/reflectUtil"
"log"
"os"
"reflect"
Expand Down Expand Up @@ -81,14 +82,7 @@ func checkNilFields(obj interface{}, nilObjMap map[string]bool) {
}

func canFieldTypeBeNil(field reflect.Value) bool {
kind := field.Kind()
switch kind {
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer,
reflect.Interface, reflect.Slice:
return true
default: //other types can not be nil
return false
}
return reflectUtil.IsNullableValue(field)
}

func canSkipFieldStructCheck(fieldName, valName string) bool {
Expand Down
22 changes: 16 additions & 6 deletions client/argocdServer/ArgoClientWrapperService.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/caarlos0/env"
"github.com/devtron-labs/common-lib/async"
"github.com/devtron-labs/devtron/client/argocdServer/adapter"
"github.com/devtron-labs/devtron/client/argocdServer/application"
"github.com/devtron-labs/devtron/client/argocdServer/bean"
Expand Down Expand Up @@ -104,25 +105,29 @@ type ArgoClientWrapperServiceImpl struct {
repositoryService repository.ServiceClient
gitOpsConfigReadService config.GitOpsConfigReadService
gitOperationService git.GitOperationService
asyncRunnable *async.Runnable
}

func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient application.ServiceClient,
ACDConfig *ACDConfig, repositoryService repository.ServiceClient, gitOpsConfigReadService config.GitOpsConfigReadService,
gitOperationService git.GitOperationService) *ArgoClientWrapperServiceImpl {
gitOperationService git.GitOperationService, asyncRunnable *async.Runnable) *ArgoClientWrapperServiceImpl {
return &ArgoClientWrapperServiceImpl{
logger: logger,
acdClient: acdClient,
ACDConfig: ACDConfig,
repositoryService: repositoryService,
gitOpsConfigReadService: gitOpsConfigReadService,
gitOperationService: gitOperationService,
asyncRunnable: asyncRunnable,
}
}

func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(context context.Context, argoAppName string) error {
func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(ctx context.Context, argoAppName string) error {
newCtx, span := otel.Tracer("orchestrator").Start(ctx, "ArgoClientWrapperServiceImpl.GetArgoAppWithNormalRefresh")
defer span.End()
refreshType := bean.RefreshTypeNormal
impl.logger.Debugw("trying to normal refresh application through get ", "argoAppName", argoAppName)
_, err := impl.acdClient.Get(context, &application2.ApplicationQuery{Name: &argoAppName, Refresh: &refreshType})
_, err := impl.acdClient.Get(newCtx, &application2.ApplicationQuery{Name: &argoAppName, Refresh: &refreshType})
if err != nil {
internalMsg := fmt.Sprintf("%s, err:- %s", constants.CannotGetAppWithRefreshErrMsg, err.Error())
clientCode, _ := util.GetClientDetailedError(err)
Expand Down Expand Up @@ -177,10 +182,15 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres
}
impl.logger.Infow("ArgoCd sync completed", "argoAppName", argoAppName)
}
refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName)
if refreshErr != nil {
impl.logger.Errorw("error in refreshing argo app", "err", refreshErr)

runnableFunc := func() {
// running ArgoCd app refresh in asynchronous mode
refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName)
if refreshErr != nil {
impl.logger.Errorw("error in refreshing argo app", "argoAppName", argoAppName, "err", refreshErr)
}
}
impl.asyncRunnable.Execute(runnableFunc)
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions client/argocdServer/application/Application.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ func (c ServiceClientImpl) Patch(ctxt context.Context, query *application.Applic
return resp, err
}

func (c ServiceClientImpl) Get(ctxt context.Context, query *application.ApplicationQuery) (*v1alpha1.Application, error) {
ctx, cancel := context.WithTimeout(ctxt, argoApplication.TimeoutFast)
defer cancel()
token, ok := ctxt.Value("token").(string)
func (c ServiceClientImpl) Get(ctx context.Context, query *application.ApplicationQuery) (*v1alpha1.Application, error) {
token, ok := ctx.Value("token").(string)
if !ok {
return nil, errors.New("Unauthorized")
}
newCtx, cancel := context.WithTimeout(ctx, argoApplication.TimeoutFast)
defer cancel()
conn := c.argoCDConnectionManager.GetConnection(token)
defer util.Close(conn, c.logger)
asc := application.NewApplicationServiceClient(conn)
resp, err := asc.Get(ctx, query)
resp, err := asc.Get(newCtx, query)
return resp, err
}

Expand Down
2 changes: 1 addition & 1 deletion env_gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
| NATS_MSG_BUFFER_SIZE | -1 | |
| NATS_MSG_MAX_AGE | 86400 | |
| NATS_MSG_PROCESSING_BATCH_SIZE | 1 | |
| NATS_MSG_REPLICAS | 0 | |
| NATS_SERVER_HOST | nats://devtron-nats.devtroncd:4222 | |
| NOTIFICATION_MEDIUM | rest | |
| ORCH_HOST | http://devtroncd-orchestrator-service-prod.devtroncd/webhook/msg/nats | |
Expand All @@ -210,7 +211,6 @@
| PRE_CI_CACHE_PATH | /devtroncd-cache | |
| PROPAGATE_EXTRA_LABELS | false | |
| PROXY_SERVICE_CONFIG | {} | |
| REPLICAS | 0 | |
| REQ_CI_CPU | 0.5 | |
| REQ_CI_MEM | 3G | |
| RESOURCE_LIST_FOR_REPLICAS | Deployment,Rollout,StatefulSet,ReplicaSet | |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160
github.com/devtron-labs/common-lib v0.0.23-beta2
github.com/devtron-labs/go-bitbucket v0.9.60-beta
github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1
github.com/evanphx/json-patch v5.7.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY=
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc=
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160 h1:9iumIJmRId91aUcyPkxPb6nvjhHuYDoAgomNSG6OIdE=
github.com/devtron-labs/common-lib v0.0.22-0.20240705073412-32e32c499160/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
github.com/devtron-labs/common-lib v0.0.23-beta2 h1:wEyNdHVHUm14V6+DC/ct+03O21QJEQqUz6sqJg1XNYs=
github.com/devtron-labs/common-lib v0.0.23-beta2/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type EAModeDeploymentService interface {
GetDeploymentHistory(ctx context.Context, installedApp *appStoreBean.InstallAppVersionDTO) (*gRPC.HelmAppDeploymentHistory, error)
GetDeploymentHistoryInfo(ctx context.Context, installedApp *appStoreBean.InstallAppVersionDTO, version int32) (*openapi.HelmAppDeploymentManifestDetail, error)
UpgradeDeployment(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ChartGitAttribute *commonBean.ChartGitAttribute, installedAppVersionHistoryId int, ctx context.Context) error
GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error)
}

type EAModeDeploymentServiceImpl struct {
Expand Down Expand Up @@ -442,6 +441,7 @@ func (impl *EAModeDeploymentServiceImpl) GetChartBytesForParticularDeployment(in
func (impl *EAModeDeploymentServiceImpl) DeleteACD(acdAppName string, ctx context.Context, isNonCascade bool) error {
return errors.New("this is not implemented")
}

func (impl *EAModeDeploymentServiceImpl) GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error) {
return "", errors.New("this is not implemented")
}
11 changes: 11 additions & 0 deletions pkg/asyncProvider/AsyncProvider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package asyncProvider

import (
"github.com/devtron-labs/common-lib/async"
"github.com/devtron-labs/common-lib/constants"
"go.uber.org/zap"
)

func NewAsyncRunnable(logger *zap.SugaredLogger) *async.Runnable {
return async.NewAsyncRunnable(logger, constants.Orchestrator)
}
9 changes: 9 additions & 0 deletions pkg/asyncProvider/wire_AsyncProvider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package asyncProvider

import (
"github.com/google/wire"
)

var WireSet = wire.NewSet(
NewAsyncRunnable,
)
14 changes: 14 additions & 0 deletions util/reflectUtil/ReflectUtil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package reflectUtil

import "reflect"

func IsNullableValue(field reflect.Value) bool {
kind := field.Kind()
switch kind {
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer,
reflect.Interface, reflect.Slice:
return true
default: //other types can not be nil
return false
}
}
73 changes: 73 additions & 0 deletions vendor/github.com/devtron-labs/common-lib/async/async.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading