forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
store.go
60 lines (52 loc) · 1.47 KB
/
store.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
package ingress
import (
"github.com/rancher/norman/store/proxy"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/workload/controller/ingress"
"github.com/rancher/types/config"
"github.com/satori/uuid"
)
type Store struct {
types.Store
proxyStore *proxy.Store
controller *ingress.Controller
}
func NewStore(workload *config.WorkloadContext) *Store {
return &Store{
Store: proxy.NewProxyStore(workload.UnversionedClient,
[]string{"apis"},
"extensions",
"v1beta1",
"Ingress",
"ingresses"),
proxyStore: proxy.NewRawProxyStore(workload.UnversionedClient,
[]string{"apis"},
"extensions",
"v1beta1",
"Ingress",
"ingresses"),
controller: ingress.NewIngressWorkloadController(workload),
}
}
func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
data["uuid"] = uuid.NewV4().String()
_, err := s.controller.Reconcile(data, true)
if err != nil {
return nil, err
}
return s.Store.Create(apiContext, schema, data)
}
func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
existing, err := s.Store.ByID(apiContext, schema, id)
if err != nil {
return existing, err
}
for k, v := range data {
existing[k] = v
}
_, err = s.controller.Reconcile(existing, true)
if err != nil {
return nil, err
}
return s.Store.Update(apiContext, schema, data, id)
}