@@ -50,6 +50,7 @@ import (
50
50
"sigs.k8s.io/controller-runtime/examples/crd/pkg"
51
51
"sigs.k8s.io/controller-runtime/pkg/cache"
52
52
"sigs.k8s.io/controller-runtime/pkg/client"
53
+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
53
54
)
54
55
55
56
func deleteDeployment (ctx context.Context , dep * appsv1.Deployment , ns string ) {
@@ -1638,6 +1639,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1638
1639
nodeName := node .Name
1639
1640
err = cl .Delete (context .TODO (), node )
1640
1641
Expect (err ).NotTo (HaveOccurred ())
1642
+ Expect (node .ObjectMeta .DeletionTimestamp ).To (BeNil ())
1641
1643
1642
1644
By ("validating the Node no longer exists" )
1643
1645
_ , err = clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
@@ -1654,6 +1656,36 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1654
1656
Expect (err ).To (HaveOccurred ())
1655
1657
})
1656
1658
1659
+ It ("should update the resource when deleting if it receives a response" , func () {
1660
+ cl , err := client .New (cfg , client.Options {})
1661
+ Expect (err ).NotTo (HaveOccurred ())
1662
+ Expect (cl ).NotTo (BeNil ())
1663
+
1664
+ By ("initially creating a Node" )
1665
+ node , err := clientset .CoreV1 ().Nodes ().Create (ctx , node , metav1.CreateOptions {})
1666
+ Expect (err ).NotTo (HaveOccurred ())
1667
+
1668
+ By ("adding a finalizer we prevent the node from being deleted immediately" )
1669
+ controllerutil .AddFinalizer (node , "example.com/test" )
1670
+ node , err = clientset .CoreV1 ().Nodes ().Update (ctx , node , metav1.UpdateOptions {})
1671
+ Expect (err ).NotTo (HaveOccurred ())
1672
+
1673
+ By ("deleting the Node" )
1674
+ nodeName := node .Name
1675
+ err = cl .Delete (context .TODO (), node )
1676
+ Expect (err ).NotTo (HaveOccurred ())
1677
+ Expect (node .ObjectMeta .DeletionTimestamp ).NotTo (BeNil ())
1678
+
1679
+ By ("removing the finalizer" )
1680
+ controllerutil .RemoveFinalizer (node , "example.com/test" )
1681
+ _ , err = clientset .CoreV1 ().Nodes ().Update (ctx , node , metav1.UpdateOptions {})
1682
+ Expect (err ).NotTo (HaveOccurred ())
1683
+
1684
+ By ("validating the Node no longer exists" )
1685
+ _ , err = clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
1686
+ Expect (err ).To (HaveOccurred ())
1687
+ })
1688
+
1657
1689
PIt ("should fail if the object doesn't have meta" , func () {
1658
1690
1659
1691
})
0 commit comments