@@ -1752,7 +1752,10 @@ func TestHelmRepositoryReconciler_ReconcileTypeUpdatePredicateFilter(t *testing.
17521752 if err := testEnv .Get (ctx , key , obj ); err != nil {
17531753 return false
17541754 }
1755+ ready := conditions .Get (obj , meta .ReadyCondition )
17551756 return newGen == obj .Generation &&
1757+ conditions .IsReady (obj ) &&
1758+ ready != nil && ready .Reason == sourcev1 .NoIndexReason &&
17561759 ! intpredicates .HelmRepositoryOCIRequireMigration (obj )
17571760 }, timeout ).Should (BeTrue ())
17581761
@@ -1965,10 +1968,11 @@ func TestHelmRepositoryReconciler_ociMigration(t *testing.T) {
19651968
19661969 g .Eventually (func () bool {
19671970 _ = testEnv .Get (ctx , hrKey , hr )
1968- return ! intpredicates .HelmRepositoryOCIRequireMigration (hr )
1971+ ready := conditions .Get (hr , meta .ReadyCondition )
1972+ return conditions .IsReady (hr ) &&
1973+ ready != nil && ready .Reason == sourcev1 .NoIndexReason &&
1974+ ! intpredicates .HelmRepositoryOCIRequireMigration (hr )
19691975 }, timeout , time .Second ).Should (BeTrue ())
1970- g .Expect (conditions .IsReady (hr )).To (BeTrue ())
1971- g .Expect (conditions .Get (hr , meta .ReadyCondition ).Reason ).To (Equal (sourcev1 .NoIndexReason ))
19721976 g .Expect (controllerutil .ContainsFinalizer (hr , sourcev1 .SourceFinalizer )).To (BeFalse ())
19731977
19741978 // Migrates updated object with finalizer.
@@ -1981,10 +1985,11 @@ func TestHelmRepositoryReconciler_ociMigration(t *testing.T) {
19811985
19821986 g .Eventually (func () bool {
19831987 _ = testEnv .Get (ctx , hrKey , hr )
1984- return ! intpredicates .HelmRepositoryOCIRequireMigration (hr )
1988+ ready := conditions .Get (hr , meta .ReadyCondition )
1989+ return conditions .IsReady (hr ) &&
1990+ ready != nil && ready .Reason == sourcev1 .NoIndexReason &&
1991+ ! intpredicates .HelmRepositoryOCIRequireMigration (hr )
19851992 }, timeout , time .Second ).Should (BeTrue ())
1986- g .Expect (conditions .IsReady (hr )).To (BeTrue ())
1987- g .Expect (conditions .Get (hr , meta .ReadyCondition ).Reason ).To (Equal (sourcev1 .NoIndexReason ))
19881993
19891994 // Migrates deleted object with finalizer.
19901995
@@ -2049,14 +2054,21 @@ func TestHelmRepositoryReconciler_ociReadyCondition(t *testing.T) {
20492054 }
20502055 g .Expect (testEnv .Create (ctx , hr )).ToNot (HaveOccurred ())
20512056
2052- waitForSourceReady (ctx , g , hr , false )
2057+ g .Eventually (func () bool {
2058+ if err := testEnv .Get (ctx , client .ObjectKeyFromObject (hr ), hr ); err != nil {
2059+ return false
2060+ }
2061+ ready := conditions .Get (hr , meta .ReadyCondition )
2062+ return conditions .IsReady (hr ) &&
2063+ ready != nil && ready .Reason == sourcev1 .NoIndexReason &&
2064+ hr .GetArtifact () == nil &&
2065+ ! intpredicates .HelmRepositoryOCIRequireMigration (hr )
2066+ }, timeout ).Should (BeTrue ())
20532067
20542068 g .Expect (hr .GetArtifact ()).To (BeNil ())
20552069 g .Expect (hr .Status .URL ).To (BeEmpty ())
20562070 g .Expect (controllerutil .ContainsFinalizer (hr , sourcev1 .SourceFinalizer )).To (BeFalse ())
2057- g .Expect (conditions .Get (hr , meta .ReadyCondition ).Reason ).To (Equal (sourcev1 .NoIndexReason ))
20582071 g .Expect (conditions .Get (hr , meta .ReadyCondition ).Message ).To (ContainSubstring ("do not produce an index artifact" ))
2059- g .Expect (intpredicates .HelmRepositoryOCIRequireMigration (hr )).To (BeFalse ())
20602072
20612073 // Spec updates on a static Ready object must not wipe the condition.
20622074 patchHelper , err := patch .NewHelper (hr , testEnv .Client )
@@ -2171,3 +2183,66 @@ func TestHelmRepositoryReconciler_migrationToStatic_emptyStatus(t *testing.T) {
21712183 g .Expect (conditions .IsReady (got2 )).To (BeTrue ())
21722184 g .Expect (conditions .Get (got2 , meta .ReadyCondition ).Reason ).To (Equal (sourcev1 .NoIndexReason ))
21732185}
2186+
2187+ func TestHelmRepositoryReconciler_migrationToStatic_staleReady (t * testing.T ) {
2188+ tests := []struct {
2189+ name string
2190+ markReady func (obj * sourcev1.HelmRepository )
2191+ }{
2192+ {
2193+ name : "Succeeded reason" ,
2194+ markReady : func (obj * sourcev1.HelmRepository ) {
2195+ conditions .MarkTrue (obj , meta .ReadyCondition , meta .SucceededReason , "fetched index" )
2196+ },
2197+ },
2198+ {
2199+ name : "empty reason" ,
2200+ markReady : func (obj * sourcev1.HelmRepository ) {
2201+ conditions .MarkTrue (obj , meta .ReadyCondition , "" , "" )
2202+ },
2203+ },
2204+ }
2205+
2206+ for _ , tt := range tests {
2207+ t .Run (tt .name , func (t * testing.T ) {
2208+ g := NewWithT (t )
2209+
2210+ obj := & sourcev1.HelmRepository {
2211+ ObjectMeta : metav1.ObjectMeta {
2212+ Name : "oci-stale-ready" ,
2213+ Namespace : "default" ,
2214+ Generation : 1 ,
2215+ },
2216+ Spec : sourcev1.HelmRepositorySpec {
2217+ Type : sourcev1 .HelmRepositoryTypeOCI ,
2218+ URL : "oci://example.com/charts" ,
2219+ Interval : metav1.Duration {Duration : interval },
2220+ },
2221+ Status : sourcev1.HelmRepositoryStatus {
2222+ ObservedGeneration : 1 ,
2223+ },
2224+ }
2225+ tt .markReady (obj )
2226+ g .Expect (intpredicates .HelmRepositoryOCIRequireMigration (obj )).To (BeTrue ())
2227+
2228+ r := & HelmRepositoryReconciler {
2229+ Client : fakeclient .NewClientBuilder ().
2230+ WithScheme (testEnv .GetScheme ()).
2231+ WithObjects (obj ).
2232+ WithStatusSubresource (& sourcev1.HelmRepository {}).
2233+ Build (),
2234+ EventRecorder : record .NewFakeRecorder (32 ),
2235+ Storage : testStorage ,
2236+ }
2237+
2238+ _ , err := r .Reconcile (context .TODO (), ctrl.Request {NamespacedName : client .ObjectKeyFromObject (obj )})
2239+ g .Expect (err ).ToNot (HaveOccurred ())
2240+
2241+ got := & sourcev1.HelmRepository {}
2242+ g .Expect (r .Client .Get (context .TODO (), client .ObjectKeyFromObject (obj ), got )).To (Succeed ())
2243+ g .Expect (conditions .IsReady (got )).To (BeTrue ())
2244+ g .Expect (conditions .Get (got , meta .ReadyCondition ).Reason ).To (Equal (sourcev1 .NoIndexReason ))
2245+ g .Expect (intpredicates .HelmRepositoryOCIRequireMigration (got )).To (BeFalse ())
2246+ })
2247+ }
2248+ }
0 commit comments