Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Refactor typed_client and unstructured_client to be consistent #1795

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions pkg/client/typed_client.go
Expand Up @@ -42,6 +42,7 @@ func (c *typedClient) Create(ctx context.Context, obj Object, opts ...CreateOpti

createOpts := &CreateOptions{}
createOpts.ApplyOptions(opts)

return o.Post().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Expand All @@ -60,6 +61,7 @@ func (c *typedClient) Update(ctx context.Context, obj Object, opts ...UpdateOpti

updateOpts := &UpdateOptions{}
updateOpts.ApplyOptions(opts)

return o.Put().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Expand Down Expand Up @@ -121,11 +123,13 @@ func (c *typedClient) Patch(ctx context.Context, obj Object, patch Patch, opts .
}

patchOpts := &PatchOptions{}
patchOpts.ApplyOptions(opts)

return o.Patch(patch.Type()).
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), c.paramCodec).
VersionedParams(patchOpts.AsPatchOptions(), c.paramCodec).
Body(data).
Do(ctx).
Into(obj)
Expand All @@ -149,8 +153,10 @@ func (c *typedClient) List(ctx context.Context, obj ObjectList, opts ...ListOpti
if err != nil {
return err
}

listOpts := ListOptions{}
listOpts.ApplyOptions(opts)

return r.Get().
NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
Resource(r.resource()).
Expand All @@ -169,13 +175,16 @@ func (c *typedClient) UpdateStatus(ctx context.Context, obj Object, opts ...Upda
// wrapped to improve the UX ?
// It will be nice to receive an error saying the object doesn't implement
// status subresource and check CRD definition
updateOpts := &UpdateOptions{}
updateOpts.ApplyOptions(opts)

return o.Put().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
SubResource("status").
Body(obj).
VersionedParams((&UpdateOptions{}).ApplyOptions(opts).AsUpdateOptions(), c.paramCodec).
VersionedParams(updateOpts.AsUpdateOptions(), c.paramCodec).
Do(ctx).
Into(obj)
}
Expand All @@ -193,13 +202,15 @@ func (c *typedClient) PatchStatus(ctx context.Context, obj Object, patch Patch,
}

patchOpts := &PatchOptions{}
patchOpts.ApplyOptions(opts)

return o.Patch(patch.Type()).
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
SubResource("status").
Body(data).
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), c.paramCodec).
VersionedParams(patchOpts.AsPatchOptions(), c.paramCodec).
Do(ctx).
Into(obj)
}
23 changes: 17 additions & 6 deletions pkg/client/unstructured_client.go
Expand Up @@ -52,6 +52,7 @@ func (uc *unstructuredClient) Create(ctx context.Context, obj Object, opts ...Cr

createOpts := &CreateOptions{}
createOpts.ApplyOptions(opts)

result := o.Post().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Expand Down Expand Up @@ -80,6 +81,7 @@ func (uc *unstructuredClient) Update(ctx context.Context, obj Object, opts ...Up

updateOpts := UpdateOptions{}
updateOpts.ApplyOptions(opts)

result := o.Put().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Expand Down Expand Up @@ -107,6 +109,7 @@ func (uc *unstructuredClient) Delete(ctx context.Context, obj Object, opts ...De

deleteOpts := DeleteOptions{}
deleteOpts.ApplyOptions(opts)

return o.Delete().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Expand All @@ -130,6 +133,7 @@ func (uc *unstructuredClient) DeleteAllOf(ctx context.Context, obj Object, opts

deleteAllOfOpts := DeleteAllOfOptions{}
deleteAllOfOpts.ApplyOptions(opts)

return o.Delete().
NamespaceIfScoped(deleteAllOfOpts.ListOptions.Namespace, o.isNamespaced()).
Resource(o.resource()).
Expand Down Expand Up @@ -157,11 +161,13 @@ func (uc *unstructuredClient) Patch(ctx context.Context, obj Object, patch Patch
}

patchOpts := &PatchOptions{}
patchOpts.ApplyOptions(opts)

return o.Patch(patch.Type()).
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), uc.paramCodec).
VersionedParams(patchOpts.AsPatchOptions(), uc.paramCodec).
Body(data).
Do(ctx).
Into(obj)
Expand Down Expand Up @@ -205,14 +211,14 @@ func (uc *unstructuredClient) List(ctx context.Context, obj ObjectList, opts ...
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
}

listOpts := ListOptions{}
listOpts.ApplyOptions(opts)

r, err := uc.cache.getResource(obj)
if err != nil {
return err
}

listOpts := ListOptions{}
listOpts.ApplyOptions(opts)

return r.Get().
NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
Resource(r.resource()).
Expand All @@ -232,13 +238,16 @@ func (uc *unstructuredClient) UpdateStatus(ctx context.Context, obj Object, opts
return err
}

updateOpts := UpdateOptions{}
updateOpts.ApplyOptions(opts)

return o.Put().
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
SubResource("status").
Body(obj).
VersionedParams((&UpdateOptions{}).ApplyOptions(opts).AsUpdateOptions(), uc.paramCodec).
VersionedParams(updateOpts.AsUpdateOptions(), uc.paramCodec).
Do(ctx).
Into(obj)
}
Expand All @@ -262,13 +271,15 @@ func (uc *unstructuredClient) PatchStatus(ctx context.Context, obj Object, patch
}

patchOpts := &PatchOptions{}
patchOpts.ApplyOptions(opts)

result := o.Patch(patch.Type()).
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
SubResource("status").
Body(data).
VersionedParams(patchOpts.ApplyOptions(opts).AsPatchOptions(), uc.paramCodec).
VersionedParams(patchOpts.AsPatchOptions(), uc.paramCodec).
Do(ctx).
Into(u)

Expand Down