clusterroles.go 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Copyright 2016 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/rbac"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // ClusterRoles has methods to work with ClusterRole resources in a namespace
  20. type ClusterRoles interface {
  21. ClusterRoles() ClusterRoleInterface
  22. }
  23. // ClusterRoleInterface has methods to work with ClusterRole resources.
  24. type ClusterRoleInterface interface {
  25. List(opts api.ListOptions) (*rbac.ClusterRoleList, error)
  26. Get(name string) (*rbac.ClusterRole, error)
  27. Delete(name string, options *api.DeleteOptions) error
  28. Create(clusterRole *rbac.ClusterRole) (*rbac.ClusterRole, error)
  29. Update(clusterRole *rbac.ClusterRole) (*rbac.ClusterRole, error)
  30. Watch(opts api.ListOptions) (watch.Interface, error)
  31. }
  32. // clusterRoles implements ClusterRolesNamespacer interface
  33. type clusterRoles struct {
  34. client *RbacClient
  35. }
  36. // newClusterRoles returns a clusterRoles
  37. func newClusterRoles(c *RbacClient) *clusterRoles {
  38. return &clusterRoles{
  39. client: c,
  40. }
  41. }
  42. // List takes label and field selectors, and returns the list of clusterRoles that match those selectors.
  43. func (c *clusterRoles) List(opts api.ListOptions) (result *rbac.ClusterRoleList, err error) {
  44. result = &rbac.ClusterRoleList{}
  45. err = c.client.Get().Resource("clusterroles").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  46. return
  47. }
  48. // Get takes the name of the clusterRole, and returns the corresponding ClusterRole object, and an error if it occurs
  49. func (c *clusterRoles) Get(name string) (result *rbac.ClusterRole, err error) {
  50. result = &rbac.ClusterRole{}
  51. err = c.client.Get().Resource("clusterroles").Name(name).Do().Into(result)
  52. return
  53. }
  54. // Delete takes the name of the clusterRole and deletes it. Returns an error if one occurs.
  55. func (c *clusterRoles) Delete(name string, options *api.DeleteOptions) error {
  56. return c.client.Delete().Resource("clusterroles").Name(name).Body(options).Do().Error()
  57. }
  58. // Create takes the representation of a clusterRole and creates it. Returns the server's representation of the clusterRole, and an error, if it occurs.
  59. func (c *clusterRoles) Create(clusterRole *rbac.ClusterRole) (result *rbac.ClusterRole, err error) {
  60. result = &rbac.ClusterRole{}
  61. err = c.client.Post().Resource("clusterroles").Body(clusterRole).Do().Into(result)
  62. return
  63. }
  64. // Update takes the representation of a clusterRole and updates it. Returns the server's representation of the clusterRole, and an error, if it occurs.
  65. func (c *clusterRoles) Update(clusterRole *rbac.ClusterRole) (result *rbac.ClusterRole, err error) {
  66. result = &rbac.ClusterRole{}
  67. err = c.client.Put().Resource("clusterroles").Name(clusterRole.Name).Body(clusterRole).Do().Into(result)
  68. return
  69. }
  70. // Watch returns a watch.Interface that watches the requested clusterRoles.
  71. func (c *clusterRoles) Watch(opts api.ListOptions) (watch.Interface, error) {
  72. return c.client.Get().
  73. Prefix("watch").
  74. Resource("clusterroles").
  75. VersionedParams(&opts, api.ParameterCodec).
  76. Watch()
  77. }