Skip to content
12 changes: 8 additions & 4 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/client/argocdServer/application"
cluster2 "github.com/devtron-labs/devtron/client/argocdServer/cluster"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
repository2 "github.com/devtron-labs/devtron/client/argocdServer/repository"
session2 "github.com/devtron-labs/devtron/client/argocdServer/session"
"github.com/devtron-labs/devtron/client/cron"
Expand Down Expand Up @@ -171,10 +172,10 @@ func InitializeApp() (*App, error) {
wire.Value(appStoreBean.RefChartProxyDir("scripts/devtron-reference-helm-charts")),
wire.Value(chart.DefaultChart("reference-app-rolling")),
wire.Value(util.ChartWorkingDir("/tmp/charts/")),
argocdServer.SettingsManager,
connection.SettingsManager,
//auth.GetConfig,

argocdServer.GetConfig,
connection.GetConfig,
wire.Bind(new(session2.ServiceClient), new(*middleware.LoginService)),

sse.NewSSE,
Expand Down Expand Up @@ -814,8 +815,8 @@ func InitializeApp() (*App, error) {
wire.Bind(new(pipeline.PipelineStageService), new(*pipeline.PipelineStageServiceImpl)),
//plugin ends

argocdServer.NewArgoCDConnectionManagerImpl,
wire.Bind(new(argocdServer.ArgoCDConnectionManager), new(*argocdServer.ArgoCDConnectionManagerImpl)),
connection.NewArgoCDConnectionManagerImpl,
wire.Bind(new(connection.ArgoCDConnectionManager), new(*connection.ArgoCDConnectionManagerImpl)),
argo.NewArgoUserServiceImpl,
wire.Bind(new(argo.ArgoUserService), new(*argo.ArgoUserServiceImpl)),
util2.GetDevtronSecretName,
Expand Down Expand Up @@ -943,6 +944,9 @@ func InitializeApp() (*App, error) {

devtronResource.NewDevtronResourceSearchableKeyServiceImpl,
wire.Bind(new(devtronResource.DevtronResourceService), new(*devtronResource.DevtronResourceSearchableKeyServiceImpl)),

argocdServer.NewArgoClientWrapperServiceImpl,
wire.Bind(new(argocdServer.ArgoClientWrapperService), new(*argocdServer.ArgoClientWrapperServiceImpl)),
)
return &App{}, nil
}
39 changes: 39 additions & 0 deletions client/argocdServer/ArgoClientWrapperService.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package argocdServer

import (
"context"
application2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/devtron-labs/devtron/client/argocdServer/application"
"github.com/devtron-labs/devtron/client/argocdServer/bean"
"go.uber.org/zap"
)

type ArgoClientWrapperService interface {
GetArgoAppWithNormalRefresh(context context.Context, argoAppName string) error
}

type ArgoClientWrapperServiceImpl struct {
logger *zap.SugaredLogger
acdClient application.ServiceClient
}

func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger,
acdClient application.ServiceClient,
) *ArgoClientWrapperServiceImpl {
return &ArgoClientWrapperServiceImpl{
logger: logger,
acdClient: acdClient,
}
}

