forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.go
90 lines (78 loc) · 3.04 KB
/
templates.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
package client
import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
templateapi "github.com/openshift/origin/pkg/template/api"
)
// TemplatesNamespacer has methods to work with Template resources in a namespace
type TemplatesNamespacer interface {
Templates(namespace string) TemplateInterface
}
// TemplateInterface exposes methods on Template resources.
type TemplateInterface interface {
List(label labels.Selector, field fields.Selector) (*templateapi.TemplateList, error)
Get(name string) (*templateapi.Template, error)
Create(template *templateapi.Template) (*templateapi.Template, error)
Update(template *templateapi.Template) (*templateapi.Template, error)
Delete(name string) error
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
}
// templates implements TemplatesNamespacer interface
type templates struct {
r *Client
ns string
}
// newTemplates returns a templates
func newTemplates(c *Client, namespace string) *templates {
return &templates{
r: c,
ns: namespace,
}
}
// List returns a list of templates that match the label and field selectors.
func (c *templates) List(label labels.Selector, field fields.Selector) (result *templateapi.TemplateList, err error) {
result = &templateapi.TemplateList{}
err = c.r.Get().
Namespace(c.ns).
Resource("templates").
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return
}
// Get returns information about a particular template and error if one occurs.
func (c *templates) Get(name string) (result *templateapi.Template, err error) {
result = &templateapi.Template{}
err = c.r.Get().Namespace(c.ns).Resource("templates").Name(name).Do().Into(result)
return
}
// Create creates new template. Returns the server's representation of the template and error if one occurs.
func (c *templates) Create(template *templateapi.Template) (result *templateapi.Template, err error) {
result = &templateapi.Template{}
err = c.r.Post().Namespace(c.ns).Resource("templates").Body(template).Do().Into(result)
return
}
// Update updates the template on server. Returns the server's representation of the template and error if one occurs.
func (c *templates) Update(template *templateapi.Template) (result *templateapi.Template, err error) {
result = &templateapi.Template{}
err = c.r.Put().Namespace(c.ns).Resource("templates").Name(template.Name).Body(template).Do().Into(result)
return
}
// Delete deletes a template, returns error if one occurs.
func (c *templates) Delete(name string) (err error) {
err = c.r.Delete().Namespace(c.ns).Resource("templates").Name(name).Do().Error()
return
}
// Watch returns a watch.Interface that watches the requested templates
func (c *templates) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("templates").
Param("resourceVersion", resourceVersion).
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Watch()
}