clusterrole_interfaces.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Copyright 2017 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 reconciliation
  14. import (
  15. "context"
  16. rbacv1 "k8s.io/api/rbac/v1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. "k8s.io/apimachinery/pkg/runtime"
  19. rbacv1client "k8s.io/client-go/kubernetes/typed/rbac/v1"
  20. )
  21. // +k8s:deepcopy-gen=true
  22. // +k8s:deepcopy-gen:interfaces=k8s.io/kubernetes/pkg/registry/rbac/reconciliation.RuleOwner
  23. // +k8s:deepcopy-gen:nonpointer-interfaces=true
  24. type ClusterRoleRuleOwner struct {
  25. ClusterRole *rbacv1.ClusterRole
  26. }
  27. func (o ClusterRoleRuleOwner) GetObject() runtime.Object {
  28. return o.ClusterRole
  29. }
  30. func (o ClusterRoleRuleOwner) GetNamespace() string {
  31. return o.ClusterRole.Namespace
  32. }
  33. func (o ClusterRoleRuleOwner) GetName() string {
  34. return o.ClusterRole.Name
  35. }
  36. func (o ClusterRoleRuleOwner) GetLabels() map[string]string {
  37. return o.ClusterRole.Labels
  38. }
  39. func (o ClusterRoleRuleOwner) SetLabels(in map[string]string) {
  40. o.ClusterRole.Labels = in
  41. }
  42. func (o ClusterRoleRuleOwner) GetAnnotations() map[string]string {
  43. return o.ClusterRole.Annotations
  44. }
  45. func (o ClusterRoleRuleOwner) SetAnnotations(in map[string]string) {
  46. o.ClusterRole.Annotations = in
  47. }
  48. func (o ClusterRoleRuleOwner) GetRules() []rbacv1.PolicyRule {
  49. return o.ClusterRole.Rules
  50. }
  51. func (o ClusterRoleRuleOwner) SetRules(in []rbacv1.PolicyRule) {
  52. o.ClusterRole.Rules = in
  53. }
  54. func (o ClusterRoleRuleOwner) GetAggregationRule() *rbacv1.AggregationRule {
  55. return o.ClusterRole.AggregationRule
  56. }
  57. func (o ClusterRoleRuleOwner) SetAggregationRule(in *rbacv1.AggregationRule) {
  58. o.ClusterRole.AggregationRule = in
  59. }
  60. type ClusterRoleModifier struct {
  61. Client rbacv1client.ClusterRoleInterface
  62. }
  63. func (c ClusterRoleModifier) Get(namespace, name string) (RuleOwner, error) {
  64. ret, err := c.Client.Get(context.TODO(), name, metav1.GetOptions{})
  65. if err != nil {
  66. return nil, err
  67. }
  68. return ClusterRoleRuleOwner{ClusterRole: ret}, err
  69. }
  70. func (c ClusterRoleModifier) Create(in RuleOwner) (RuleOwner, error) {
  71. ret, err := c.Client.Create(context.TODO(), in.(ClusterRoleRuleOwner).ClusterRole, metav1.CreateOptions{})
  72. if err != nil {
  73. return nil, err
  74. }
  75. return ClusterRoleRuleOwner{ClusterRole: ret}, err
  76. }
  77. func (c ClusterRoleModifier) Update(in RuleOwner) (RuleOwner, error) {
  78. ret, err := c.Client.Update(context.TODO(), in.(ClusterRoleRuleOwner).ClusterRole, metav1.UpdateOptions{})
  79. if err != nil {
  80. return nil, err
  81. }
  82. return ClusterRoleRuleOwner{ClusterRole: ret}, err
  83. }