Skip to content

Commit 3bff81a

Browse files
authored
Merge pull request #945 from fluxcd/fix-source-index
Fix GitRepository namespace not used in watch index key
2 parents 03080ba + 0e29d53 commit 3bff81a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/controller/imageupdateautomation_controller.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(ctx context.Context,
134134
if err := mgr.GetFieldIndexer().IndexField(ctx, &imagev1.ImageUpdateAutomation{}, repoRefKey, func(obj client.Object) []string {
135135
updater := obj.(*imagev1.ImageUpdateAutomation)
136136
ref := updater.Spec.SourceRef
137-
return []string{ref.Name}
137+
ns := ref.Namespace
138+
if ns == "" {
139+
ns = obj.GetNamespace()
140+
}
141+
return []string{fmt.Sprintf("%s/%s", ns, ref.Name)}
138142
}); err != nil {
139143
return err
140144
}
@@ -162,8 +166,8 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(ctx context.Context,
162166
// particular source.GitRepository object.
163167
func (r *ImageUpdateAutomationReconciler) automationsForGitRepo(ctx context.Context, obj client.Object) []reconcile.Request {
164168
var autoList imagev1.ImageUpdateAutomationList
165-
if err := r.List(ctx, &autoList, client.InNamespace(obj.GetNamespace()),
166-
client.MatchingFields{repoRefKey: obj.GetName()}); err != nil {
169+
objKey := fmt.Sprintf("%s/%s", obj.GetNamespace(), obj.GetName())
170+
if err := r.List(ctx, &autoList, client.MatchingFields{repoRefKey: objKey}); err != nil {
167171
ctrl.LoggerFrom(ctx).Error(err, "failed to list ImageUpdateAutomations for GitRepository change")
168172
return nil
169173
}

0 commit comments

Comments
 (0)