Skip to content

Commit

Permalink
Accept narrower interfaces
Browse files Browse the repository at this point in the history
The Get function only uses methods defined in client.Reader.

The Delete function only uses methods defined in client.Writer.

Therefore they can accept client.Reader and client.Writer, instead
of client.Client, which combines both client.Reader and client.Writer.

This change allows callers that can only pass in a client.Reader
or client.Writer.
  • Loading branch information
dlipovetsky committed Feb 10, 2022
1 parent 691e5c4 commit f9e4148
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions controllers/external/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// Get uses the client and reference to get an external, unstructured object.
func Get(ctx context.Context, c client.Client, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) {
func Get(ctx context.Context, c client.Reader, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) {
if ref == nil {
return nil, errors.Errorf("cannot get object - object reference not set")
}
Expand All @@ -47,7 +47,7 @@ func Get(ctx context.Context, c client.Client, ref *corev1.ObjectReference, name
}

// Delete uses the client and reference to delete an external, unstructured object.
func Delete(ctx context.Context, c client.Client, ref *corev1.ObjectReference) error {
func Delete(ctx context.Context, c client.Writer, ref *corev1.ObjectReference) error {
obj := new(unstructured.Unstructured)
obj.SetAPIVersion(ref.APIVersion)
obj.SetKind(ref.Kind)
Expand Down

0 comments on commit f9e4148

Please sign in to comment.