Skip to content
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

Support apps with multiple sources #240

Closed
wants to merge 1 commit into from

Conversation

sl1pm4t
Copy link
Collaborator

@sl1pm4t sl1pm4t commented Jul 11, 2024

@sl1pm4t sl1pm4t marked this pull request as draft July 11, 2024 04:54
make the machine happier
@zapier-sre-bot
Copy link
Collaborator

Mergecat's Review

Click to read mergecats review!

😼 Mergecat review of pkg/appdir/vcstoargomap.go

@@ -80,17 +80,26 @@ func (v2a VcsToArgoMap) WalkKustomizeApps(cloneURL string, fs fs.FS) *AppDirecto
 }
 
 func (v2a VcsToArgoMap) AddApp(app *v1alpha1.Application) {
-	if app.Spec.Source == nil {
+	if app.Spec.Source == nil && app.Spec.Sources == nil {
 		log.Warn().Msgf("%s/%s: no source, skipping", app.Namespace, app.Name)
 		return
 	}
 
-	appDirectory := v2a.GetAppsInRepo(app.Spec.Source.RepoURL)
-	appDirectory.ProcessApp(*app)
+	if app.Spec.Source != nil {
+		appDirectory := v2a.GetAppsInRepo(app.Spec.Source.RepoURL)
+		appDirectory.ProcessApp(*app)
+	}
+	if app.Spec.Sources != nil {
+		for _, src := range app.Spec.Sources {
+			appDirectory := v2a.GetAppsInRepo(src.RepoURL)
+			appDirectory.ProcessApp(*app)
+		}
+	}
+
 }
 
 func (v2a VcsToArgoMap) UpdateApp(old *v1alpha1.Application, new *v1alpha1.Application) {
-	if new.Spec.Source == nil {
+	if new.Spec.Source == nil && new.Spec.Sources == nil {
 		log.Warn().Msgf("%s/%s: no source, skipping", new.Namespace, new.Name)
 		return
 	}
@@ -103,7 +112,7 @@ func (v2a VcsToArgoMap) UpdateApp(old *v1alpha1.Application, new *v1alpha1.Appli
 }
 
 func (v2a VcsToArgoMap) DeleteApp(app *v1alpha1.Application) {
-	if app.Spec.Source == nil {
+	if app.Spec.Source == nil && app.Spec.Sources == nil {
 		log.Warn().Msgf("%s/%s: no source, skipping", app.Namespace, app.Name)
 		return
 	}

Feedback & Suggestions:

  1. Code Duplication: The logic for processing app.Spec.Source and app.Spec.Sources is duplicated across the AddApp, UpdateApp, and DeleteApp methods. Consider refactoring this logic into a helper function to reduce duplication and improve maintainability. 🛠️

  2. Error Handling: When iterating over app.Spec.Sources, if src.RepoURL is invalid or causes an error in GetAppsInRepo, it might be beneficial to log an error or handle it gracefully. This will help in debugging issues related to invalid URLs. 🐛

  3. Performance Consideration: In the AddApp method, the loop over app.Spec.Sources calls GetAppsInRepo for each source. If GetAppsInRepo involves expensive operations, consider optimizing this by caching results or reducing redundant calls. 🚀

  4. Logging: Ensure that the log messages provide enough context for debugging. For instance, when processing multiple sources, it might be helpful to log which source is being processed. 📜



Dependency Review

Click to read mergecats review!

No suggestions found

@sl1pm4t
Copy link
Collaborator Author

sl1pm4t commented Oct 22, 2024

Closing in favour of #294

@sl1pm4t sl1pm4t closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants