forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
33 lines (31 loc) · 966 Bytes
/
helpers.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
package restoptions
import (
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic/registry"
)
// DefaultKeyFunctions sets the default behavior for storage key generation onto a Store.
func DefaultKeyFunctions(store *registry.Store, prefix string, isNamespaced bool) {
if isNamespaced {
if store.KeyRootFunc == nil {
store.KeyRootFunc = func(ctx apirequest.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
}
}
if store.KeyFunc == nil {
store.KeyFunc = func(ctx apirequest.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
}
}
} else {
if store.KeyRootFunc == nil {
store.KeyRootFunc = func(ctx apirequest.Context) string {
return prefix
}
}
if store.KeyFunc == nil {
store.KeyFunc = func(ctx apirequest.Context, name string) (string, error) {
return registry.NoNamespaceKeyFunc(ctx, prefix, name)
}
}
}
}