-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
etcd.go
108 lines (89 loc) · 3.77 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
package etcd
import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/generic/registry"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
"github.com/openshift/origin/pkg/authorization/registry/subjectaccessreview"
imageadmission "github.com/openshift/origin/pkg/image/admission"
"github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/image/registry/imagestream"
"github.com/openshift/origin/pkg/util/restoptions"
)
// REST implements a RESTStorage for image streams against etcd.
type REST struct {
*registry.Store
subjectAccessReviewRegistry subjectaccessreview.Registry
}
// NewREST returns a new REST.
func NewREST(optsGetter restoptions.Getter, defaultRegistry api.DefaultRegistry, subjectAccessReviewRegistry subjectaccessreview.Registry, limitVerifier imageadmission.LimitVerifier) (*REST, *StatusREST, *InternalREST, error) {
store := registry.Store{
NewFunc: func() runtime.Object { return &api.ImageStream{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageStreamList{} },
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.ImageStream).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
return imagestream.Matcher(label, field)
},
QualifiedResource: api.Resource("imagestreams"),
ReturnDeletedObject: false,
}
rest := &REST{
Store: &store,
subjectAccessReviewRegistry: subjectAccessReviewRegistry,
}
// strategy must be able to load image streams across namespaces during tag verification
strategy := imagestream.NewStrategy(defaultRegistry, subjectAccessReviewRegistry, limitVerifier, rest)
store.CreateStrategy = strategy
store.UpdateStrategy = strategy
store.Decorator = strategy.Decorate
if err := restoptions.ApplyOptions(optsGetter, &store, true, storage.NoTriggerPublisher); err != nil {
return nil, nil, nil, err
}
statusStrategy := imagestream.NewStatusStrategy(strategy)
statusStore := store
statusStore.Decorator = nil
statusStore.CreateStrategy = nil
statusStore.UpdateStrategy = statusStrategy
statusREST := &StatusREST{store: &statusStore}
internalStore := store
internalStrategy := imagestream.NewInternalStrategy(strategy)
internalStore.Decorator = nil
internalStore.CreateStrategy = internalStrategy
internalStore.UpdateStrategy = internalStrategy
internalREST := &InternalREST{store: &internalStore}
return rest, statusREST, internalREST, nil
}
// StatusREST implements the REST endpoint for changing the status of an image stream.
type StatusREST struct {
store *registry.Store
}
func (r *StatusREST) New() runtime.Object {
return &api.ImageStream{}
}
// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx kapi.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo)
}
// InternalREST implements the REST endpoint for changing both the spec and status of an image stream.
type InternalREST struct {
store *registry.Store
}
func (r *InternalREST) New() runtime.Object {
return &api.ImageStream{}
}
// Create alters both the spec and status of the object.
func (r *InternalREST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
return r.store.Create(ctx, obj)
}
// Update alters both the spec and status of the object.
func (r *InternalREST) Update(ctx kapi.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo)
}