@@ -101,6 +101,90 @@ func TestImagePolicyReconciler_imageRepoNotReady(t *testing.T) {
101101 }).Should (BeTrue ())
102102}
103103
104+ func TestImagePolicyReconciler_ignoresImageRepoNotReadyEvent (t * testing.T ) {
105+ g := NewWithT (t )
106+
107+ namespaceName := "imagepolicy-" + randStringRunes (5 )
108+ namespace := & corev1.Namespace {
109+ ObjectMeta : metav1.ObjectMeta {Name : namespaceName },
110+ }
111+ g .Expect (k8sClient .Create (ctx , namespace )).ToNot (HaveOccurred ())
112+ t .Cleanup (func () {
113+ g .Expect (k8sClient .Delete (ctx , namespace )).NotTo (HaveOccurred ())
114+ })
115+
116+ imageRepo := & imagev1.ImageRepository {
117+ ObjectMeta : metav1.ObjectMeta {
118+ Namespace : namespaceName ,
119+ Name : "repo" ,
120+ },
121+ Spec : imagev1.ImageRepositorySpec {
122+ Image : "ghcr.io/stefanprodan/podinfo" ,
123+ },
124+ }
125+ g .Expect (k8sClient .Create (ctx , imageRepo )).NotTo (HaveOccurred ())
126+ t .Cleanup (func () {
127+ g .Expect (k8sClient .Delete (ctx , imageRepo )).NotTo (HaveOccurred ())
128+ })
129+
130+ g .Eventually (func () bool {
131+ err := k8sClient .Get (ctx , client .ObjectKeyFromObject (imageRepo ), imageRepo )
132+ return err == nil && conditions .IsReady (imageRepo )
133+ }, timeout ).Should (BeTrue ())
134+
135+ imagePolicy := & imagev1.ImagePolicy {
136+ ObjectMeta : metav1.ObjectMeta {
137+ Namespace : namespaceName ,
138+ Name : "test-imagepolicy" ,
139+ },
140+ Spec : imagev1.ImagePolicySpec {
141+ ImageRepositoryRef : meta.NamespacedObjectReference {
142+ Name : imageRepo .Name ,
143+ },
144+ Policy : imagev1.ImagePolicyChoice {
145+ Alphabetical : & imagev1.AlphabeticalPolicy {},
146+ },
147+ },
148+ }
149+ g .Expect (k8sClient .Create (ctx , imagePolicy )).NotTo (HaveOccurred ())
150+ t .Cleanup (func () {
151+ g .Expect (k8sClient .Delete (ctx , imagePolicy )).NotTo (HaveOccurred ())
152+ })
153+
154+ g .Eventually (func () bool {
155+ err := k8sClient .Get (ctx , client .ObjectKeyFromObject (imagePolicy ), imagePolicy )
156+ return err == nil && conditions .IsReady (imagePolicy )
157+ }).Should (BeTrue ())
158+
159+ // Now cause the ImageRepository to become not ready.
160+ g .Eventually (func () bool {
161+ err := k8sClient .Get (ctx , client .ObjectKeyFromObject (imageRepo ), imageRepo )
162+ if err != nil {
163+ return false
164+ }
165+ p := patch .NewSerialPatcher (imageRepo , k8sClient )
166+ imageRepo .Spec .Image = "ghcr.io/stefanprodan/podinfo/foo:bar:zzz:qqq/aaa"
167+ return p .Patch (ctx , imageRepo ) == nil
168+ }).Should (BeTrue ())
169+
170+ // Wait for the ImageRepository to become not ready.
171+ g .Eventually (func () bool {
172+ err := k8sClient .Get (ctx , client .ObjectKeyFromObject (imageRepo ), imageRepo )
173+ return err == nil && conditions .IsStalled (imageRepo )
174+ }).Should (BeTrue ())
175+
176+ // Check that the ImagePolicy is still ready and does not get updated.
177+ err := k8sClient .Get (ctx , client .ObjectKeyFromObject (imagePolicy ), imagePolicy )
178+ g .Expect (err ).NotTo (HaveOccurred ())
179+ g .Expect (conditions .IsReady (imagePolicy )).To (BeTrue ())
180+
181+ // Wait a bit and check that the ImagePolicy remains ready.
182+ time .Sleep (time .Second )
183+ err = k8sClient .Get (ctx , client .ObjectKeyFromObject (imagePolicy ), imagePolicy )
184+ g .Expect (err ).NotTo (HaveOccurred ())
185+ g .Expect (conditions .IsReady (imagePolicy )).To (BeTrue ())
186+ }
187+
104188func TestImagePolicyReconciler_invalidImage (t * testing.T ) {
105189 g := NewWithT (t )
106190
0 commit comments