Skip to content

fix: update argo app repo url in patch #4876

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 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion client/argocdServer/ArgoClientWrapperService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

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

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

// IsArgoAppPatchRequired decides weather the v1alpha1.ApplicationSource requires to be updated
IsArgoAppPatchRequired(argoAppSpec *v1alpha1.ApplicationSource, currentGitRepoUrl, currentChartPath string) bool

// GetGitOpsRepoName returns the GitOps repository name, configured for the argoCd app
GetGitOpsRepoName(ctx context.Context, appName string) (gitOpsRepoName string, err error)
}
Expand Down Expand Up @@ -180,6 +183,12 @@ func (impl *ArgoClientWrapperServiceImpl) GetArgoAppByName(ctx context.Context,
return argoApplication, nil
}

func (impl *ArgoClientWrapperServiceImpl) IsArgoAppPatchRequired(argoAppSpec *v1alpha1.ApplicationSource, currentGitRepoUrl, currentChartPath string) bool {
return (len(currentGitRepoUrl) != 0 && argoAppSpec.RepoURL != currentGitRepoUrl) ||
argoAppSpec.Path != currentChartPath ||
argoAppSpec.TargetRevision != bean.TargetRevisionMaster
}

func (impl *ArgoClientWrapperServiceImpl) PatchArgoCdApp(ctx context.Context, dto *bean.ArgoCdAppPatchReqDto) error {
patchReq := adapter.GetArgoCdPatchReqFromDto(dto)
reqbyte, err := json.Marshal(patchReq)
Expand Down
5 changes: 4 additions & 1 deletion pkg/deployment/trigger/devtronApps/TriggerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(pipeline *pipelineConfig.Pipe
appStatus, _ := status2.FromError(err)
if appStatus.Code() == codes.OK {
impl.logger.Debugw("argo app exists", "app", argoAppName, "pipeline", pipeline.Name)
if argoApplication.Spec.Source.Path != envOverride.Chart.ChartLocation || argoApplication.Spec.Source.TargetRevision != "master" {
if impl.argoClientWrapperService.IsArgoAppPatchRequired(argoApplication.Spec.Source, envOverride.Chart.GitRepoUrl, envOverride.Chart.ChartLocation) {
patchRequestDto := &bean7.ArgoCdAppPatchReqDto{
ArgoAppName: argoAppName,
ChartLocation: envOverride.Chart.ChartLocation,
Expand All @@ -1097,6 +1097,9 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(pipeline *pipelineConfig.Pipe
impl.logger.Errorw("error in patching argo pipeline", "err", err, "req", patchRequestDto)
return false, err
}
if envOverride.Chart.GitRepoUrl != argoApplication.Spec.Source.RepoURL {
impl.logger.Infow("patching argo application's repo url", "argoAppName", argoAppName)
}
impl.logger.Debugw("pipeline update req", "res", patchRequestDto)
} else {
impl.logger.Debug("pipeline no need to update ")
Expand Down