@@ -1751,7 +1751,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1751
1751
Expect (err ).To (HaveOccurred ())
1752
1752
})
1753
1753
1754
- It ("should update the resource when deleting if it receives a response" , func () {
1754
+ It ("should update the resource when deleting if it receives a response" , func (ctx SpecContext ) {
1755
1755
cl , err := client .New (cfg , client.Options {})
1756
1756
Expect (err ).NotTo (HaveOccurred ())
1757
1757
Expect (cl ).NotTo (BeNil ())
@@ -1767,7 +1767,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1767
1767
1768
1768
By ("deleting the Node" )
1769
1769
nodeName := node .Name
1770
- err = cl .Delete (context . TODO () , node )
1770
+ err = cl .Delete (ctx , node )
1771
1771
Expect (err ).NotTo (HaveOccurred ())
1772
1772
Expect (node .ObjectMeta .DeletionTimestamp ).NotTo (BeNil ())
1773
1773
@@ -1940,7 +1940,48 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
1940
1940
_ , err = clientset .AppsV1 ().Deployments (ns ).Get (ctx , dep2Name , metav1.GetOptions {})
1941
1941
Expect (err ).To (HaveOccurred ())
1942
1942
})
1943
+
1944
+ It ("should update the resource when deleting if it receives a response" , func (ctx SpecContext ) {
1945
+ cl , err := client .New (cfg , client.Options {})
1946
+ Expect (err ).NotTo (HaveOccurred ())
1947
+ Expect (cl ).NotTo (BeNil ())
1948
+
1949
+ By ("initially creating a Node" )
1950
+ node , err := clientset .CoreV1 ().Nodes ().Create (ctx , node , metav1.CreateOptions {})
1951
+ Expect (err ).NotTo (HaveOccurred ())
1952
+
1953
+ By ("adding a finalizer we prevent the node from being deleted immediately" )
1954
+ controllerutil .AddFinalizer (node , "example.com/test" )
1955
+ node , err = clientset .CoreV1 ().Nodes ().Update (ctx , node , metav1.UpdateOptions {})
1956
+ Expect (err ).NotTo (HaveOccurred ())
1957
+
1958
+ By ("deleting the Node" )
1959
+ nodeName := node .Name
1960
+ u := & unstructured.Unstructured {}
1961
+ Expect (scheme .Convert (node , u , nil )).To (Succeed ())
1962
+ u .SetGroupVersionKind (schema.GroupVersionKind {
1963
+ Group : "" ,
1964
+ Kind : "Node" ,
1965
+ Version : "v1" ,
1966
+ })
1967
+ err = cl .Delete (ctx , u )
1968
+ Expect (err ).NotTo (HaveOccurred ())
1969
+
1970
+ accessor , err := meta .Accessor (u )
1971
+ Expect (err ).NotTo (HaveOccurred ())
1972
+ Expect (accessor .GetDeletionTimestamp ()).NotTo (BeNil ())
1973
+
1974
+ By ("removing the finalizer" )
1975
+ controllerutil .RemoveFinalizer (u , "example.com/test" )
1976
+ err = cl .Delete (ctx , u )
1977
+ Expect (err ).NotTo (HaveOccurred ())
1978
+
1979
+ By ("validating the Node no longer exists" )
1980
+ _ , err = clientset .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
1981
+ Expect (err ).NotTo (HaveOccurred ())
1982
+ })
1943
1983
})
1984
+
1944
1985
Context ("with metadata objects" , func () {
1945
1986
It ("should delete an existing object from a go struct" , func (ctx SpecContext ) {
1946
1987
cl , err := client .New (cfg , client.Options {})
0 commit comments