forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builds.go
98 lines (85 loc) · 3.26 KB
/
builds.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
package client
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
buildapi "github.com/openshift/origin/pkg/build/api"
)
// BuildsNamespacer has methods to work with Build resources in a namespace
type BuildsNamespacer interface {
Builds(namespace string) BuildInterface
}
// BuildInterface exposes methods on Build resources.
type BuildInterface interface {
List(label labels.Selector, field fields.Selector) (*buildapi.BuildList, error)
Get(name string) (*buildapi.Build, error)
Create(build *buildapi.Build) (*buildapi.Build, error)
Update(build *buildapi.Build) (*buildapi.Build, error)
Delete(name string) error
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
Clone(request *buildapi.BuildRequest) (*buildapi.Build, error)
}
// builds implements BuildsNamespacer interface
type builds struct {
r *Client
ns string
}
// newBuilds returns a builds
func newBuilds(c *Client, namespace string) *builds {
return &builds{
r: c,
ns: namespace,
}
}
// List returns a list of builds that match the label and field selectors.
func (c *builds) List(label labels.Selector, field fields.Selector) (result *buildapi.BuildList, err error) {
result = &buildapi.BuildList{}
err = c.r.Get().
Namespace(c.ns).
Resource("builds").
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return
}
// Get returns information about a particular build and error if one occurs.
func (c *builds) Get(name string) (result *buildapi.Build, err error) {
result = &buildapi.Build{}
err = c.r.Get().Namespace(c.ns).Resource("builds").Name(name).Do().Into(result)
return
}
// Create creates new build. Returns the server's representation of the build and error if one occurs.
func (c *builds) Create(build *buildapi.Build) (result *buildapi.Build, err error) {
result = &buildapi.Build{}
err = c.r.Post().Namespace(c.ns).Resource("builds").Body(build).Do().Into(result)
return
}
// Update updates the build on server. Returns the server's representation of the build and error if one occurs.
func (c *builds) Update(build *buildapi.Build) (result *buildapi.Build, err error) {
result = &buildapi.Build{}
err = c.r.Put().Namespace(c.ns).Resource("builds").Name(build.Name).Body(build).Do().Into(result)
return
}
// Delete deletes a build, returns error if one occurs.
func (c *builds) Delete(name string) (err error) {
err = c.r.Delete().Namespace(c.ns).Resource("builds").Name(name).Do().Error()
return
}
// Watch returns a watch.Interface that watches the requested builds
func (c *builds) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("builds").
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Watch()
}
// Clone creates a clone of a build returning new object or an error
func (c *builds) Clone(request *buildapi.BuildRequest) (result *buildapi.Build, err error) {
result = &buildapi.Build{}
err = c.r.Post().Namespace(c.ns).Resource("builds").Name(request.Name).SubResource("clone").Body(request).Do().Into(result)
return
}