kubelatte-ce
Форк от sbertech/kubelatte-ce
113 строк · 3.0 Кб
1package clientset
2
3import (
4"context"
5"gitverse.ru/ktrntrsv/kubelatte-ce/pkg/api/v1alpha1"
6metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7"k8s.io/apimachinery/pkg/watch"
8"k8s.io/client-go/kubernetes/scheme"
9"k8s.io/client-go/rest"
10)
11
12type ScopeInterface interface {
13List(ctx context.Context, opts metav1.ListOptions) (*v1alpha1.ScopeList, error)
14Get(ctx context.Context, name string, options metav1.GetOptions) (*v1alpha1.Scope, error)
15Update(ctx context.Context, scope *v1alpha1.Scope, opts metav1.UpdateOptions) (result *v1alpha1.Scope, err error)
16UpdateStatus(ctx context.Context, hostEntry *v1alpha1.Scope, opts metav1.UpdateOptions) (*v1alpha1.Scope, error)
17Create(ctx context.Context, scope *v1alpha1.Scope) (*v1alpha1.Scope, error)
18Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
19Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
20}
21
22type scopeClient struct {
23restClient rest.Interface
24ns string
25}
26
27func (c *scopeClient) List(ctx context.Context, opts metav1.ListOptions) (*v1alpha1.ScopeList, error) {
28result := v1alpha1.ScopeList{}
29err := c.restClient.
30Get().
31Namespace(c.ns).
32Resource("scopes").
33VersionedParams(&opts, scheme.ParameterCodec).
34Do(ctx).
35Into(&result)
36
37return &result, err
38}
39
40func (c *scopeClient) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1alpha1.Scope, error) {
41result := v1alpha1.Scope{}
42err := c.restClient.
43Get().
44Namespace(c.ns).
45Resource("scopes").
46Name(name).
47VersionedParams(&opts, scheme.ParameterCodec).
48Do(ctx).
49Into(&result)
50
51return &result, err
52}
53
54func (c *scopeClient) Update(ctx context.Context, scope *v1alpha1.Scope, opts metav1.UpdateOptions) (result *v1alpha1.Scope, err error) {
55result = &v1alpha1.Scope{}
56err = c.restClient.Put().
57Namespace(c.ns).
58Resource("scopes").
59Name(scope.Name).
60VersionedParams(&opts, scheme.ParameterCodec).
61Body(scope).
62Do(ctx).
63Into(result)
64return
65}
66
67func (c *scopeClient) UpdateStatus(ctx context.Context, hostEntry *v1alpha1.Scope, opts metav1.UpdateOptions) (result *v1alpha1.Scope, err error) {
68result = &v1alpha1.Scope{}
69err = c.restClient.Put().
70Namespace(c.ns).
71Resource("scopes").
72Name(hostEntry.Name).
73SubResource("status").
74VersionedParams(&opts, scheme.ParameterCodec).
75Body(hostEntry).
76Do(ctx).
77Into(result)
78return
79}
80
81func (c *scopeClient) Create(ctx context.Context, scope *v1alpha1.Scope) (*v1alpha1.Scope, error) {
82result := v1alpha1.Scope{}
83err := c.restClient.
84Post().
85Namespace(c.ns).
86Resource("scopes").
87Body(scope).
88Do(ctx).
89Into(&result)
90
91return &result, err
92}
93
94func (c *scopeClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
95return c.restClient.
96Delete().
97Namespace(c.ns).
98Resource("scopes").
99Name(name).
100Body(&opts).
101Do(ctx).
102Error()
103}
104
105func (c *scopeClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
106opts.Watch = true
107return c.restClient.
108Get().
109Namespace(c.ns).
110Resource("scope").
111VersionedParams(&opts, scheme.ParameterCodec).
112Watch(ctx)
113}
114