defaults.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 v1
  14. import (
  15. rbacv1 "k8s.io/api/rbac/v1"
  16. "k8s.io/apimachinery/pkg/runtime"
  17. )
  18. func addDefaultingFuncs(scheme *runtime.Scheme) error {
  19. return RegisterDefaults(scheme)
  20. }
  21. func SetDefaults_ClusterRoleBinding(obj *rbacv1.ClusterRoleBinding) {
  22. if len(obj.RoleRef.APIGroup) == 0 {
  23. obj.RoleRef.APIGroup = GroupName
  24. }
  25. }
  26. func SetDefaults_RoleBinding(obj *rbacv1.RoleBinding) {
  27. if len(obj.RoleRef.APIGroup) == 0 {
  28. obj.RoleRef.APIGroup = GroupName
  29. }
  30. }
  31. func SetDefaults_Subject(obj *rbacv1.Subject) {
  32. if len(obj.APIGroup) == 0 {
  33. switch obj.Kind {
  34. case rbacv1.ServiceAccountKind:
  35. obj.APIGroup = ""
  36. case rbacv1.UserKind:
  37. obj.APIGroup = GroupName
  38. case rbacv1.GroupKind:
  39. obj.APIGroup = GroupName
  40. }
  41. }
  42. }