forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
etcd.go
79 lines (63 loc) · 2.32 KB
/
etcd.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
package etcd
import (
"k8s.io/apimachinery/pkg/runtime"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
kapi "k8s.io/kubernetes/pkg/api"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
"github.com/openshift/origin/pkg/build/registry/build"
"github.com/openshift/origin/pkg/util/restoptions"
)
type REST struct {
*registry.Store
}
var _ rest.StandardStorage = &REST{}
var _ rest.CategoriesProvider = &REST{}
// Categories implements the CategoriesProvider interface. Returns a list of categories a resource is part of.
func (r *REST) Categories() []string {
return []string{"all"}
}
// NewREST returns a RESTStorage object that will work against Build objects.
func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) {
store := ®istry.Store{
Copier: kapi.Scheme,
NewFunc: func() runtime.Object { return &buildapi.Build{} },
NewListFunc: func() runtime.Object { return &buildapi.BuildList{} },
DefaultQualifiedResource: buildapi.Resource("builds"),
CreateStrategy: build.Strategy,
UpdateStrategy: build.Strategy,
DeleteStrategy: build.Strategy,
}
options := &generic.StoreOptions{
RESTOptions: optsGetter,
AttrFunc: storage.AttrFunc(storage.DefaultNamespaceScopedAttr).WithFieldMutation(buildapi.BuildFieldSelector),
}
if err := store.CompleteWithOptions(options); err != nil {
return nil, nil, err
}
detailsStore := *store
detailsStore.UpdateStrategy = build.DetailsStrategy
return &REST{store}, &DetailsREST{&detailsStore}, nil
}
type DetailsREST struct {
store *registry.Store
}
var _ rest.Updater = &DetailsREST{}
// New returns an empty object that can be used with Update after request data has been put into it.
func (r *DetailsREST) New() runtime.Object {
return r.store.New()
}
// Update finds a resource in the storage and updates it.
func (r *DetailsREST) Update(ctx apirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo)
}
// LegacyREST allows us to wrap and alter some behavior
type LegacyREST struct {
*REST
}
func (r *LegacyREST) Categories() []string {
return []string{}
}