Skip to content

Commit 27a3c52

Browse files
author
Shawn Hurley
committed
updating unstrcutured client to fix the tests.
1 parent 0d3d74b commit 27a3c52

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

pkg/cache/cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ var _ = Describe("Informer Cache", func() {
521521
By("verifying the object is received on the channel")
522522
Eventually(out).Should(Receive(Equal(pod)))
523523
close(done)
524-
})
524+
}, 3)
525525

526526
It("should be able to index an object field then retrieve objects by that field", func() {
527527
By("creating the cache")
@@ -571,7 +571,7 @@ var _ = Describe("Informer Cache", func() {
571571
Expect(listObj.Items).Should(HaveLen(1))
572572
actual := listObj.Items[0]
573573
Expect(actual.GetName()).To(Equal("test-pod-3"))
574-
})
574+
}, 3)
575575
})
576576
})
577577
})

pkg/client/unstructured_client.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ func (uc *unstructuredClient) Create(ctx context.Context, obj runtime.Object) er
4141
if !ok {
4242
return fmt.Errorf("unstructured client did not understand object: %T", obj)
4343
}
44-
r, err := uc.getResourceInterface(u.GroupVersionKind(), u.GetName())
44+
r, err := uc.getResourceInterface(u.GroupVersionKind(), u.GetNamespace())
4545
if err != nil {
4646
return err
4747
}
48-
_, err = r.Create(u)
49-
return err
48+
i, err := r.Create(u)
49+
if err != nil {
50+
return err
51+
}
52+
u.Object = i.Object
53+
return nil
5054
}
5155

5256
// Update implements client.Client
@@ -55,12 +59,16 @@ func (uc *unstructuredClient) Update(ctx context.Context, obj runtime.Object) er
5559
if !ok {
5660
return fmt.Errorf("unstructured client did not understand object: %T", obj)
5761
}
58-
r, err := uc.getResourceInterface(u.GroupVersionKind(), u.GetName())
62+
r, err := uc.getResourceInterface(u.GroupVersionKind(), u.GetNamespace())
5963
if err != nil {
6064
return err
6165
}
62-
u, err = r.Update(u)
63-
return err
66+
i, err := r.Update(u)
67+
if err != nil {
68+
return err
69+
}
70+
u.Object = i.Object
71+
return nil
6472
}
6573

6674
// Delete implements client.Client
@@ -69,7 +77,7 @@ func (uc *unstructuredClient) Delete(ctx context.Context, obj runtime.Object) er
6977
if !ok {
7078
return fmt.Errorf("unstructured client did not understand object: %T", obj)
7179
}
72-
r, err := uc.getResourceInterface(u.GroupVersionKind(), u.GetName())
80+
r, err := uc.getResourceInterface(u.GroupVersionKind(), u.GetNamespace())
7381
if err != nil {
7482
return err
7583
}
@@ -87,8 +95,12 @@ func (uc *unstructuredClient) Get(ctx context.Context, key ObjectKey, obj runtim
8795
if err != nil {
8896
return err
8997
}
90-
u, err = r.Get(key.Name, metav1.GetOptions{})
91-
return err
98+
i, err := r.Get(key.Name, metav1.GetOptions{})
99+
if err != nil {
100+
return err
101+
}
102+
u.Object = i.Object
103+
return nil
92104
}
93105

94106
// List implements client.Client
@@ -102,8 +114,12 @@ func (uc *unstructuredClient) List(ctx context.Context, opts *ListOptions, obj r
102114
if err != nil {
103115
return err
104116
}
105-
u, err = r.List(*opts.AsListOptions())
106-
return err
117+
i, err := r.List(*opts.AsListOptions())
118+
if err != nil {
119+
return err
120+
}
121+
u.Object = i.Object
122+
return nil
107123
}
108124

109125
func (uc *unstructuredClient) getResourceInterface(gvk schema.GroupVersionKind, ns string) (dynamic.ResourceInterface, error) {

0 commit comments

Comments
 (0)