Skip to content

Commit 7397811

Browse files
committed
WIP: client: update status subresource support
1 parent 3aaf8cd commit 7397811

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

pkg/client/client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ func (c *client) Update(ctx context.Context, obj runtime.Object) error {
110110
Into(obj)
111111
}
112112

113+
// UpdateStatus implements client.Client
114+
func (c *client) UpdateStatus(ctx context.Context, obj runtime.Object) error {
115+
o, err := c.cache.getObjMeta(obj)
116+
if err != nil {
117+
return err
118+
}
119+
// TODO(droot): examine the returned error and check if it error needs to be
120+
// wrapped to improve the UX ?
121+
return o.Put().
122+
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
123+
Resource(o.resource()).
124+
Name(o.GetName()).
125+
SubResource("status").
126+
Body(obj).
127+
Do().
128+
Into(obj)
129+
}
130+
113131
// Delete implements client.Client
114132
func (c *client) Delete(ctx context.Context, obj runtime.Object) error {
115133
o, err := c.cache.getObjMeta(obj)

pkg/client/fake/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ func (c *fakeClient) Update(ctx context.Context, obj runtime.Object) error {
123123
return c.tracker.Update(gvr, obj, accessor.GetNamespace())
124124
}
125125

126+
func (c *fakeClient) UpdateStatus(ctx context.Context, obj runtime.Object) error {
127+
// TODO(droot): implement for *real*
128+
return nil
129+
}
130+
126131
func getGVRFromObject(obj runtime.Object) (schema.GroupVersionResource, error) {
127132
gvk, err := apiutil.GVKForObject(obj, scheme.Scheme)
128133
if err != nil {

pkg/client/interfaces.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ type Writer interface {
5555
// Update updates the given obj in the Kubernetes cluster. obj must be a
5656
// struct pointer so that obj can be updated with the content returned by the Server.
5757
Update(ctx context.Context, obj runtime.Object) error
58+
59+
// UpdateStatus updates the fields corresponding to status subresource for
60+
// the given obj. obj must be a struct pointer so that obj can be updated
61+
// with the content returned by the Server.
62+
UpdateStatus(ctx context.Context, obj runtime.Object) error
5863
}
5964

6065
// Client knows how to perform CRUD operations on Kubernetes objects.

0 commit comments

Comments
 (0)