deployment.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package unversioned
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/apis/extensions"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // DeploymentsNamespacer has methods to work with Deployment resources in a namespace
  20. type DeploymentsNamespacer interface {
  21. Deployments(namespace string) DeploymentInterface
  22. }
  23. // DeploymentInterface has methods to work with Deployment resources.
  24. type DeploymentInterface interface {
  25. List(opts api.ListOptions) (*extensions.DeploymentList, error)
  26. Get(name string) (*extensions.Deployment, error)
  27. Delete(name string, options *api.DeleteOptions) error
  28. Create(*extensions.Deployment) (*extensions.Deployment, error)
  29. Update(*extensions.Deployment) (*extensions.Deployment, error)
  30. UpdateStatus(*extensions.Deployment) (*extensions.Deployment, error)
  31. Watch(opts api.ListOptions) (watch.Interface, error)
  32. Rollback(*extensions.DeploymentRollback) error
  33. }
  34. // deployments implements DeploymentInterface
  35. type deployments struct {
  36. client *ExtensionsClient
  37. ns string
  38. }
  39. // Ensure statically that deployments implements DeploymentInterface.
  40. var _ DeploymentInterface = &deployments{}
  41. // newDeployments returns a Deployments
  42. func newDeployments(c *ExtensionsClient, namespace string) *deployments {
  43. return &deployments{
  44. client: c,
  45. ns: namespace,
  46. }
  47. }
  48. // List takes label and field selectors, and returns the list of Deployments that match those selectors.
  49. func (c *deployments) List(opts api.ListOptions) (result *extensions.DeploymentList, err error) {
  50. result = &extensions.DeploymentList{}
  51. err = c.client.Get().Namespace(c.ns).Resource("deployments").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  52. return
  53. }
  54. // Get takes name of the deployment, and returns the corresponding deployment object, and an error if there is any.
  55. func (c *deployments) Get(name string) (result *extensions.Deployment, err error) {
  56. result = &extensions.Deployment{}
  57. err = c.client.Get().Namespace(c.ns).Resource("deployments").Name(name).Do().Into(result)
  58. return
  59. }
  60. // Delete takes name of the deployment and deletes it. Returns an error if one occurs.
  61. func (c *deployments) Delete(name string, options *api.DeleteOptions) error {
  62. return c.client.Delete().Namespace(c.ns).Resource("deployments").Name(name).Body(options).Do().Error()
  63. }
  64. // Create takes the representation of a deployment and creates it. Returns the server's representation of the deployment, and an error, if there is any.
  65. func (c *deployments) Create(deployment *extensions.Deployment) (result *extensions.Deployment, err error) {
  66. result = &extensions.Deployment{}
  67. err = c.client.Post().Namespace(c.ns).Resource("deployments").Body(deployment).Do().Into(result)
  68. return
  69. }
  70. // Update takes the representation of a deployment and updates it. Returns the server's representation of the deployment, and an error, if there is any.
  71. func (c *deployments) Update(deployment *extensions.Deployment) (result *extensions.Deployment, err error) {
  72. result = &extensions.Deployment{}
  73. err = c.client.Put().Namespace(c.ns).Resource("deployments").Name(deployment.Name).Body(deployment).Do().Into(result)
  74. return
  75. }
  76. func (c *deployments) UpdateStatus(deployment *extensions.Deployment) (result *extensions.Deployment, err error) {
  77. result = &extensions.Deployment{}
  78. err = c.client.Put().Namespace(c.ns).Resource("deployments").Name(deployment.Name).SubResource("status").Body(deployment).Do().Into(result)
  79. return
  80. }
  81. // Watch returns a watch.Interface that watches the requested deployments.
  82. func (c *deployments) Watch(opts api.ListOptions) (watch.Interface, error) {
  83. return c.client.Get().
  84. Prefix("watch").
  85. Namespace(c.ns).
  86. Resource("deployments").
  87. VersionedParams(&opts, api.ParameterCodec).
  88. Watch()
  89. }
  90. // Rollback applied the provided DeploymentRollback to the named deployment in the current namespace.
  91. func (c *deployments) Rollback(deploymentRollback *extensions.DeploymentRollback) error {
  92. return c.client.Post().Namespace(c.ns).Resource("deployments").Name(deploymentRollback.Name).SubResource("rollback").Body(deploymentRollback).Do().Error()
  93. }