forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
registry.go
117 lines (102 loc) · 4.39 KB
/
registry.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
package imagestream
import (
metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
kapi "k8s.io/kubernetes/pkg/api"
"github.com/openshift/origin/pkg/image/api"
)
// Registry is an interface for things that know how to store ImageStream objects.
type Registry interface {
// ListImageStreams obtains a list of image streams that match a selector.
ListImageStreams(ctx apirequest.Context, options *metainternal.ListOptions) (*api.ImageStreamList, error)
// GetImageStream retrieves a specific image stream.
GetImageStream(ctx apirequest.Context, id string, options *metav1.GetOptions) (*api.ImageStream, error)
// CreateImageStream creates a new image stream.
CreateImageStream(ctx apirequest.Context, repo *api.ImageStream) (*api.ImageStream, error)
// UpdateImageStream updates an image stream.
UpdateImageStream(ctx apirequest.Context, repo *api.ImageStream) (*api.ImageStream, error)
// UpdateImageStreamSpec updates an image stream's spec.
UpdateImageStreamSpec(ctx apirequest.Context, repo *api.ImageStream) (*api.ImageStream, error)
// UpdateImageStreamStatus updates an image stream's status.
UpdateImageStreamStatus(ctx apirequest.Context, repo *api.ImageStream) (*api.ImageStream, error)
// DeleteImageStream deletes an image stream.
DeleteImageStream(ctx apirequest.Context, id string) (*metav1.Status, error)
// WatchImageStreams watches for new/changed/deleted image streams.
WatchImageStreams(ctx apirequest.Context, options *metainternal.ListOptions) (watch.Interface, error)
}
// Storage is an interface for a standard REST Storage backend
type Storage interface {
rest.GracefulDeleter
rest.Lister
rest.Getter
rest.Watcher
Create(ctx apirequest.Context, obj runtime.Object) (runtime.Object, error)
Update(ctx apirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error)
}
// storage puts strong typing around storage calls
type storage struct {
Storage
status rest.Updater
internal rest.Updater
}
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
// types will panic.
func NewRegistry(s Storage, status, internal rest.Updater) Registry {
return &storage{Storage: s, status: status, internal: internal}
}
func (s *storage) ListImageStreams(ctx apirequest.Context, options *metainternal.ListOptions) (*api.ImageStreamList, error) {
obj, err := s.List(ctx, options)
if err != nil {
return nil, err
}
return obj.(*api.ImageStreamList), nil
}
func (s *storage) GetImageStream(ctx apirequest.Context, imageStreamID string, options *metav1.GetOptions) (*api.ImageStream, error) {
obj, err := s.Get(ctx, imageStreamID, options)
if err != nil {
return nil, err
}
return obj.(*api.ImageStream), nil
}
func (s *storage) CreateImageStream(ctx apirequest.Context, imageStream *api.ImageStream) (*api.ImageStream, error) {
obj, err := s.Create(ctx, imageStream)
if err != nil {
return nil, err
}
return obj.(*api.ImageStream), nil
}
func (s *storage) UpdateImageStream(ctx apirequest.Context, imageStream *api.ImageStream) (*api.ImageStream, error) {
obj, _, err := s.internal.Update(ctx, imageStream.Name, rest.DefaultUpdatedObjectInfo(imageStream, kapi.Scheme))
if err != nil {
return nil, err
}
return obj.(*api.ImageStream), nil
}
func (s *storage) UpdateImageStreamSpec(ctx apirequest.Context, imageStream *api.ImageStream) (*api.ImageStream, error) {
obj, _, err := s.Update(ctx, imageStream.Name, rest.DefaultUpdatedObjectInfo(imageStream, kapi.Scheme))
if err != nil {
return nil, err
}
return obj.(*api.ImageStream), nil
}
func (s *storage) UpdateImageStreamStatus(ctx apirequest.Context, imageStream *api.ImageStream) (*api.ImageStream, error) {
obj, _, err := s.status.Update(ctx, imageStream.Name, rest.DefaultUpdatedObjectInfo(imageStream, kapi.Scheme))
if err != nil {
return nil, err
}
return obj.(*api.ImageStream), nil
}
func (s *storage) DeleteImageStream(ctx apirequest.Context, imageStreamID string) (*metav1.Status, error) {
obj, _, err := s.Delete(ctx, imageStreamID, nil)
if err != nil {
return nil, err
}
return obj.(*metav1.Status), nil
}
func (s *storage) WatchImageStreams(ctx apirequest.Context, options *metainternal.ListOptions) (watch.Interface, error) {
return s.Watch(ctx, options)
}