forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
94 lines (79 loc) · 1.99 KB
/
build.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
package test
import (
"sync"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
buildapi "github.com/openshift/origin/pkg/build/api"
)
type BuildRegistry struct {
Err error
Builds *buildapi.BuildList
Build *buildapi.Build
DeletedBuildID string
sync.Mutex
}
func (r *BuildRegistry) ListBuilds(ctx kapi.Context, options *kapi.ListOptions) (*buildapi.BuildList, error) {
r.Lock()
defer r.Unlock()
return r.Builds, r.Err
}
func (r *BuildRegistry) GetBuild(ctx kapi.Context, id string) (*buildapi.Build, error) {
r.Lock()
defer r.Unlock()
return r.Build, r.Err
}
func (r *BuildRegistry) CreateBuild(ctx kapi.Context, build *buildapi.Build) error {
r.Lock()
defer r.Unlock()
r.Build = build
return r.Err
}
func (r *BuildRegistry) UpdateBuild(ctx kapi.Context, build *buildapi.Build) error {
r.Lock()
defer r.Unlock()
r.Build = build
return r.Err
}
func (r *BuildRegistry) DeleteBuild(ctx kapi.Context, id string) error {
r.Lock()
defer r.Unlock()
r.DeletedBuildID = id
r.Build = nil
return r.Err
}
func (r *BuildRegistry) WatchBuilds(ctx kapi.Context, options *kapi.ListOptions) (watch.Interface, error) {
return nil, r.Err
}
type BuildStorage struct {
Err error
Build *buildapi.Build
Builds *buildapi.BuildList
sync.Mutex
}
func (r *BuildStorage) Get(ctx kapi.Context, id string) (runtime.Object, error) {
r.Lock()
defer r.Unlock()
// TODO: Use the list of builds in all of the rest registry calls
if r.Builds != nil {
for _, build := range r.Builds.Items {
if build.Name == id {
return &build, r.Err
}
}
}
return r.Build, r.Err
}
type BuildStorageWithOptions struct {
Err error
Build *buildapi.Build
sync.Mutex
}
func (r *BuildStorageWithOptions) NewGetOptions() (runtime.Object, bool, string) {
return nil, false, ""
}
func (r *BuildStorageWithOptions) Get(ctx kapi.Context, id string, opts runtime.Object) (runtime.Object, error) {
r.Lock()
defer r.Unlock()
return r.Build, r.Err
}