forked from projectatomic/atomic-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
93 lines (79 loc) · 3.54 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
package imagerepository
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"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"
)
// Registry is an interface for things that know how to store ImageRepository objects.
type Registry interface {
// ListImageRepositories obtains a list of image repositories that match a selector.
ListImageRepositories(ctx kapi.Context, selector labels.Selector) (*api.ImageRepositoryList, error)
// GetImageRepository retrieves a specific image repository.
GetImageRepository(ctx kapi.Context, id string) (*api.ImageRepository, error)
// CreateImageRepository creates a new image repository.
CreateImageRepository(ctx kapi.Context, repo *api.ImageRepository) error
// UpdateImageRepository updates an image repository.
UpdateImageRepository(ctx kapi.Context, repo *api.ImageRepository) error
// UpdateImageRepository updates an image repository's status.
UpdateImageRepositoryStatus(ctx kapi.Context, repo *api.ImageRepository) error
// DeleteImageRepository deletes an image repository.
DeleteImageRepository(ctx kapi.Context, id string) error
// WatchImageRepositories watches for new/changed/deleted image repositories.
WatchImageRepositories(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
}
// Storage is an interface for a standard REST Storage backend
type Storage interface {
apiserver.RESTGracefulDeleter
apiserver.RESTLister
apiserver.RESTGetter
apiserver.ResourceWatcher
Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error)
Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error)
}
// storage puts strong typing around storage calls
type storage struct {
Storage
status apiserver.RESTUpdater
}
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
// types will panic.
func NewRegistry(s Storage, status apiserver.RESTUpdater) Registry {
return &storage{s, status}
}
func (s *storage) ListImageRepositories(ctx kapi.Context, label labels.Selector) (*api.ImageRepositoryList, error) {
obj, err := s.List(ctx, label, fields.Everything())
if err != nil {
return nil, err
}
return obj.(*api.ImageRepositoryList), nil
}
func (s *storage) GetImageRepository(ctx kapi.Context, imageRepositoryID string) (*api.ImageRepository, error) {
obj, err := s.Get(ctx, imageRepositoryID)
if err != nil {
return nil, err
}
return obj.(*api.ImageRepository), nil
}
func (s *storage) CreateImageRepository(ctx kapi.Context, imageRepository *api.ImageRepository) error {
_, err := s.Create(ctx, imageRepository)
return err
}
func (s *storage) UpdateImageRepository(ctx kapi.Context, imageRepository *api.ImageRepository) error {
_, _, err := s.Update(ctx, imageRepository)
return err
}
func (s *storage) UpdateImageRepositoryStatus(ctx kapi.Context, imageRepository *api.ImageRepository) error {
_, _, err := s.status.Update(ctx, imageRepository)
return err
}
func (s *storage) DeleteImageRepository(ctx kapi.Context, imageRepositoryID string) error {
_, err := s.Delete(ctx, imageRepositoryID, nil)
return err
}
func (s *storage) WatchImageRepositories(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return s.Watch(ctx, label, field, resourceVersion)
}