Skip to content

Commit 4ac29a2

Browse files
committed
Update the unstructured client to return the values.
Signed-off-by: Kevin McDermott <[email protected]>
1 parent 00b465d commit 4ac29a2

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

pkg/client/client_test.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
17511751
Expect(err).To(HaveOccurred())
17521752
})
17531753

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) {
17551755
cl, err := client.New(cfg, client.Options{})
17561756
Expect(err).NotTo(HaveOccurred())
17571757
Expect(cl).NotTo(BeNil())
@@ -1767,7 +1767,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
17671767

17681768
By("deleting the Node")
17691769
nodeName := node.Name
1770-
err = cl.Delete(context.TODO(), node)
1770+
err = cl.Delete(ctx, node)
17711771
Expect(err).NotTo(HaveOccurred())
17721772
Expect(node.ObjectMeta.DeletionTimestamp).NotTo(BeNil())
17731773

@@ -1940,7 +1940,48 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
19401940
_, err = clientset.AppsV1().Deployments(ns).Get(ctx, dep2Name, metav1.GetOptions{})
19411941
Expect(err).To(HaveOccurred())
19421942
})
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+
})
19431983
})
1984+
19441985
Context("with metadata objects", func() {
19451986
It("should delete an existing object from a go struct", func(ctx SpecContext) {
19461987
cl, err := client.New(cfg, client.Options{})

pkg/client/dryrun_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ var _ = Describe("DryRunClient", func() {
179179
Expect(actual).To(BeEquivalentTo(dep))
180180
})
181181

182-
It("should not delete objects", func() {
182+
It("should not delete objects", func(ctx SpecContext) {
183183
changedDep := dep.DeepCopy()
184184
Expect(getClient().Delete(ctx, changedDep)).NotTo(HaveOccurred())
185185

pkg/client/unstructured_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (uc *unstructuredClient) Delete(ctx context.Context, obj Object, opts ...De
112112
Name(o.name).
113113
Body(deleteOpts.AsDeleteOptions()).
114114
Do(ctx).
115-
Error()
115+
Into(obj)
116116
}
117117

118118
// DeleteAllOf implements client.Client.

0 commit comments

Comments
 (0)