forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
etcd.go
86 lines (72 loc) · 2.72 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
80
81
82
83
84
85
86
package etcd
import (
"errors"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/image/registry/image"
)
// REST implements a RESTStorage for images against etcd.
type REST struct {
store *etcdgeneric.Etcd
}
// NewREST returns a new REST.
func NewREST(h tools.EtcdHelper) *REST {
prefix := "/images"
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Image{} },
NewListFunc: func() runtime.Object { return &api.ImageList{} },
KeyRootFunc: func(ctx kapi.Context) string {
// images are not namespace scoped
return prefix
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
// images are not namespace scoped
return prefix + "/" + name, nil
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Image).Name, nil
},
EndpointName: "image",
CreateStrategy: image.Strategy,
ReturnDeletedObject: false,
Helper: h,
}
return &REST{store: store}
}
// New returns a new object
func (r *REST) New() runtime.Object {
return r.store.NewFunc()
}
// NewList returns a new list object
func (r *REST) NewList() runtime.Object {
return r.store.NewListFunc()
}
// List obtains a list of images with labels that match selector.
func (r *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
return r.store.ListPredicate(ctx, image.MatchImage(label, field))
}
// Watch begins watching for new, changed, or deleted images.
func (r *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
if !field.Empty() {
return nil, errors.New("field selectors are not supported on images")
}
return r.store.WatchPredicate(ctx, image.MatchImage(label, field), resourceVersion)
}
// Get gets a specific image specified by its ID.
func (r *REST) Get(ctx kapi.Context, name string) (runtime.Object, error) {
return r.store.Get(ctx, name)
}
// Create creates an image based on a specification.
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
return r.store.Create(ctx, obj)
}
// Delete deletes an existing image specified by its ID.
func (r *REST) Delete(ctx kapi.Context, name string, options *kapi.DeleteOptions) (runtime.Object, error) {
return r.store.Delete(ctx, name, options)
}