forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
137 lines (114 loc) · 4.15 KB
/
rest.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
129
130
131
132
133
134
135
136
137
package imagerepository
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/image/registry/imagestream"
)
type REST struct {
imageStreamRegistry imagestream.Registry
}
func NewREST(isr imagestream.Registry) (*REST, *StatusREST) {
return &REST{imageStreamRegistry: isr}, &StatusREST{imageStreamRegistry: isr}
}
// New returns a new object
func (r *REST) New() runtime.Object {
return &api.ImageRepository{}
}
// NewList returns a new list object
func (r *REST) NewList() runtime.Object {
return &api.ImageRepositoryList{}
}
// List obtains a list of image repositories with labels that match selector.
func (r *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
imageStreamList, err := r.imageStreamRegistry.ListImageStreams(ctx, label)
if err != nil {
return nil, err
}
imageRepoList := api.ImageRepositoryList{}
if err := kapi.Scheme.Convert(imageStreamList, &imageRepoList); err != nil {
return nil, err
}
return &imageRepoList, nil
}
// Watch begins watching for new, changed, or deleted image repositories.
func (r *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return r.imageStreamRegistry.WatchImageStreams(ctx, label, field, resourceVersion)
}
// Get gets a specific image repository specified by its ID.
func (r *REST) Get(ctx kapi.Context, name string) (runtime.Object, error) {
stream, err := r.imageStreamRegistry.GetImageStream(ctx, name)
if err != nil {
return nil, err
}
repo := api.ImageRepository{}
if err := kapi.Scheme.Convert(stream, &repo); err != nil {
return nil, err
}
return &repo, nil
}
// Create creates a image repository based on a specification.
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
repo := obj.(*api.ImageRepository)
var stream api.ImageStream
if err := kapi.Scheme.Convert(repo, &stream); err != nil {
return nil, err
}
createdStream, err := r.imageStreamRegistry.CreateImageStream(ctx, &stream)
if err != nil {
return nil, err
}
createdRepo := api.ImageRepository{}
if err := kapi.Scheme.Convert(createdStream, &createdRepo); err != nil {
return nil, err
}
return &createdRepo, nil
}
// Update changes a image repository specification.
func (r *REST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
repo := obj.(*api.ImageRepository)
var stream api.ImageStream
if err := kapi.Scheme.Convert(repo, &stream); err != nil {
return nil, false, err
}
updatedStream, err := r.imageStreamRegistry.UpdateImageStream(ctx, &stream)
if err != nil {
return nil, false, err
}
updatedRepo := api.ImageRepository{}
if err := kapi.Scheme.Convert(updatedStream, &updatedRepo); err != nil {
return nil, false, err
}
return &updatedRepo, false, err
}
// Delete deletes an existing image repository specified by its ID.
func (r *REST) Delete(ctx kapi.Context, name string, options *kapi.DeleteOptions) (runtime.Object, error) {
return r.imageStreamRegistry.DeleteImageStream(ctx, name)
}
// StatusREST implements the REST endpoint for changing the status of an image repository.
type StatusREST struct {
imageStreamRegistry imagestream.Registry
}
func (r *StatusREST) New() runtime.Object {
return &api.ImageRepository{}
}
// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
repo := obj.(*api.ImageRepository)
var stream api.ImageStream
if err := kapi.Scheme.Convert(&repo, &stream); err != nil {
return nil, false, err
}
updatedStream, err := r.imageStreamRegistry.UpdateImageStreamStatus(ctx, &stream)
if err != nil {
return nil, false, err
}
updatedRepo := api.ImageRepository{}
if err := kapi.Scheme.Convert(updatedStream, &updatedRepo); err != nil {
return nil, false, err
}
return &updatedRepo, false, err
}