/
pvc.go
77 lines (72 loc) · 2.32 KB
/
pvc.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
package libk8s
import (
"github.com/robertkrimen/otto"
"k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/pkg/api/v1"
)
type PersistentVolumeClaim struct {
Create func(map[string]interface{}) otto.Value `otto:"create"`
Delete func(string, map[string]interface{}) `otto:"delete"`
List func(map[string]interface{}) otto.Value `otto:"list"`
Get func(string) otto.Value `otto:"get"`
Update func(map[string]interface{}) otto.Value `otto:"update"`
UpdateStatus func(map[string]interface{}) otto.Value `otto:"updateStatus"`
DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
// Watch func() otto.Value `otto:"watch"`
// Patch func() otto.Value `otto:"patch"`
}
func NewPersistentVolumeClaim(c kubernetes.Interface, o *otto.Otto, ns string) *PersistentVolumeClaim {
pi := func() v1core.PersistentVolumeClaimInterface {
return c.CoreV1().PersistentVolumeClaims(ns)
}
return &PersistentVolumeClaim{
Create: func(pod map[string]interface{}) otto.Value {
gp := &v1.PersistentVolumeClaim{}
poe(remarshal(pod, gp))
p, err := pi().Create(gp)
poe(err)
return MustToObject(p, o)
},
Delete: func(name string, opts map[string]interface{}) {
do := &v1.DeleteOptions{}
poe(remarshal(opts, do))
err := pi().Delete(name, do)
poe(err)
},
List: func(opts map[string]interface{}) otto.Value {
lo := v1.ListOptions{}
poe(remarshal(opts, &lo))
pl, err := pi().List(lo)
poe(err)
return MustToObject(pl, o)
},
Get: func(name string) otto.Value {
out, err := pi().Get(name)
poe(err)
return MustToObject(out, o)
},
Update: func(pod map[string]interface{}) otto.Value {
gp := &v1.PersistentVolumeClaim{}
poe(remarshal(pod, gp))
p, err := pi().Update(gp)
poe(err)
return MustToObject(p, o)
},
UpdateStatus: func(pod map[string]interface{}) otto.Value {
gp := &v1.PersistentVolumeClaim{}
poe(remarshal(pod, gp))
p, err := pi().UpdateStatus(gp)
poe(err)
return MustToObject(p, o)
},
DeleteCollection: func(dopts, lopts map[string]interface{}) {
do := &v1.DeleteOptions{}
poe(remarshal(dopts, do))
lo := v1.ListOptions{}
poe(remarshal(lopts, &lo))
err := pi().DeleteCollection(do, lo)
poe(err)
},
}
}