forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployments.go
88 lines (76 loc) · 2.92 KB
/
deployments.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
package client
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
deployapi "github.com/openshift/origin/pkg/deploy/api"
)
// DeploymentsNamespacer has methods to work with Deployment resources in a namespace
type DeploymentsNamespacer interface {
Deployments(namespace string) DeploymentInterface
}
// DeploymentInterface contains methods for working with Deployments
type DeploymentInterface interface {
List(label, field labels.Selector) (*deployapi.DeploymentList, error)
Get(name string) (*deployapi.Deployment, error)
Create(deployment *deployapi.Deployment) (*deployapi.Deployment, error)
Update(deployment *deployapi.Deployment) (*deployapi.Deployment, error)
Delete(name string) error
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
}
// deployments implements DeploymentsNamespacer interface
type deployments struct {
r *Client
ns string
}
// newDeployments returns a deployments
func newDeployments(c *Client, namespace string) *deployments {
return &deployments{
r: c,
ns: namespace,
}
}
// List takes a label and field selector, and returns the list of deployments that match that selectors
func (c *deployments) List(label, field labels.Selector) (result *deployapi.DeploymentList, err error) {
result = &deployapi.DeploymentList{}
err = c.r.Get().
Namespace(c.ns).
Resource("deployments").
SelectorParam("labels", label).
SelectorParam("fields", field).
Do().
Into(result)
return
}
// Get returns information about a particular deployment
func (c *deployments) Get(name string) (result *deployapi.Deployment, err error) {
result = &deployapi.Deployment{}
err = c.r.Get().Namespace(c.ns).Resource("deployments").Name(name).Do().Into(result)
return
}
// Create creates a new deployment
func (c *deployments) Create(deployment *deployapi.Deployment) (result *deployapi.Deployment, err error) {
result = &deployapi.Deployment{}
err = c.r.Post().Namespace(c.ns).Resource("deployments").Body(deployment).Do().Into(result)
return
}
// Update updates an existing deployment
func (c *deployments) Update(deployment *deployapi.Deployment) (result *deployapi.Deployment, err error) {
result = &deployapi.Deployment{}
err = c.r.Put().Namespace(c.ns).Resource("deployments").Name(deployment.Name).Body(deployment).Do().Into(result)
return
}
// Delete deletes an existing replication deployment.
func (c *deployments) Delete(name string) error {
return c.r.Delete().Namespace(c.ns).Resource("deployments").Name(name).Do().Error()
}
// Watch returns a watch.Interface that watches the requested deployments.
func (c *deployments) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("deployments").
Param("resourceVersion", resourceVersion).
SelectorParam("labels", label).
SelectorParam("fields", field).
Watch()
}