-
Notifications
You must be signed in to change notification settings - Fork 103
/
client.go
61 lines (50 loc) · 2.26 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package client
import (
"context"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// ObjectKey identifies a Kubernetes Object.
type ObjectKey = types.NamespacedName
// Client is a wrapper around the raw kube client provided
// by operator-sdk. Using the wrapper facilitates mocking of client
// interactions with the cluster, while using fakeclient during unit testing.
// TODO(tflannag): Should this be removed entirely in favor of c-r's dynamic client?
type Client interface {
Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
Get(ctx context.Context, key ObjectKey, objExisting client.Object, opts ...client.GetOption) error
Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}
// kubeClient is an implementation of the Client interface
type kubeClient struct {
client client.Client
}
// NewClient returns a kubeClient that can perform
// create, get and update operations on a runtime object
func NewClient(client client.Client) Client {
return &kubeClient{
client: client,
}
}
// Create creates a new runtime object in the cluster
func (h *kubeClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
return h.client.Create(ctx, obj, opts...)
}
// Get gets an existing runtime object from the cluster
func (h *kubeClient) Get(ctx context.Context, key ObjectKey, objExisting client.Object, opts ...client.GetOption) error {
return h.client.Get(ctx, key, objExisting, opts...)
}
// Update updates an existing runtime object in the cluster
func (h *kubeClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
return h.client.Update(ctx, obj, opts...)
}
// Delete deletes a new runtime object in the cluster
func (h *kubeClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
return h.client.Delete(ctx, obj, opts...)
}
// List lists runtime objects in the cluster
func (h *kubeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
return h.client.List(ctx, list, opts...)
}