forked from projectcalico/calico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.go
93 lines (79 loc) · 2.57 KB
/
storage.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
89
90
91
92
93
// Copyright (c) 2019 Tigera, Inc. All rights reserved.
package bgpconfiguration
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic/registry"
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
calico "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
"github.com/dtest11/calico/apiserver/pkg/registry/projectcalico/server"
)
// rest implements a RESTStorage for API services against etcd
type REST struct {
*genericregistry.Store
shortNames []string
}
func (r *REST) ShortNames() []string {
return r.shortNames
}
func (r *REST) Categories() []string {
return []string{""}
}
// EmptyObject returns an empty instance
func EmptyObject() runtime.Object {
return &calico.BGPConfiguration{}
}
// NewList returns a new shell of a binding list
func NewList() runtime.Object {
return &calico.BGPConfigurationList{}
}
// NewREST returns a RESTStorage object that will work against API services.
func NewREST(scheme *runtime.Scheme, opts server.Options) (*REST, error) {
strategy := NewStrategy(scheme)
prefix := "/" + opts.ResourcePrefix()
// We adapt the store's keyFunc so that we can use it with the StorageDecorator
// without making any assumptions about where objects are stored in etcd
keyFunc := func(obj runtime.Object) (string, error) {
accessor, err := meta.Accessor(obj)
if err != nil {
return "", err
}
return registry.NoNamespaceKeyFunc(
genericapirequest.NewContext(),
prefix,
accessor.GetName(),
)
}
storageInterface, dFunc, err := opts.GetStorage(
prefix,
keyFunc,
strategy,
func() runtime.Object { return &calico.BGPConfiguration{} },
func() runtime.Object { return &calico.BGPConfigurationList{} },
GetAttrs,
nil,
nil,
)
if err != nil {
return nil, err
}
store := &genericregistry.Store{
NewFunc: func() runtime.Object { return &calico.BGPConfiguration{} },
NewListFunc: func() runtime.Object { return &calico.BGPConfigurationList{} },
KeyRootFunc: opts.KeyRootFunc(false),
KeyFunc: opts.KeyFunc(false),
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*calico.BGPConfiguration).Name, nil
},
PredicateFunc: MatchBGPConfiguration,
DefaultQualifiedResource: calico.Resource("bgpconfigurations"),
CreateStrategy: strategy,
UpdateStrategy: strategy,
DeleteStrategy: strategy,
EnableGarbageCollection: true,
Storage: storageInterface,
DestroyFunc: dFunc,
}
return &REST{store, opts.ShortNames}, nil
}