/
no_op_dynamic_client.go
76 lines (65 loc) · 3.09 KB
/
no_op_dynamic_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package incluster
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
)
// implement k8s.io/client-go/dynamic.Interface to be able to use it in the adapter
type NoOpDynamicClient struct {
}
type NoOpDynamicResource struct {
gvr schema.GroupVersionResource
}
// watch.Interface
type NoOpWatch struct {
eventChan chan watch.Event
}
func (n *NoOpDynamicClient) Resource(gvr schema.GroupVersionResource) dynamic.NamespaceableResourceInterface {
return &NoOpDynamicResource{gvr: gvr}
}
func (n *NoOpDynamicResource) Namespace(namespace string) dynamic.ResourceInterface {
return n
}
func (n *NoOpDynamicResource) Create(ctx context.Context, obj *unstructured.Unstructured, options metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error) {
return obj, nil
}
func (n *NoOpDynamicResource) Update(ctx context.Context, obj *unstructured.Unstructured, options metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) {
return obj, nil
}
func (n *NoOpDynamicResource) UpdateStatus(ctx context.Context, obj *unstructured.Unstructured, options metav1.UpdateOptions) (*unstructured.Unstructured, error) {
return obj, nil
}
func (n *NoOpDynamicResource) Delete(ctx context.Context, name string, options metav1.DeleteOptions, subresources ...string) error {
return nil
}
func (n *NoOpDynamicResource) DeleteCollection(ctx context.Context, options metav1.DeleteOptions, listOptions metav1.ListOptions) error {
return nil
}
func (n *NoOpDynamicResource) Get(ctx context.Context, name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error) {
return &unstructured.Unstructured{Object: map[string]interface{}{}}, nil
}
func (n *NoOpDynamicResource) List(ctx context.Context, opts metav1.ListOptions) (*unstructured.UnstructuredList, error) {
return &unstructured.UnstructuredList{Object: map[string]interface{}{}, Items: []unstructured.Unstructured{{Object: map[string]interface{}{}}}}, nil
}
func (n *NoOpDynamicResource) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return &NoOpWatch{eventChan: make(chan watch.Event)}, nil
}
func (n *NoOpDynamicResource) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, options metav1.PatchOptions, subresources ...string) (*unstructured.Unstructured, error) {
return &unstructured.Unstructured{Object: map[string]interface{}{}}, nil
}
func (n *NoOpDynamicResource) Apply(ctx context.Context, name string, obj *unstructured.Unstructured, options metav1.ApplyOptions, subresources ...string) (*unstructured.Unstructured, error) {
return obj, nil
}
func (n *NoOpDynamicResource) ApplyStatus(ctx context.Context, name string, obj *unstructured.Unstructured, options metav1.ApplyOptions) (*unstructured.Unstructured, error) {
return obj, nil
}
func (n *NoOpWatch) Stop() {
close(n.eventChan)
}
func (n *NoOpWatch) ResultChan() <-chan watch.Event {
return n.eventChan
}