Skip to content

fix: repo url and name handling with argocd #5445

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
Jul 5, 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
16 changes: 16 additions & 0 deletions client/argocdServer/ArgoClientWrapperService.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ type ArgoClientWrapperService interface {

// GetGitOpsRepoName returns the GitOps repository name, configured for the argoCd app
GetGitOpsRepoName(ctx context.Context, appName string) (gitOpsRepoName string, err error)

GetGitOpsRepoURL(ctx context.Context, appName string) (gitOpsRepoURL string, err error)
}

type ArgoClientWrapperServiceImpl struct {
Expand Down Expand Up @@ -290,6 +292,20 @@ func (impl *ArgoClientWrapperServiceImpl) GetGitOpsRepoName(ctx context.Context,
return gitOpsRepoName, fmt.Errorf("unable to get any ArgoCd application '%s'", appName)
}

func (impl *ArgoClientWrapperServiceImpl) GetGitOpsRepoURL(ctx context.Context, appName string) (gitOpsRepoName string, err error) {
acdApplication, err := impl.acdClient.Get(ctx, &application2.ApplicationQuery{Name: &appName})
if err != nil {
impl.logger.Errorw("no argo app exists", "acdAppName", appName, "err", err)
return gitOpsRepoName, err
}
// safety checks nil pointers
if acdApplication != nil && acdApplication.Spec.Source != nil {
gitOpsRepoUrl := acdApplication.Spec.Source.RepoURL
return gitOpsRepoUrl, nil
}
return "", fmt.Errorf("unable to get any ArgoCd application '%s'", appName)
}

// createRepoInArgoCd is the wrapper function to Create Repository in ArgoCd
func (impl *ArgoClientWrapperServiceImpl) createRepoInArgoCd(ctx context.Context, gitOpsRepoUrl string) error {
repo := &v1alpha1.Repository{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,14 @@ func (impl *AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Contex
installedAppDeploymentAction := adapter.NewInstalledAppDeploymentAction(installedApp.DeploymentAppType)
// migrate installedApp.GitOpsRepoName to installedApp.GitOpsRepoUrl
if util.IsAcdApp(installedApp.DeploymentAppType) &&
len(installedApp.GitOpsRepoName) != 0 &&
len(installedApp.GitOpsRepoUrl) == 0 {
//as the installedApp.GitOpsRepoName is not an empty string; migrate installedApp.GitOpsRepoName to installedApp.GitOpsRepoUrl
gitRepoUrl, err := impl.fullModeDeploymentService.GetGitRepoUrl(installedApp.GitOpsRepoName)
gitRepoUrl, err := impl.fullModeDeploymentService.GetAcdAppGitOpsRepoURL(installedApp.App.AppName, installedApp.Environment.Name)
if err != nil {
impl.logger.Errorw("error in GitOps repository url migration", "err", err)
return nil, err
}
installedApp.GitOpsRepoUrl = gitRepoUrl
installedApp.GitOpsRepoName = impl.gitOpsConfigReadService.GetGitOpsRepoNameFromUrl(gitRepoUrl)
}
// migration ends

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type InstalledAppArgoCdService interface {
// UpdateAndSyncACDApps this will update chart info in acd app if required in case of mono repo migration and will refresh argo app
UpdateAndSyncACDApps(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ChartGitAttribute *commonBean.ChartGitAttribute, isMonoRepoMigrationRequired bool, ctx context.Context, tx *pg.Tx) error
DeleteACD(acdAppName string, ctx context.Context, isNonCascade bool) error
GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error)
}

func (impl *FullModeDeploymentServiceImpl) GetAcdAppGitOpsRepoName(appName string, environmentName string) (string, error) {
Expand Down Expand Up @@ -230,3 +231,15 @@ func (impl *FullModeDeploymentServiceImpl) patchAcdApp(ctx context.Context, inst
}
return nil
}

func (impl *FullModeDeploymentServiceImpl) GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error) {
acdToken, err := impl.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
impl.Logger.Errorw("error in getting acd token", "err", err)
return "", err
}
ctx := context.Background()
ctx = context.WithValue(ctx, "token", acdToken)
acdAppName := fmt.Sprintf("%s-%s", appName, environmentName)
return impl.argoClientWrapperService.GetGitOpsRepoURL(ctx, acdAppName)
}
Loading