1/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1alpha1
18
19import (
20	rbacv1alpha1 "k8s.io/api/rbac/v1alpha1"
21	"k8s.io/apimachinery/pkg/runtime"
22)
23
24func addDefaultingFuncs(scheme *runtime.Scheme) error {
25	return RegisterDefaults(scheme)
26}
27
28func SetDefaults_ClusterRoleBinding(obj *rbacv1alpha1.ClusterRoleBinding) {
29	if len(obj.RoleRef.APIGroup) == 0 {
30		obj.RoleRef.APIGroup = GroupName
31	}
32}
33func SetDefaults_RoleBinding(obj *rbacv1alpha1.RoleBinding) {
34	if len(obj.RoleRef.APIGroup) == 0 {
35		obj.RoleRef.APIGroup = GroupName
36	}
37}
38func SetDefaults_Subject(obj *rbacv1alpha1.Subject) {
39	if len(obj.APIVersion) == 0 {
40		switch obj.Kind {
41		case rbacv1alpha1.ServiceAccountKind:
42			obj.APIVersion = "v1"
43		case rbacv1alpha1.UserKind:
44			obj.APIVersion = SchemeGroupVersion.String()
45		case rbacv1alpha1.GroupKind:
46			obj.APIVersion = SchemeGroupVersion.String()
47		}
48	}
49}
50