Skip to content

Commit

Permalink
Update ImagePolicy index imageRepoKey include ns
Browse files Browse the repository at this point in the history
The imageRepoKey only contains the name of the ImageRepository resource.
This change uses the namespaced name to avoid collisions.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
  • Loading branch information
relu committed Nov 11, 2021
1 parent 0dd4f70 commit 006f204
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions controllers/imagepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
// this is used as the key for the index of policy->repository; the
// string is arbitrary and acts as a reminder where the value comes
// from.
const imageRepoKey = ".spec.imageRepository.name"
const imageRepoKey = ".spec.imageRepository"

// ImagePolicyReconciler reconciles a ImagePolicy object
type ImagePolicyReconciler struct {
Expand Down Expand Up @@ -237,7 +237,11 @@ func (r *ImagePolicyReconciler) SetupWithManager(mgr ctrl.Manager, opts ImagePol
// it's easy to list those out when an image repo changes.
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &imagev1.ImagePolicy{}, imageRepoKey, func(obj client.Object) []string {
pol := obj.(*imagev1.ImagePolicy)
return []string{pol.Spec.ImageRepositoryRef.Name}
namespacedName := types.NamespacedName{
Name: pol.Spec.ImageRepositoryRef.Name,
Namespace: pol.Spec.ImageRepositoryRef.Namespace,
}
return []string{namespacedName.String()}
}); err != nil {
return err
}
Expand All @@ -259,7 +263,7 @@ func (r *ImagePolicyReconciler) SetupWithManager(mgr ctrl.Manager, opts ImagePol
func (r *ImagePolicyReconciler) imagePoliciesForRepository(obj client.Object) []reconcile.Request {
ctx := context.Background()
var policies imagev1.ImagePolicyList
if err := r.List(ctx, &policies, client.MatchingFields{imageRepoKey: obj.GetName()}); err != nil {
if err := r.List(ctx, &policies, client.MatchingFields{imageRepoKey: client.ObjectKeyFromObject(obj).String()}); err != nil {
return nil
}
reqs := make([]reconcile.Request, len(policies.Items))
Expand Down

0 comments on commit 006f204

Please sign in to comment.