Watched cross-ns image repos trigger reconcile
Cross-namespace ImageRepository resources should trigger reconciles for ImagePolicies that refer to them. Previously, this was only done for resources in the same namespace. Fixes #195 Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
This commit is contained in:
parent
2d05314858
commit
0dd4f706ff
|
@ -259,8 +259,7 @@ func (r *ImagePolicyReconciler) SetupWithManager(mgr ctrl.Manager, opts ImagePol
|
||||||
func (r *ImagePolicyReconciler) imagePoliciesForRepository(obj client.Object) []reconcile.Request {
|
func (r *ImagePolicyReconciler) imagePoliciesForRepository(obj client.Object) []reconcile.Request {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var policies imagev1.ImagePolicyList
|
var policies imagev1.ImagePolicyList
|
||||||
if err := r.List(ctx, &policies, client.InNamespace(obj.GetNamespace()),
|
if err := r.List(ctx, &policies, client.MatchingFields{imageRepoKey: obj.GetName()}); err != nil {
|
||||||
client.MatchingFields{imageRepoKey: obj.GetName()}); err != nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
reqs := make([]reconcile.Request, len(policies.Items))
|
reqs := make([]reconcile.Request, len(policies.Items))
|
||||||
|
|
|
@ -615,7 +615,8 @@ var _ = Describe("ImagePolicy controller", func() {
|
||||||
defer k8sClient.Delete(context.Background(), policyNamespace)
|
defer k8sClient.Delete(context.Background(), policyNamespace)
|
||||||
|
|
||||||
versions := []string{"1.0.0", "1.0.1"}
|
versions := []string{"1.0.0", "1.0.1"}
|
||||||
imgRepo := loadImages(registryServer, "acl-image-"+randStringRunes(5), versions)
|
imageName := "acl-image-" + randStringRunes(5)
|
||||||
|
imgRepo := loadImages(registryServer, imageName, versions)
|
||||||
|
|
||||||
repo := imagev1.ImageRepository{
|
repo := imagev1.ImageRepository{
|
||||||
Spec: imagev1.ImageRepositorySpec{
|
Spec: imagev1.ImageRepositorySpec{
|
||||||
|
@ -687,6 +688,19 @@ var _ = Describe("ImagePolicy controller", func() {
|
||||||
}, timeout, interval).Should(BeTrue())
|
}, timeout, interval).Should(BeTrue())
|
||||||
Expect(pol.Status.LatestImage).To(Equal(imgRepo + ":1.0.1"))
|
Expect(pol.Status.LatestImage).To(Equal(imgRepo + ":1.0.1"))
|
||||||
|
|
||||||
|
// Updating the image should reconcile the cross-namespace policy
|
||||||
|
imgRepo = loadImages(registryServer, imageName, []string{"1.0.2"})
|
||||||
|
Eventually(func() bool {
|
||||||
|
err := r.Get(ctx, repoObjectName, &repo)
|
||||||
|
return err == nil && repo.Status.LastScanResult.TagCount == len(versions)+1
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
|
||||||
|
Eventually(func() bool {
|
||||||
|
err := r.Get(ctx, polObjectName, &pol)
|
||||||
|
return err == nil && pol.Status.LatestImage != ""
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
Expect(pol.Status.LatestImage).To(Equal(imgRepo + ":1.0.2"))
|
||||||
|
|
||||||
Expect(r.Delete(ctx, &pol)).To(Succeed())
|
Expect(r.Delete(ctx, &pol)).To(Succeed())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue