@@ -51,6 +51,7 @@ import (
51
51
"sigs.k8s.io/controller-runtime/examples/crd/pkg"
52
52
"sigs.k8s.io/controller-runtime/pkg/cache"
53
53
"sigs.k8s.io/controller-runtime/pkg/client"
54
+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
54
55
)
55
56
56
57
func deleteDeployment (ctx context.Context , dep * appsv1.Deployment , ns string ) {
@@ -1733,6 +1734,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1733
1734
nodeName := node .Name
1734
1735
err = cl .Delete (ctx , node )
1735
1736
Expect (err ).NotTo (HaveOccurred ())
1737
+ Expect (node .ObjectMeta .DeletionTimestamp ).To (BeNil ())
1736
1738
1737
1739
By ("validating the Node no longer exists" )
1738
1740
_ , err = clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
@@ -1749,6 +1751,36 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1749
1751
Expect (err ).To (HaveOccurred ())
1750
1752
})
1751
1753
1754
+ It ("should update the resource when deleting if it receives a response" , func () {
1755
+ cl , err := client .New (cfg , client.Options {})
1756
+ Expect (err ).NotTo (HaveOccurred ())
1757
+ Expect (cl ).NotTo (BeNil ())
1758
+
1759
+ By ("initially creating a Node" )
1760
+ node , err := clientset .CoreV1 ().Nodes ().Create (ctx , node , metav1.CreateOptions {})
1761
+ Expect (err ).NotTo (HaveOccurred ())
1762
+
1763
+ By ("adding a finalizer we prevent the node from being deleted immediately" )
1764
+ controllerutil .AddFinalizer (node , "example.com/test" )
1765
+ node , err = clientset .CoreV1 ().Nodes ().Update (ctx , node , metav1.UpdateOptions {})
1766
+ Expect (err ).NotTo (HaveOccurred ())
1767
+
1768
+ By ("deleting the Node" )
1769
+ nodeName := node .Name
1770
+ err = cl .Delete (context .TODO (), node )
1771
+ Expect (err ).NotTo (HaveOccurred ())
1772
+ Expect (node .ObjectMeta .DeletionTimestamp ).NotTo (BeNil ())
1773
+
1774
+ By ("removing the finalizer" )
1775
+ controllerutil .RemoveFinalizer (node , "example.com/test" )
1776
+ _ , err = clientset .CoreV1 ().Nodes ().Update (ctx , node , metav1.UpdateOptions {})
1777
+ Expect (err ).NotTo (HaveOccurred ())
1778
+
1779
+ By ("validating the Node no longer exists" )
1780
+ _ , err = clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
1781
+ Expect (err ).To (HaveOccurred ())
1782
+ })
1783
+
1752
1784
PIt ("should fail if the object doesn't have meta" , func () {
1753
1785
1754
1786
})
0 commit comments