@@ -1374,12 +1374,6 @@ var _ = Describe("applying manifests", func() {
13741374 // The environment prepared by the envtest package does not support namespace
13751375 // deletion; each test case would use a new namespace.
13761376 nsName := fmt .Sprintf (nsNameTemplate , utils .RandStr ())
1377- anotherOwnerReference := metav1.OwnerReference {
1378- APIVersion : "another-api-version" ,
1379- Kind : "another-kind" ,
1380- Name : "another-owner" ,
1381- UID : "another-uid" ,
1382- }
13831377
13841378 var appliedWorkOwnerRef * metav1.OwnerReference
13851379 var regularNS * corev1.Namespace
@@ -1398,7 +1392,7 @@ var _ = Describe("applying manifests", func() {
13981392 regularDeployJSON := marshalK8sObjJSON (regularDeploy )
13991393
14001394 // Create a new Work object with all the manifest JSONs.
1401- createWorkObject (workName , & fleetv1beta1. ApplyStrategy { AllowCoOwnership : true } , regularNSJSON , regularDeployJSON )
1395+ createWorkObject (workName , nil , regularNSJSON , regularDeployJSON )
14021396 })
14031397
14041398 It ("should add cleanup finalizer to the Work object" , func () {
@@ -1534,75 +1528,82 @@ var _ = Describe("applying manifests", func() {
15341528 })
15351529
15361530 It ("can update object to add another owner reference" , func () {
1537- // Retrieve the Deployment object.
1538- gotDeploy := & appsv1.Deployment {}
1539- Expect (memberClient .Get (ctx , client.ObjectKey {Namespace : nsName , Name : deployName }, gotDeploy )).To (Succeed (), "Failed to retrieve the Deployment object" )
1540-
1541- // Add another owner reference to the Deployment object.
1542- gotDeploy .OwnerReferences = append (gotDeploy .OwnerReferences , anotherOwnerReference )
1543- Expect (memberClient .Update (ctx , gotDeploy )).To (Succeed (), "Failed to update the Deployment object with another owner reference" )
1544-
1545- // Ensure that the Deployment object has been updated as expected.
1546- Eventually (func () error {
1547- // Retrieve the Deployment object again.
1548- if err := memberClient .Get (ctx , client.ObjectKey {Namespace : nsName , Name : deployName }, gotDeploy ); err != nil {
1549- return fmt .Errorf ("failed to retrieve the Deployment object: %w" , err )
1550- }
1551-
1552- // Check that the Deployment object has been updated as expected.
1553- if len (gotDeploy .OwnerReferences ) != 2 {
1554- return fmt .Errorf ("expected 2 owner references, got %d" , len (gotDeploy .OwnerReferences ))
1555- }
1556- for _ , ownerRef := range gotDeploy .OwnerReferences {
1557- if ownerRef .UID == anotherOwnerReference .UID {
1558- return nil
1559- }
1560- }
1561- return fmt .Errorf ("another owner reference not found in the Deployment object" )
1562- }, eventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to find another owner reference on Deployment" )
15631531 })
15641532
1565- It ("should start deleting the Work object " , func () {
1566- // Start deleting the Work object.
1567- deleteWorkObject ( workName )
1533+ It ("should garbage collect removed manifests " , func () {
1534+ deployRemovedActual := regularDeployRemovedActual ( nsName , deployName )
1535+ Eventually ( deployRemovedActual , eventuallyDuration , eventuallyInterval ). Should ( Succeed (), "Failed to remove the deployment object" )
15681536 })
15691537
1570- It ("should start deleting the AppliedWork object" , func () {
1571- // Ensure that the Work object is being deleted.
1572- Eventually (func () error {
1573- appliedWork := & fleetv1beta1.AppliedWork {}
1574- if err := memberClient .Get (ctx , client.ObjectKey {Name : workName }, appliedWork ); err != nil {
1575- return err
1576- }
1577- if ! appliedWork .DeletionTimestamp .IsZero () {
1578- return fmt .Errorf ("appliedWork object still is not being deleted" )
1579- }
1580- return nil
1581- }, eventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to start deleting the AppliedWork object" )
1538+ It ("should update the Work object status" , func () {
1539+ // Prepare the status information.
1540+ workConds := []metav1.Condition {
1541+ {
1542+ Type : fleetv1beta1 .WorkConditionTypeApplied ,
1543+ Status : metav1 .ConditionTrue ,
1544+ Reason : WorkAllManifestsAppliedReason ,
1545+ },
1546+ {
1547+ Type : fleetv1beta1 .WorkConditionTypeAvailable ,
1548+ Status : metav1 .ConditionTrue ,
1549+ Reason : WorkAllManifestsAvailableReason ,
1550+ },
1551+ }
1552+ manifestConds := []fleetv1beta1.ManifestCondition {
1553+ {
1554+ Identifier : fleetv1beta1.WorkResourceIdentifier {
1555+ Ordinal : 0 ,
1556+ Group : "" ,
1557+ Version : "v1" ,
1558+ Kind : "Namespace" ,
1559+ Resource : "namespaces" ,
1560+ Name : nsName ,
1561+ },
1562+ Conditions : []metav1.Condition {
1563+ {
1564+ Type : fleetv1beta1 .WorkConditionTypeApplied ,
1565+ Status : metav1 .ConditionTrue ,
1566+ Reason : string (ManifestProcessingApplyResultTypeApplied ),
1567+ ObservedGeneration : 0 ,
1568+ },
1569+ {
1570+ Type : fleetv1beta1 .WorkConditionTypeAvailable ,
1571+ Status : metav1 .ConditionTrue ,
1572+ Reason : string (ManifestProcessingAvailabilityResultTypeAvailable ),
1573+ ObservedGeneration : 0 ,
1574+ },
1575+ },
1576+ },
1577+ }
1578+
1579+ workStatusUpdatedActual := workStatusUpdated (workName , workConds , manifestConds , nil , nil )
1580+ Eventually (workStatusUpdatedActual , eventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to update work status" )
15821581 })
15831582
1584- It ("should update owner reference from the Deployment object" , func () {
1585- // Ensure that the Deployment object has been updated to remove the owner reference.
1586- Eventually (func () error {
1587- // Retrieve the Deployment object again.
1588- gotDeploy := & appsv1.Deployment {}
1589- if err := memberClient .Get (ctx , client.ObjectKey {Namespace : nsName , Name : deployName }, gotDeploy ); err != nil {
1590- return fmt .Errorf ("failed to retrieve the Deployment object: %w" , err )
1591- }
1583+ It ("should update the AppliedWork object status" , func () {
1584+ // Prepare the status information.
1585+ appliedResourceMeta := []fleetv1beta1.AppliedResourceMeta {
1586+ {
1587+ WorkResourceIdentifier : fleetv1beta1.WorkResourceIdentifier {
1588+ Ordinal : 0 ,
1589+ Group : "" ,
1590+ Version : "v1" ,
1591+ Kind : "Namespace" ,
1592+ Resource : "namespaces" ,
1593+ Name : nsName ,
1594+ },
1595+ UID : regularNS .UID ,
1596+ },
1597+ }
15921598
1593- // Check that the Deployment object has been updated as expected.
1594- for _ , ownerRef := range gotDeploy .OwnerReferences {
1595- if ownerRef .UID == appliedWorkOwnerRef .UID {
1596- if * ownerRef .BlockOwnerDeletion {
1597- return fmt .Errorf ("owner reference from AppliedWork still has BlockOwnerDeletion set to true" )
1598- }
1599- }
1600- }
1601- return nil
1602- }, eventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to remove owner reference from Deployment" )
1599+ appliedWorkStatusUpdatedActual := appliedWorkStatusUpdated (workName , appliedResourceMeta )
1600+ Eventually (appliedWorkStatusUpdatedActual , eventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to update appliedWork status" )
16031601 })
16041602
16051603 AfterAll (func () {
1604+ // Delete the Work object and related resources.
1605+ deleteWorkObject (workName )
1606+
16061607 // Ensure that the AppliedWork object has been removed.
16071608 appliedWorkRemovedActual := appliedWorkRemovedActual (workName )
16081609 Eventually (appliedWorkRemovedActual , eventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to remove the AppliedWork object" )
0 commit comments