@@ -451,7 +451,7 @@ var _ = Describe("Test Work Generator Controller", func() {
451451 // mark one of the failed manifests as available but no change in the overall condition
452452 markOneManifestAvailable (& work , false )
453453 // check the binding status that it should be applied but not available and with one failed placement
454- verifyBindStatusNotAvailableWithOnePlacement (binding , false , true )
454+ verifyBindStatusNotAvailableWithOnePlacement (binding , false , true , false )
455455 // mark the work available directly
456456 markWorkAvailable (& work )
457457 // check the binding status that it should be marked as available true eventually
@@ -470,7 +470,8 @@ var _ = Describe("Test Work Generator Controller", func() {
470470 // mark one of the failed manifests as available but no change in the overall condition
471471 markOneManifestAvailable (& work , false )
472472 // check the binding status that it should be applied but not available and with one failed placement
473- verifyBindStatusNotAvailableWithOnePlacement (binding , false , true )
473+ // placement list should be changed
474+ verifyBindStatusNotAvailableWithOnePlacement (binding , false , true , false )
474475 // mark the work available directly
475476 markWorkAvailable (& work )
476477 // check the binding status that it should be marked as available true eventually
@@ -486,10 +487,21 @@ var _ = Describe("Test Work Generator Controller", func() {
486487 markWorkAsAppliedButNotAvailableWithFailedManifest (& work , true )
487488 // check the binding status that it should be applied but not available and with two failed placement and 2 drifted placement
488489 verifyBindStatusNotAvailableWithTwoPlacements (binding , false , true , true )
490+ // mark one of the failed manifests as available and no drift placements but no change in the overall condition
491+ markOneManifestAvailable (& work , true )
492+ // check the binding status that it should be applied but not available and with one failed placement and one drifted placement
493+ // placement list should be changed
494+ verifyBindStatusNotAvailableWithOnePlacement (binding , false , true , true )
489495 // mark the work available directly
490496 markWorkAvailable (& work )
491- // check the binding status that it should be marked as available true eventually with 2 drift placements
492- verifyBindStatusAvail (binding , false , true )
497+ // check the binding status that it should be marked as available true eventually with one drift placement
498+ verifyBindStatusAvailableWithOnePlacement (binding , false )
499+ // mark the work with no drift placements
500+ markWorkWithNoDrift (& work )
501+ // check the binding status that it should be marked as available true eventually with no drift placement
502+ // placement list should be changed
503+ verifyBindStatusAvail (binding , false , false )
504+
493505 })
494506
495507 It ("Should continue to update the binding status even if the master resource snapshot is deleted after the work is synced" , func () {
@@ -2073,7 +2085,7 @@ func verifyBindStatusNotAvailableWithTwoPlacements(binding *placementv1beta1.Clu
20732085 }, timeout , interval ).Should (BeEmpty (), fmt .Sprintf ("binding(%s) mismatch (-want +got)" , binding .Name ))
20742086}
20752087
2076- func verifyBindStatusNotAvailableWithOnePlacement (binding * placementv1beta1.ClusterResourceBinding , hasOverride , hasFailedPlacement bool ) {
2088+ func verifyBindStatusNotAvailableWithOnePlacement (binding * placementv1beta1.ClusterResourceBinding , hasOverride , hasFailedPlacement , hasDriftedPlacement bool ) {
20772089 Eventually (func () string {
20782090 Expect (k8sClient .Get (ctx , types.NamespacedName {Name : binding .Name }, binding )).Should (Succeed ())
20792091 overrideReason := condition .OverrideNotSpecifiedReason
@@ -2133,6 +2145,96 @@ func verifyBindStatusNotAvailableWithOnePlacement(binding *placementv1beta1.Clus
21332145 },
21342146 }
21352147 }
2148+
2149+ if hasDriftedPlacement {
2150+ wantStatus .DriftedPlacements = []placementv1beta1.DriftedResourcePlacement {
2151+ {
2152+ ResourceIdentifier : placementv1beta1.ResourceIdentifier {
2153+ Group : "" ,
2154+ Version : "v1" ,
2155+ Kind : "Service" ,
2156+ Name : "svc-name" ,
2157+ Namespace : "svc-namespace" ,
2158+ },
2159+ ObservationTime : metav1.Time {Time : specificTime },
2160+ FirstDriftedObservedTime : metav1.Time {Time : specificTime },
2161+ TargetClusterObservedGeneration : 1 ,
2162+ ObservedDrifts : []placementv1beta1.PatchDetail {
2163+ {
2164+ Path : "/spec/ports/1/containerPort" ,
2165+ ValueInHub : "80" ,
2166+ ValueInMember : "90" ,
2167+ },
2168+ },
2169+ },
2170+ }
2171+ }
2172+ return cmp .Diff (wantStatus , binding .Status , cmpConditionOption )
2173+ }, timeout , interval ).Should (BeEmpty (), fmt .Sprintf ("binding(%s) mismatch (-want +got)" , binding .Name ))
2174+ }
2175+
2176+ func verifyBindStatusAvailableWithOnePlacement (binding * placementv1beta1.ClusterResourceBinding , hasOverride bool ) {
2177+ Eventually (func () string {
2178+ Expect (k8sClient .Get (ctx , types.NamespacedName {Name : binding .Name }, binding )).Should (Succeed ())
2179+ overrideReason := condition .OverrideNotSpecifiedReason
2180+ if hasOverride {
2181+ overrideReason = condition .OverriddenSucceededReason
2182+ }
2183+ wantStatus := placementv1beta1.ResourceBindingStatus {
2184+ Conditions : []metav1.Condition {
2185+ {
2186+ Type : string (placementv1beta1 .ResourceBindingRolloutStarted ),
2187+ Status : metav1 .ConditionTrue ,
2188+ Reason : condition .RolloutStartedReason ,
2189+ ObservedGeneration : binding .GetGeneration (),
2190+ },
2191+ {
2192+ Type : string (placementv1beta1 .ResourceBindingOverridden ),
2193+ Status : metav1 .ConditionTrue ,
2194+ Reason : overrideReason ,
2195+ ObservedGeneration : binding .GetGeneration (),
2196+ },
2197+ {
2198+ Type : string (placementv1beta1 .ResourceBindingWorkSynchronized ),
2199+ Status : metav1 .ConditionTrue ,
2200+ Reason : condition .AllWorkSyncedReason ,
2201+ ObservedGeneration : binding .GetGeneration (),
2202+ },
2203+ {
2204+ Type : string (placementv1beta1 .ResourceBindingApplied ),
2205+ Status : metav1 .ConditionTrue ,
2206+ Reason : condition .AllWorkAppliedReason ,
2207+ ObservedGeneration : binding .GetGeneration (),
2208+ },
2209+ {
2210+ Type : string (placementv1beta1 .ResourceBindingAvailable ),
2211+ Status : metav1 .ConditionTrue ,
2212+ Reason : condition .AllWorkAvailableReason ,
2213+ ObservedGeneration : binding .GetGeneration (),
2214+ },
2215+ },
2216+ DriftedPlacements : []placementv1beta1.DriftedResourcePlacement {
2217+ {
2218+ ResourceIdentifier : placementv1beta1.ResourceIdentifier {
2219+ Group : "" ,
2220+ Version : "v1" ,
2221+ Kind : "Service" ,
2222+ Name : "svc-name" ,
2223+ Namespace : "svc-namespace" ,
2224+ },
2225+ ObservationTime : metav1.Time {Time : specificTime },
2226+ FirstDriftedObservedTime : metav1.Time {Time : specificTime },
2227+ TargetClusterObservedGeneration : 1 ,
2228+ ObservedDrifts : []placementv1beta1.PatchDetail {
2229+ {
2230+ Path : "/spec/ports/1/containerPort" ,
2231+ ValueInHub : "80" ,
2232+ ValueInMember : "90" ,
2233+ },
2234+ },
2235+ },
2236+ },
2237+ }
21362238 return cmp .Diff (wantStatus , binding .Status , cmpConditionOption )
21372239 }, timeout , interval ).Should (BeEmpty (), fmt .Sprintf ("binding(%s) mismatch (-want +got)" , binding .Name ))
21382240}
@@ -2232,6 +2334,67 @@ func markWorkAvailable(work *placementv1beta1.Work) {
22322334 By (fmt .Sprintf ("resource work `%s` is marked as available" , work .Name ))
22332335}
22342336
2337+ func markWorkWithNoDrift (work * placementv1beta1.Work ) {
2338+ work .Status .ManifestConditions = []placementv1beta1.ManifestCondition {
2339+ {
2340+ Identifier : placementv1beta1.WorkResourceIdentifier {
2341+ Ordinal : 0 ,
2342+ Group : "" ,
2343+ Version : "v1" ,
2344+ Kind : "ConfigMap" ,
2345+ Name : "config-name" ,
2346+ Namespace : "config-namespace" ,
2347+ },
2348+ Conditions : []metav1.Condition {
2349+ {
2350+ Type : placementv1beta1 .WorkConditionTypeApplied ,
2351+ Status : metav1 .ConditionTrue ,
2352+ Reason : "fakeAppliedManifest" ,
2353+ Message : "fake apply manifest" ,
2354+ LastTransitionTime : metav1 .Now (),
2355+ },
2356+ {
2357+ Type : placementv1beta1 .WorkConditionTypeAvailable ,
2358+ Status : metav1 .ConditionTrue ,
2359+ Reason : "fakeAvailableManifest" ,
2360+ Message : "fake available manifest" ,
2361+ LastTransitionTime : metav1 .Now (),
2362+ },
2363+ },
2364+ DriftDetails : nil ,
2365+ },
2366+ {
2367+ Identifier : placementv1beta1.WorkResourceIdentifier {
2368+ Ordinal : 1 ,
2369+ Group : "" ,
2370+ Version : "v1" ,
2371+ Kind : "Service" ,
2372+ Name : "svc-name" ,
2373+ Namespace : "svc-namespace" ,
2374+ },
2375+ Conditions : []metav1.Condition {
2376+ {
2377+ Type : placementv1beta1 .WorkConditionTypeApplied ,
2378+ Status : metav1 .ConditionTrue ,
2379+ Reason : "fakeAppliedManifest" ,
2380+ Message : "fake apply manifest" ,
2381+ LastTransitionTime : metav1 .Now (),
2382+ },
2383+ {
2384+ Type : placementv1beta1 .WorkConditionTypeAvailable ,
2385+ Status : metav1 .ConditionTrue ,
2386+ Reason : "fakeAvailableManifest" ,
2387+ Message : "fake available manifest" ,
2388+ LastTransitionTime : metav1 .Now (),
2389+ },
2390+ },
2391+ DriftDetails : nil ,
2392+ },
2393+ }
2394+ Expect (k8sClient .Status ().Update (ctx , work )).Should (Succeed ())
2395+ By (fmt .Sprintf ("resource work `%s` is marked with no drift" , work .Name ))
2396+ }
2397+
22352398// markWorkWithFailedToApplyAndNotAvailable marks the work as not applied with failedPlacement
22362399func markWorkWithFailedToApplyAndNotAvailable (work * placementv1beta1.Work , hasDiffedDetails , hasDriftedDetails bool ) {
22372400 meta .SetStatusCondition (& work .Status .Conditions , metav1.Condition {
0 commit comments