ingress.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // IngressNamespacer has methods to work with Ingress resources in a namespace
  20. type IngressNamespacer interface {
  21. Ingress(namespace string) IngressInterface
  22. }
  23. // IngressInterface exposes methods to work on Ingress resources.
  24. type IngressInterface interface {
  25. List(opts api.ListOptions) (*extensions.IngressList, error)
  26. Get(name string) (*extensions.Ingress, error)
  27. Create(ingress *extensions.Ingress) (*extensions.Ingress, error)
  28. Update(ingress *extensions.Ingress) (*extensions.Ingress, error)
  29. Delete(name string, options *api.DeleteOptions) error
  30. Watch(opts api.ListOptions) (watch.Interface, error)
  31. UpdateStatus(ingress *extensions.Ingress) (*extensions.Ingress, error)
  32. }
  33. // ingress implements IngressNamespacer interface
  34. type ingress struct {
  35. r *ExtensionsClient
  36. ns string
  37. }
  38. // newIngress returns a ingress
  39. func newIngress(c *ExtensionsClient, namespace string) *ingress {
  40. return &ingress{c, namespace}
  41. }
  42. // List returns a list of ingress that match the label and field selectors.
  43. func (c *ingress) List(opts api.ListOptions) (result *extensions.IngressList, err error) {
  44. result = &extensions.IngressList{}
  45. err = c.r.Get().Namespace(c.ns).Resource("ingresses").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  46. return
  47. }
  48. // Get returns information about a particular ingress.
  49. func (c *ingress) Get(name string) (result *extensions.Ingress, err error) {
  50. result = &extensions.Ingress{}
  51. err = c.r.Get().Namespace(c.ns).Resource("ingresses").Name(name).Do().Into(result)
  52. return
  53. }
  54. // Create creates a new ingress.
  55. func (c *ingress) Create(ingress *extensions.Ingress) (result *extensions.Ingress, err error) {
  56. result = &extensions.Ingress{}
  57. err = c.r.Post().Namespace(c.ns).Resource("ingresses").Body(ingress).Do().Into(result)
  58. return
  59. }
  60. // Update updates an existing ingress.
  61. func (c *ingress) Update(ingress *extensions.Ingress) (result *extensions.Ingress, err error) {
  62. result = &extensions.Ingress{}
  63. err = c.r.Put().Namespace(c.ns).Resource("ingresses").Name(ingress.Name).Body(ingress).Do().Into(result)
  64. return
  65. }
  66. // Delete deletes a ingress, returns error if one occurs.
  67. func (c *ingress) Delete(name string, options *api.DeleteOptions) (err error) {
  68. return c.r.Delete().Namespace(c.ns).Resource("ingresses").Name(name).Body(options).Do().Error()
  69. }
  70. // Watch returns a watch.Interface that watches the requested ingress.
  71. func (c *ingress) Watch(opts api.ListOptions) (watch.Interface, error) {
  72. return c.r.Get().
  73. Prefix("watch").
  74. Namespace(c.ns).
  75. Resource("ingresses").
  76. VersionedParams(&opts, api.ParameterCodec).
  77. Watch()
  78. }
  79. // UpdateStatus takes the name of the ingress and the new status. Returns the server's representation of the ingress, and an error, if it occurs.
  80. func (c *ingress) UpdateStatus(ingress *extensions.Ingress) (result *extensions.Ingress, err error) {
  81. result = &extensions.Ingress{}
  82. err = c.r.Put().Namespace(c.ns).Resource("ingresses").Name(ingress.Name).SubResource("status").Body(ingress).Do().Into(result)
  83. return
  84. }