@@ -50,6 +50,7 @@ import (
5050 "sigs.k8s.io/controller-runtime/examples/crd/pkg"
5151 "sigs.k8s.io/controller-runtime/pkg/cache"
5252 "sigs.k8s.io/controller-runtime/pkg/client"
53+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
5354)
5455
5556func deleteDeployment (ctx context.Context , dep * appsv1.Deployment , ns string ) {
@@ -1638,6 +1639,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
16381639 nodeName := node .Name
16391640 err = cl .Delete (context .TODO (), node )
16401641 Expect (err ).NotTo (HaveOccurred ())
1642+ Expect (node .ObjectMeta .DeletionTimestamp ).To (BeNil ())
16411643
16421644 By ("validating the Node no longer exists" )
16431645 _ , err = clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
@@ -1654,6 +1656,36 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
16541656 Expect (err ).To (HaveOccurred ())
16551657 })
16561658
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+
16571689 PIt ("should fail if the object doesn't have meta" , func () {
16581690
16591691 })
0 commit comments