@@ -39,7 +39,7 @@ import (
3939 "github.com/kubefleet-dev/kubefleet/pkg/utils"
4040 "github.com/kubefleet-dev/kubefleet/pkg/utils/condition"
4141 "github.com/kubefleet-dev/kubefleet/pkg/utils/resource"
42- statussyncutils "github.com/kubefleet-dev/kubefleet/test/utils/crpstatussync"
42+ "github.com/kubefleet-dev/kubefleet/test/utils/crpstatussync"
4343 metricsUtils "github.com/kubefleet-dev/kubefleet/test/utils/metrics"
4444)
4545
@@ -2189,26 +2189,31 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
21892189 })
21902190
21912191 It ("Should handle missing target namespace" , func () {
2192- By ("Validate CRP keeps retrying due to missing namespace ( status remain nil) " )
2192+ By ("Validate CRP status includes StatusSynced condition " )
21932193 wantCRP := & placementv1beta1.ClusterResourcePlacement {
21942194 ObjectMeta : metav1.ObjectMeta {
21952195 Name : testCRPName ,
21962196 Finalizers : []string {placementv1beta1 .PlacementCleanupFinalizer },
21972197 },
21982198 Spec : crp .Spec ,
2199+ Status : placementv1beta1.PlacementStatus {
2200+ ObservedResourceIndex : "0" ,
2201+ Conditions : []metav1.Condition {
2202+ {
2203+ Status : metav1 .ConditionUnknown ,
2204+ Type : string (placementv1beta1 .ClusterResourcePlacementScheduledConditionType ),
2205+ Reason : condition .SchedulingUnknownReason ,
2206+ },
2207+ {
2208+ Status : metav1 .ConditionFalse ,
2209+ Type : string (placementv1beta1 .ClusterResourcePlacementStatusSyncedConditionType ),
2210+ Reason : condition .StatusSyncFailedReason ,
2211+ },
2212+ },
2213+ },
21992214 }
2200- retrieveAndValidateClusterResourcePlacement (testCRPName , wantCRP )
2201- // Ensure that CRP status remains nil as the controller keeps retrying.
2202- Consistently (func () error {
2203- gotCRP := & placementv1beta1.ClusterResourcePlacement {}
2204- if err := k8sClient .Get (ctx , types.NamespacedName {Name : testCRPName }, gotCRP ); err != nil {
2205- return err
2206- }
2207- if diff := cmp .Diff (wantCRP , gotCRP , cmpCRPOptions ); diff != "" {
2208- return fmt .Errorf ("clusterResourcePlacement mismatch (-want, +got) :\n %s" , diff )
2209- }
2210- return nil
2211- }, consistentlyTimeout , interval ).Should (Succeed (), "ClusterResourcePlacement status must be nil" )
2215+ retrieveAndValidateClusterResourcePlacement (crp .Name , wantCRP )
2216+
22122217 // Namespace doesn't exist, so no CRPS should be created - sanity check.
22132218 By ("Ensure no ClusterResourcePlacementStatus is created in the nonexistent namespace" )
22142219 Consistently (func () bool {
@@ -2250,7 +2255,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
22502255 {
22512256 Group : corev1 .GroupName ,
22522257 Version : "v1" ,
2253- Kind : "InvalidKind" , // Invalid kind to trigger user error
2258+ Kind : "InvalidKind" , // Invalid kind to trigger user error.
22542259 Name : "invalid-resource" ,
22552260 },
22562261 },
@@ -2268,7 +2273,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
22682273 },
22692274 }
22702275 Expect (k8sClient .Delete (ctx , crp )).Should (Succeed ())
2271- retrieveAndValidateCRPDeletion (gotCRP )
2276+ retrieveAndValidateCRPDeletion (crp )
22722277
22732278 // Need to manually clean up CRPS in test environment https://book.kubebuilder.io/reference/envtest#testing-considerations.
22742279 By ("Deleting crps" )
@@ -2293,8 +2298,8 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
22932298 Expect (k8sClient .Delete (ctx , namespace )).Should (Succeed ())
22942299 })
22952300
2296- It ("Should handle invalid resource selector" , func () {
2297- By ("Validate CRP status" )
2301+ It ("Should handle invalid resource selector and create CRPS " , func () {
2302+ By ("Validate CRP status includes both Scheduled and StatusSynced conditions " )
22982303 wantCRP := & placementv1beta1.ClusterResourcePlacement {
22992304 ObjectMeta : metav1.ObjectMeta {
23002305 Name : testCRPName ,
@@ -2303,20 +2308,25 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
23032308 Spec : crp .Spec ,
23042309 Status : placementv1beta1.PlacementStatus {
23052310 Conditions : []metav1.Condition {
2311+ // ObservedResourceIndex is not set because resource selector is invalid.
23062312 {
23072313 Status : metav1 .ConditionFalse ,
23082314 Type : string (placementv1beta1 .ClusterResourcePlacementScheduledConditionType ),
23092315 Reason : condition .InvalidResourceSelectorsReason ,
23102316 },
2317+ {
2318+ Status : metav1 .ConditionTrue ,
2319+ Type : string (placementv1beta1 .ClusterResourcePlacementStatusSyncedConditionType ),
2320+ Reason : condition .StatusSyncSucceededReason ,
2321+ },
23112322 },
23122323 },
23132324 }
2314- gotCRP = retrieveAndValidateClusterResourcePlacement (crp .Name , wantCRP )
2325+ retrieveAndValidateClusterResourcePlacement (crp .Name , wantCRP )
23152326
2316- By ("Validate CRPS status" , func () {
2317- crpsMatchesActual := statussyncutils .CRPSStatusMatchesCRPActual (ctx , k8sClient , testCRPName , namespaceName )
2318- Eventually (crpsMatchesActual , eventuallyTimeout , interval ).Should (Succeed (), "ClusterResourcePlacementStatus should match expected structure and CRP status" )
2319- })
2327+ By ("Validate CRPS is created and matches CRP status" )
2328+ crpsMatchesActual := crpstatussync .CRPSStatusMatchesCRPActual (ctx , k8sClient , testCRPName , namespaceName )
2329+ Eventually (crpsMatchesActual , eventuallyTimeout , interval ).Should (Succeed (), "ClusterResourcePlacementStatus should be created and match expected structure" )
23202330 })
23212331 })
23222332})
0 commit comments