Skip to content

Commit 566a6bc

Browse files
gireesh-naiduLaeeqdev
authored andcommitted
fix: update argo app repo url in patch (#4876)
1 parent a9ef491 commit 566a6bc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

client/argocdServer/ArgoClientWrapperService.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
type ACDConfig struct {
25-
ArgoCDAutoSyncEnabled bool `env:"ARGO_AUTO_SYNC_ENABLED" envDefault:"true"` //will gradually switch this flag to false in enterprise
25+
ArgoCDAutoSyncEnabled bool `env:"ARGO_AUTO_SYNC_ENABLED" envDefault:"true"` // will gradually switch this flag to false in enterprise
2626
}
2727

2828
func GetACDDeploymentConfig() (*ACDConfig, error) {
@@ -54,6 +54,9 @@ type ArgoClientWrapperService interface {
5454
// PatchArgoCdApp performs a patch operation on an argoCd app
5555
PatchArgoCdApp(ctx context.Context, dto *bean.ArgoCdAppPatchReqDto) error
5656

57+
// IsArgoAppPatchRequired decides weather the v1alpha1.ApplicationSource requires to be updated
58+
IsArgoAppPatchRequired(argoAppSpec *v1alpha1.ApplicationSource, currentGitRepoUrl, currentChartPath string) bool
59+
5760
// GetGitOpsRepoName returns the GitOps repository name, configured for the argoCd app
5861
GetGitOpsRepoName(ctx context.Context, appName string) (gitOpsRepoName string, err error)
5962
}
@@ -180,6 +183,12 @@ func (impl *ArgoClientWrapperServiceImpl) GetArgoAppByName(ctx context.Context,
180183
return argoApplication, nil
181184
}
182185

186+
func (impl *ArgoClientWrapperServiceImpl) IsArgoAppPatchRequired(argoAppSpec *v1alpha1.ApplicationSource, currentGitRepoUrl, currentChartPath string) bool {
187+
return (len(currentGitRepoUrl) != 0 && argoAppSpec.RepoURL != currentGitRepoUrl) ||
188+
argoAppSpec.Path != currentChartPath ||
189+
argoAppSpec.TargetRevision != bean.TargetRevisionMaster
190+
}
191+
183192
func (impl *ArgoClientWrapperServiceImpl) PatchArgoCdApp(ctx context.Context, dto *bean.ArgoCdAppPatchReqDto) error {
184193
patchReq := adapter.GetArgoCdPatchReqFromDto(dto)
185194
reqbyte, err := json.Marshal(patchReq)

pkg/deployment/trigger/devtronApps/TriggerService.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(pipeline *pipelineConfig.Pipe
10841084
appStatus, _ := status2.FromError(err)
10851085
if appStatus.Code() == codes.OK {
10861086
impl.logger.Debugw("argo app exists", "app", argoAppName, "pipeline", pipeline.Name)
1087-
if argoApplication.Spec.Source.Path != envOverride.Chart.ChartLocation || argoApplication.Spec.Source.TargetRevision != "master" {
1087+
if impl.argoClientWrapperService.IsArgoAppPatchRequired(argoApplication.Spec.Source, envOverride.Chart.GitRepoUrl, envOverride.Chart.ChartLocation) {
10881088
patchRequestDto := &bean7.ArgoCdAppPatchReqDto{
10891089
ArgoAppName: argoAppName,
10901090
ChartLocation: envOverride.Chart.ChartLocation,
@@ -1097,6 +1097,9 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(pipeline *pipelineConfig.Pipe
10971097
impl.logger.Errorw("error in patching argo pipeline", "err", err, "req", patchRequestDto)
10981098
return false, err
10991099
}
1100+
if envOverride.Chart.GitRepoUrl != argoApplication.Spec.Source.RepoURL {
1101+
impl.logger.Infow("patching argo application's repo url", "argoAppName", argoAppName)
1102+
}
11001103
impl.logger.Debugw("pipeline update req", "res", patchRequestDto)
11011104
} else {
11021105
impl.logger.Debug("pipeline no need to update ")

0 commit comments

Comments
 (0)