forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
etcd.go
128 lines (104 loc) · 4.33 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package etcd
import (
"github.com/openshift/origin/pkg/authorization/registry/subjectaccessreview"
"github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/image/registry/imagestream"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
etcdgeneric "k8s.io/kubernetes/pkg/registry/generic/etcd"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/watch"
)
// REST implements a RESTStorage for image streams against etcd.
type REST struct {
store *etcdgeneric.Etcd
subjectAccessReviewRegistry subjectaccessreview.Registry
}
// NewREST returns a new REST.
func NewREST(s storage.Interface, defaultRegistry imagestream.DefaultRegistry, subjectAccessReviewRegistry subjectaccessreview.Registry) (*REST, *StatusREST, *InternalREST) {
prefix := "/imagestreams"
store := etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ImageStream{} },
NewListFunc: func() runtime.Object { return &api.ImageStreamList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return etcdgeneric.NamespaceKeyFunc(ctx, prefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.ImageStream).Name, nil
},
EndpointName: "imageStream",
ReturnDeletedObject: false,
Storage: s,
}
strategy := imagestream.NewStrategy(defaultRegistry, subjectAccessReviewRegistry)
rest := &REST{subjectAccessReviewRegistry: subjectAccessReviewRegistry}
strategy.ImageStreamGetter = rest
statusStore := store
statusStore.UpdateStrategy = imagestream.NewStatusStrategy(strategy)
internalStore := store
internalStore.UpdateStrategy = imagestream.NewInternalStrategy(strategy)
store.CreateStrategy = strategy
store.UpdateStrategy = strategy
store.Decorator = strategy.Decorate
rest.store = &store
return rest, &StatusREST{store: &statusStore}, &InternalREST{store: &internalStore}
}
// 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 image streams 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, imagestream.MatchImageStream(label, field))
}
// Watch begins watching for new, changed, or deleted image streams.
func (r *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return r.store.WatchPredicate(ctx, imagestream.MatchImageStream(label, field), resourceVersion)
}
// Get gets a specific image stream specified by its ID.
func (r *REST) Get(ctx kapi.Context, name string) (runtime.Object, error) {
return r.store.Get(ctx, name)
}
// Create creates a image stream based on a specification.
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
return r.store.Create(ctx, obj)
}
// Update changes a image stream specification.
func (r *REST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
return r.store.Update(ctx, obj)
}
// Delete deletes an existing image stream 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)
}
// StatusREST implements the REST endpoint for changing the status of an image stream.
type StatusREST struct {
store *etcdgeneric.Etcd
}
func (r *StatusREST) New() runtime.Object {
return &api.ImageStream{}
}
// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
return r.store.Update(ctx, obj)
}
// InternalREST implements the REST endpoint for changing both the spec and status of an image stream.
type InternalREST struct {
store *etcdgeneric.Etcd
}
func (r *InternalREST) New() runtime.Object {
return &api.ImageStream{}
}
// Update alters both the spec and status of the object.
func (r *InternalREST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
return r.store.Update(ctx, obj)
}