nodes.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. Copyright 2014 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/watch"
  17. )
  18. type NodesInterface interface {
  19. Nodes() NodeInterface
  20. }
  21. type NodeInterface interface {
  22. Get(name string) (result *api.Node, err error)
  23. Create(node *api.Node) (*api.Node, error)
  24. List(opts api.ListOptions) (*api.NodeList, error)
  25. Delete(name string) error
  26. DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
  27. Update(*api.Node) (*api.Node, error)
  28. UpdateStatus(*api.Node) (*api.Node, error)
  29. Watch(opts api.ListOptions) (watch.Interface, error)
  30. }
  31. // nodes implements NodesInterface
  32. type nodes struct {
  33. r *Client
  34. }
  35. // newNodes returns a nodes object.
  36. func newNodes(c *Client) *nodes {
  37. return &nodes{c}
  38. }
  39. // resourceName returns node's URL resource name.
  40. func (c *nodes) resourceName() string {
  41. return "nodes"
  42. }
  43. // Create creates a new node.
  44. func (c *nodes) Create(node *api.Node) (*api.Node, error) {
  45. result := &api.Node{}
  46. err := c.r.Post().Resource(c.resourceName()).Body(node).Do().Into(result)
  47. return result, err
  48. }
  49. // List takes a selector, and returns the list of nodes that match that selector in the cluster.
  50. func (c *nodes) List(opts api.ListOptions) (*api.NodeList, error) {
  51. result := &api.NodeList{}
  52. err := c.r.Get().Resource(c.resourceName()).VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  53. return result, err
  54. }
  55. // Get gets an existing node.
  56. func (c *nodes) Get(name string) (*api.Node, error) {
  57. result := &api.Node{}
  58. err := c.r.Get().Resource(c.resourceName()).Name(name).Do().Into(result)
  59. return result, err
  60. }
  61. // Delete deletes an existing node.
  62. func (c *nodes) Delete(name string) error {
  63. return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error()
  64. }
  65. // DeleteCollection deletes a collection of nodes.
  66. func (c *nodes) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
  67. return c.r.Delete().
  68. Resource(c.resourceName()).
  69. VersionedParams(&listOptions, api.ParameterCodec).
  70. Body(options).
  71. Do().
  72. Error()
  73. }
  74. // Update updates an existing node.
  75. func (c *nodes) Update(node *api.Node) (*api.Node, error) {
  76. result := &api.Node{}
  77. err := c.r.Put().Resource(c.resourceName()).Name(node.Name).Body(node).Do().Into(result)
  78. return result, err
  79. }
  80. func (c *nodes) UpdateStatus(node *api.Node) (*api.Node, error) {
  81. result := &api.Node{}
  82. err := c.r.Put().Resource(c.resourceName()).Name(node.Name).SubResource("status").Body(node).Do().Into(result)
  83. return result, err
  84. }
  85. // Watch returns a watch.Interface that watches the requested nodes.
  86. func (c *nodes) Watch(opts api.ListOptions) (watch.Interface, error) {
  87. return c.r.Get().
  88. Prefix("watch").
  89. Namespace(api.NamespaceAll).
  90. Resource(c.resourceName()).
  91. VersionedParams(&opts, api.ParameterCodec).
  92. Watch()
  93. }