func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(context context.Context, argoAppName string) error {
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})
if err != nil {
impl.logger.Errorw("cannot get application with refresh", "app", argoAppName)
return err
}
impl.logger.Debugw("done getting the application with refresh with no error", "argoAppName", argoAppName)
return nil
}
5 changes: 3 additions & 2 deletions client/argocdServer/Version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package argocdServer
import (
"context"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/version"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"github.com/golang/protobuf/ptypes/empty"
"go.uber.org/zap"
)
Expand All @@ -31,10 +32,10 @@ type VersionService interface {

type VersionServiceImpl struct {
logger *zap.SugaredLogger
argoCDConnectionManager ArgoCDConnectionManager
argoCDConnectionManager connection.ArgoCDConnectionManager
}

func NewVersionServiceImpl(logger *zap.SugaredLogger, argoCDConnectionManager ArgoCDConnectionManager) *VersionServiceImpl {
func NewVersionServiceImpl(logger *zap.SugaredLogger, argoCDConnectionManager connection.ArgoCDConnectionManager) *VersionServiceImpl {
return &VersionServiceImpl{logger: logger, argoCDConnectionManager: argoCDConnectionManager}
}

Expand Down
6 changes: 3 additions & 3 deletions client/argocdServer/application/Application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"errors"
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/bean"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"strings"
"time"

"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/util"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand Down Expand Up @@ -116,11 +116,11 @@ type Manifests struct {

type ServiceClientImpl struct {
logger *zap.SugaredLogger
argoCDConnectionManager argocdServer.ArgoCDConnectionManager
argoCDConnectionManager connection.ArgoCDConnectionManager
}

func NewApplicationClientImpl(
logger *zap.SugaredLogger, argoCDConnectionManager argocdServer.ArgoCDConnectionManager,
logger *zap.SugaredLogger, argoCDConnectionManager connection.ArgoCDConnectionManager,
) *ServiceClientImpl {
return &ServiceClientImpl{
logger: logger,
Expand Down
3 changes: 3 additions & 0 deletions client/argocdServer/bean/bean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package bean

const RefreshTypeNormal = "normal"
6 changes: 3 additions & 3 deletions client/argocdServer/cluster/Cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"errors"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"go.uber.org/zap"
"time"
)
Expand All @@ -44,10 +44,10 @@ type ServiceClient interface {

type ServiceClientImpl struct {
logger *zap.SugaredLogger
argoCdConnection argocdServer.ArgoCDConnectionManager
argoCdConnection connection.ArgoCDConnectionManager
}

func NewServiceClientImpl(logger *zap.SugaredLogger, argoCdConnection argocdServer.ArgoCDConnectionManager) *ServiceClientImpl {
func NewServiceClientImpl(logger *zap.SugaredLogger, argoCdConnection connection.ArgoCDConnectionManager) *ServiceClientImpl {
return &ServiceClientImpl{
logger: logger,
argoCdConnection: argoCdConnection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package argocdServer
package connection

import (
"github.com/caarlos0/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package argocdServer
package connection

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package argocdServer
package connection

import (
"crypto/ecdsa"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package argocdServer
package connection

import "context"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package argocdServer
package connection

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package argocdServer
package connection

import "testing"

Expand Down
6 changes: 3 additions & 3 deletions client/argocdServer/repository/Repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/client/argocdServer/application"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"go.uber.org/zap"
)

Expand All @@ -45,10 +45,10 @@ type ServiceClient interface {

type ServiceClientImpl struct {
logger *zap.SugaredLogger
argoCDConnectionManager argocdServer.ArgoCDConnectionManager
argoCDConnectionManager connection.ArgoCDConnectionManager
}

func NewServiceClientImpl(logger *zap.SugaredLogger, argoCDConnectionManager argocdServer.ArgoCDConnectionManager) *ServiceClientImpl {
func NewServiceClientImpl(logger *zap.SugaredLogger, argoCDConnectionManager connection.ArgoCDConnectionManager) *ServiceClientImpl {
return &ServiceClientImpl{
logger: logger,
argoCDConnectionManager: argoCDConnectionManager,
Expand Down
4 changes: 2 additions & 2 deletions client/argocdServer/session/Session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package session
import (
"context"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/session"
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"time"
)

Expand All @@ -32,7 +32,7 @@ type ServiceClientImpl struct {
ssc session.SessionServiceClient
}

func NewSessionServiceClient(argoCDConnectionManager argocdServer.ArgoCDConnectionManager) *ServiceClientImpl {
func NewSessionServiceClient(argoCDConnectionManager connection.ArgoCDConnectionManager) *ServiceClientImpl {
// this function only called when gitops configured and user ask for creating acd token
conn := argoCDConnectionManager.GetConnection("")
ssc := session.NewSessionServiceClient(conn)
Expand Down
11 changes: 10 additions & 1 deletion pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type AppServiceImpl struct {
scopedVariableService variables.ScopedVariableService
variableEntityMappingService variables.VariableEntityMappingService
variableTemplateParser parsers.VariableTemplateParser
argoClientWrapperService argocdServer.ArgoClientWrapperService
}

type AppService interface {
Expand Down Expand Up @@ -261,7 +262,9 @@ func NewAppService(
variableSnapshotHistoryService variables.VariableSnapshotHistoryService,
scopedVariableService variables.ScopedVariableService,
variableEntityMappingService variables.VariableEntityMappingService,
variableTemplateParser parsers.VariableTemplateParser) *AppServiceImpl {
variableTemplateParser parsers.VariableTemplateParser,
argoClientWrapperService argocdServer.ArgoClientWrapperService,
) *AppServiceImpl {
appServiceImpl := &AppServiceImpl{
environmentConfigRepository: environmentConfigRepository,
mergeUtil: mergeUtil,
Expand Down Expand Up @@ -326,6 +329,7 @@ func NewAppService(
scopedVariableService: scopedVariableService,
variableEntityMappingService: variableEntityMappingService,
variableTemplateParser: variableTemplateParser,
argoClientWrapperService: argoClientWrapperService,
}
return appServiceImpl
}
Expand Down Expand Up @@ -2707,6 +2711,11 @@ func (impl *AppServiceImpl) updateArgoPipeline(appId int, pipelineName string, e
} else {
impl.logger.Debug("pipeline no need to update ")
}
// Doing normal refresh to avoid the sync delay in argo-cd.
err2 := impl.argoClientWrapperService.GetArgoAppWithNormalRefresh(ctx, argoAppName)
if err2 != nil {
impl.logger.Errorw("error in getting argo application with normal refresh", "argoAppName", argoAppName, "pipelineName", pipelineName)
}
return true, nil
} else if appStatus.Code() == codes.NotFound {
impl.logger.Errorw("argo app not found", "app", argoAppName, "pipeline", pipelineName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type AppStoreDeploymentFullModeServiceImpl struct {
gitOpsConfigRepository repository3.GitOpsConfigRepository
pipelineStatusTimelineService status.PipelineStatusTimelineService
appStoreDeploymentCommonService appStoreDeploymentCommon.AppStoreDeploymentCommonService
argoClientWrapperService argocdServer.ArgoClientWrapperService
}

func NewAppStoreDeploymentFullModeServiceImpl(logger *zap.SugaredLogger,
Expand All @@ -101,6 +102,7 @@ func NewAppStoreDeploymentFullModeServiceImpl(logger *zap.SugaredLogger,
argoUserService argo.ArgoUserService, gitOpsConfigRepository repository3.GitOpsConfigRepository,
pipelineStatusTimelineService status.PipelineStatusTimelineService,
appStoreDeploymentCommonService appStoreDeploymentCommon.AppStoreDeploymentCommonService,
argoClientWrapperService argocdServer.ArgoClientWrapperService,
) *AppStoreDeploymentFullModeServiceImpl {
return &AppStoreDeploymentFullModeServiceImpl{
logger: logger,
Expand All @@ -120,6 +122,7 @@ func NewAppStoreDeploymentFullModeServiceImpl(logger *zap.SugaredLogger,
gitOpsConfigRepository: gitOpsConfigRepository,
pipelineStatusTimelineService: pipelineStatusTimelineService,
appStoreDeploymentCommonService: appStoreDeploymentCommonService,
argoClientWrapperService: argoClientWrapperService,
}
}

Expand Down Expand Up @@ -316,6 +319,12 @@ func (impl AppStoreDeploymentFullModeServiceImpl) AppStoreDeployOperationACD(ins
//STEP 6: Force Sync ACD - works like trigger deployment
//impl.SyncACD(installAppVersionRequest.ACDAppName, ctx)

//STEP 7: normal refresh ACD - update for step 6 to avoid delay
err = impl.argoClientWrapperService.GetArgoAppWithNormalRefresh(ctx, installAppVersionRequest.ACDAppName)
if err != nil {
impl.logger.Errorw("error in getting the argo application with normal refresh", "err", err)
}

return installAppVersionRequest, nil
}

Expand Down
12 changes: 5 additions & 7 deletions pkg/appStore/deployment/service/AppStoreDeploymentService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1485,13 +1485,11 @@ func (impl *AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Contex
}

if installAppVersionRequest.PerformACDDeployment {
if monoRepoMigrationRequired {
// update repo details on ArgoCD as repo is changed
err = impl.appStoreDeploymentArgoCdService.UpdateChartInfo(installAppVersionRequest, gitOpsResponse.ChartGitAttribute, 0, ctx)
if err != nil {
impl.logger.Errorw("error in acd patch request", "err", err)
return nil, err
}
// refresh update repo details on ArgoCD if repo is changed
err = impl.appStoreDeploymentArgoCdService.RefreshAndUpdateACDApp(installAppVersionRequest, gitOpsResponse.ChartGitAttribute, monoRepoMigrationRequired, ctx)
if err != nil {
impl.logger.Errorw("error in acd patch request", "err", err)
return nil, err
}
} else if installAppVersionRequest.PerformHelmDeployment {
err = impl.appStoreDeploymentHelmService.UpdateChartInfo(installAppVersionRequest, gitOpsResponse.ChartGitAttribute, installAppVersionRequest.InstalledAppVersionHistoryId, ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,10 @@ func (impl *AppStoreDeploymentHelmServiceImpl) SaveTimelineForACDHelmApps(instal
func (impl *AppStoreDeploymentHelmServiceImpl) UpdateInstalledAppAndPipelineStatusForFailedDeploymentStatus(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, triggeredAt time.Time, err error) error {
return nil
}

// TODO: Need to refactor this,refer below reason
// This is being done as in ea mode wire argocd service is being binded to helmServiceImpl due to which we are restricted to implement this here.
// RefreshAndUpdateACDApp this will update chart info in acd app if required in case of mono repo migration and will refresh argo app
func (impl *AppStoreDeploymentHelmServiceImpl) RefreshAndUpdateACDApp(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ChartGitAttribute *util.ChartGitAttribute, isMonoRepoMigrationRequired bool, ctx context.Context) error {
return errors.New("this is not implemented")
}
Loading