chore(hydrator): simplify dupe destination detection (#23566)

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
This commit is contained in:
Michael Crenshaw
2025-08-27 13:05:26 -04:00
committed by GitHub
parent d154627681
commit 68e5a4a12c

View File

@@ -136,21 +136,6 @@ func getHydrationQueueKey(app *appv1.Application) types.HydrationQueueKey {
return key
}
// uniqueHydrationDestination is used to detect duplicate hydrate destinations.
type uniqueHydrationDestination struct {
// sourceRepoURL must be normalized with git.NormalizeGitURL to ensure that two apps with different URL formats
// don't end up in two different hydration queue items. Failing to normalize would result in one hydrated commit for
// each unique URL.
//nolint:unused // used as part of a map key
sourceRepoURL string
//nolint:unused // used as part of a map key
sourceTargetRevision string
//nolint:unused // used as part of a map key
destinationBranch string
//nolint:unused // used as part of a map key
destinationPath string
}
// ProcessHydrationQueueItem processes a hydration queue item. It retrieves the relevant applications for the given
// hydration key, hydrates their latest commit, and updates their status accordingly. If the hydration fails, it marks
// the operation as failed and logs the error. If successful, it updates the operation to indicate that hydration was
@@ -234,7 +219,7 @@ func (h *Hydrator) getRelevantAppsForHydration(logCtx *log.Entry, hydrationKey t
}
var relevantApps []*appv1.Application
uniqueDestinations := make(map[uniqueHydrationDestination]bool, len(apps.Items))
uniquePaths := make(map[string]bool, len(apps.Items))
for _, app := range apps.Items {
if app.Spec.SourceHydrator == nil {
continue
@@ -264,17 +249,12 @@ func (h *Hydrator) getRelevantAppsForHydration(logCtx *log.Entry, hydrationKey t
continue
}
uniqueDestinationKey := uniqueHydrationDestination{
sourceRepoURL: git.NormalizeGitURLAllowInvalid(app.Spec.SourceHydrator.DrySource.RepoURL),
sourceTargetRevision: app.Spec.SourceHydrator.DrySource.TargetRevision,
destinationBranch: destinationBranch,
destinationPath: app.Spec.SourceHydrator.SyncSource.Path,
}
// TODO: test the dupe detection
if _, ok := uniqueDestinations[uniqueDestinationKey]; ok {
return nil, fmt.Errorf("multiple app hydrators use the same destination: %v", uniqueDestinationKey)
// TODO: normalize the path to avoid "path/.." from being treated as different from "."
if _, ok := uniquePaths[app.Spec.SourceHydrator.SyncSource.Path]; ok {
return nil, fmt.Errorf("multiple app hydrators use the same destination: %v", app.Spec.SourceHydrator.SyncSource.Path)
}
uniqueDestinations[uniqueDestinationKey] = true
uniquePaths[app.Spec.SourceHydrator.SyncSource.Path] = true
relevantApps = append(relevantApps, &app)
}