-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pod.go
88 lines (76 loc) · 1.99 KB
/
Pod.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
77
78
79
80
81
82
83
84
85
86
87
88
package v1alpha1
import (
"context"
migv1 "github.com/hth0919/migcore/pkg/apis/keti/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
)
type MigrationPodInterface interface {
RESTClient() rest.Interface
List(opts metav1.ListOptions) (*migv1.PodList, error)
Get(name string, options metav1.GetOptions) (*migv1.Pod, error)
Create(migration *migv1.Pod) (*migv1.Pod, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
// ...
}
type MigrationPodClient struct {
restClient rest.Interface
ns string
}
func newMigrationPodClient(c *ExampleV1Alpha1Client, namespace string) *MigrationPodClient {
return &MigrationPodClient{
restClient: c.RESTClient(),
ns: namespace,
}
}
func (c *MigrationPodClient) RESTClient() rest.Interface {
if c == nil {
return nil
}
return c.restClient
}
func (c *MigrationPodClient) List(opts metav1.ListOptions) (*migv1.PodList, error) {
result := migv1.PodList{}
err := c.restClient.
Get().
Namespace(c.ns).
Resource("pods").
VersionedParams(&opts, scheme.ParameterCodec).
Do(context.TODO()).
Into(&result)
return &result, err
}
func (c *MigrationPodClient) Get(name string, opts metav1.GetOptions) (*migv1.Pod, error) {
result := migv1.Pod{}
err := c.restClient.
Get().
Namespace(c.ns).
Resource("pods").
Name(name).
VersionedParams(&opts, scheme.ParameterCodec).
Do(context.TODO()).
Into(&result)
return &result, err
}
func (c *MigrationPodClient) Create(migration *migv1.Pod) (*migv1.Pod, error) {
result := migv1.Pod{}
err := c.restClient.
Post().
Namespace(c.ns).
Resource("pods").
Body(migration).
Do(context.TODO()).
Into(&result)
return &result, err
}
func (c *MigrationPodClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
opts.Watch = true
return c.restClient.
Get().
Namespace(c.ns).
Resource("pods").
VersionedParams(&opts, scheme.ParameterCodec).
Watch(context.Background())
}