-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
builds.go
113 lines (98 loc) · 4.15 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package client
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
kapi "k8s.io/kubernetes/pkg/api"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
)
// 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(opts metav1.ListOptions) (*buildapi.BuildList, error)
Get(name string, options metav1.GetOptions) (*buildapi.Build, error)
Create(build *buildapi.Build) (*buildapi.Build, error)
Update(build *buildapi.Build) (*buildapi.Build, error)
Delete(name string) error
Watch(opts metav1.ListOptions) (watch.Interface, error)
Clone(request *buildapi.BuildRequest) (*buildapi.Build, error)
UpdateDetails(build *buildapi.Build) (*buildapi.Build, error)
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*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(opts metav1.ListOptions) (*buildapi.BuildList, error) {
result := &buildapi.BuildList{}
err := c.r.Get().
Namespace(c.ns).
Resource("builds").
VersionedParams(&opts, kapi.ParameterCodec).
Do().
Into(result)
return result, err
}
// Get returns information about a particular build and error if one occurs.
func (c *builds) Get(name string, options metav1.GetOptions) (*buildapi.Build, error) {
result := &buildapi.Build{}
err := c.r.Get().Namespace(c.ns).Resource("builds").Name(name).VersionedParams(&options, kapi.ParameterCodec).Do().Into(result)
return result, err
}
// Create creates new build. Returns the server's representation of the build and error if one occurs.
func (c *builds) Create(build *buildapi.Build) (*buildapi.Build, error) {
result := &buildapi.Build{}
err := c.r.Post().Namespace(c.ns).Resource("builds").Body(build).Do().Into(result)
return result, err
}
// 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) (*buildapi.Build, error) {
result := &buildapi.Build{}
err := c.r.Put().Namespace(c.ns).Resource("builds").Name(build.Name).Body(build).Do().Into(result)
return result, err
}
// Delete deletes a build, returns error if one occurs.
func (c *builds) Delete(name string) error {
return c.r.Delete().Namespace(c.ns).Resource("builds").Name(name).Do().Error()
}
// Watch returns a watch.Interface that watches the requested builds
func (c *builds) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("builds").
VersionedParams(&opts, kapi.ParameterCodec).
Watch()
}
// Clone creates a clone of a build returning new object or an error
func (c *builds) Clone(request *buildapi.BuildRequest) (*buildapi.Build, error) {
result := &buildapi.Build{}
err := c.r.Post().Namespace(c.ns).Resource("builds").Name(request.Name).SubResource("clone").Body(request).Do().Into(result)
return result, err
}
// UpdateDetails updates the build details for a given build.
// Currently only the Spec.Revision is allowed to be updated.
// Returns the server's representation of the build and error if one occurs.
func (c *builds) UpdateDetails(build *buildapi.Build) (*buildapi.Build, error) {
result := &buildapi.Build{}
err := c.r.Put().Namespace(c.ns).Resource("builds").Name(build.Name).SubResource("details").Body(build).Do().Into(result)
return result, err
}
// Patch takes the partial representation of a build and updates it.
func (c *builds) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*buildapi.Build, error) {
result := &buildapi.Build{}
err := c.r.Patch(types.StrategicMergePatchType).Namespace(c.ns).Resource("builds").SubResource(subresources...).Name(name).Body(data).Do().Into(result)
return result, err
}