forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaults.go
36 lines (29 loc) · 956 Bytes
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package v1
import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime"
internal "github.com/openshift/origin/pkg/authorization/api"
)
var oldAllowAllPolicyRule = PolicyRule{APIGroups: nil, Verbs: []string{internal.VerbAll}, Resources: []string{internal.ResourceAll}}
func SetDefaults_PolicyRule(obj *PolicyRule) {
if obj == nil {
return
}
// this seems really strange, but semantic equality checks most of what we want, but nil == {}
// this is ok for the restof the fields, but not APIGroups
if kapi.Semantic.Equalities.DeepEqual(oldAllowAllPolicyRule, *obj) && obj.APIGroups == nil {
obj.APIGroups = []string{internal.APIGroupAll}
}
// if no groups are found, then we assume ""
if len(obj.Resources) > 0 && len(obj.APIGroups) == 0 {
obj.APIGroups = []string{""}
}
}
func addDefaultingFuncs(scheme *runtime.Scheme) {
err := scheme.AddDefaultingFuncs(
SetDefaults_PolicyRule,
)
if err != nil {
panic(err)
}
}