@@ -22,10 +22,11 @@ import (
22
22
"strings"
23
23
24
24
rbacv1 "k8s.io/api/rbac/v1"
25
+ "k8s.io/apimachinery/pkg/apis/meta/v1"
25
26
"k8s.io/gengo/types"
26
- "k8s.io/apimachinery/pkg/apis/meta/v1"
27
27
)
28
28
29
+ // parseRBAC populates the RBAC rules for each annotated type.
29
30
func (b * APIs ) parseRBAC () {
30
31
for _ , c := range b .context .Order {
31
32
if IsRBAC (c ) {
@@ -37,85 +38,86 @@ func (b *APIs) parseRBAC() {
37
38
}
38
39
39
40
func (b * APIs ) getRBACTag (c * types.Type ) []string {
40
- comments := Comments (c .CommentLines )
41
- resource := comments .getTags ("rbac" , ":" )
42
- resource = append (resource , comments .getTags ("kubebuilder:rbac" , ":" )... )
43
- if len (resource ) == 0 {
44
- panic (fmt .Errorf ("Must specify +kubebuilder:rbac comment for type %v" , c .Name ))
45
- }
46
- return resource
41
+ comments := Comments (c .CommentLines )
42
+ resource := comments .getTags ("rbac" , ":" )
43
+ resource = append (resource , comments .getTags ("kubebuilder:rbac" , ":" )... )
44
+ if len (resource ) == 0 {
45
+ panic (fmt .Errorf ("Must specify +kubebuilder:rbac comment for type %v" , c .Name ))
46
+ }
47
+ return resource
47
48
}
48
49
49
50
func parseRBACTag (tag string ) rbacv1.PolicyRule {
50
- result := rbacv1.PolicyRule {}
51
- for _ , elem := range strings .Split (tag , "," ) {
52
- kv := strings .Split (elem , "=" )
53
- if len (kv ) != 2 {
54
- log .Fatalf ("// +kubebuilder:rbac: tags must be key value pairs. Expected " +
55
- "keys [groups=<group1;group2>,resources=<resource1;resource2>,verbs=<verb1;verb2>] " +
56
- "Got string: [%s]" , tag )
57
- }
58
- value := kv [1 ]
59
- values := []string {}
60
- if strings .HasPrefix (value , "\" " ) && strings .HasSuffix (value , "\" " ) {
61
- value = value [1 : len (value )- 1 ]
62
- }
63
- values = strings .Split (value , ";" )
64
- switch kv [0 ] {
65
- case "groups" :
66
- result .APIGroups = values
67
- case "resources" :
68
- result .Resources = values
69
- case "verbs" :
70
- result .Verbs = values
71
- case "urls" :
72
- result .NonResourceURLs = values
73
- }
74
- }
75
- return result
51
+ result := rbacv1.PolicyRule {}
52
+ for _ , elem := range strings .Split (tag , "," ) {
53
+ kv := strings .Split (elem , "=" )
54
+ if len (kv ) != 2 {
55
+ log .Fatalf ("// +kubebuilder:rbac: tags must be key value pairs. Expected " +
56
+ "keys [groups=<group1;group2>,resources=<resource1;resource2>,verbs=<verb1;verb2>] " +
57
+ "Got string: [%s]" , tag )
58
+ }
59
+ value := kv [1 ]
60
+ values := []string {}
61
+ if strings .HasPrefix (value , "\" " ) && strings .HasSuffix (value , "\" " ) {
62
+ value = value [1 : len (value )- 1 ]
63
+ }
64
+ values = strings .Split (value , ";" )
65
+ switch kv [0 ] {
66
+ case "groups" :
67
+ result .APIGroups = values
68
+ case "resources" :
69
+ result .Resources = values
70
+ case "verbs" :
71
+ result .Verbs = values
72
+ case "urls" :
73
+ result .NonResourceURLs = values
74
+ }
75
+ }
76
+ return result
76
77
}
77
78
79
+ // parseInfomers populates the informers to generate on each annotated type.
78
80
func (b * APIs ) parseInformers () {
79
- for _ , c := range b .context .Order {
80
- if IsInformer (c ) {
81
- for _ , tag := range b .getInformerTag (c ) {
82
- if b .Informers == nil {
83
- b .Informers = map [v1.GroupVersionKind ]bool {}
84
- }
85
- b .Informers [parseInformerTag (tag )] = true
86
- }
87
- }
88
- }
81
+ for _ , c := range b .context .Order {
82
+ if IsInformer (c ) {
83
+ for _ , tag := range b .getInformerTag (c ) {
84
+ if b .Informers == nil {
85
+ b .Informers = map [v1.GroupVersionKind ]bool {}
86
+ }
87
+ b .Informers [parseInformerTag (tag )] = true
88
+ }
89
+ }
90
+ }
89
91
}
90
92
91
93
func (b * APIs ) getInformerTag (c * types.Type ) []string {
92
- comments := Comments (c .CommentLines )
93
- resource := comments .getTags ("informers" , ":" )
94
- resource = append (resource , comments .getTags ("kubebuilder:informers" , ":" )... )
95
- if len (resource ) == 0 {
96
- panic (fmt .Errorf ("Must specify +kubebuilder:informers comment for type %v" , c .Name ))
97
- }
98
- return resource
94
+ comments := Comments (c .CommentLines )
95
+ resource := comments .getTags ("informers" , ":" )
96
+ resource = append (resource , comments .getTags ("kubebuilder:informers" , ":" )... )
97
+ if len (resource ) == 0 {
98
+ panic (fmt .Errorf ("Must specify +kubebuilder:informers comment for type %v" , c .Name ))
99
+ }
100
+ return resource
99
101
}
100
102
101
103
func parseInformerTag (tag string ) v1.GroupVersionKind {
102
- result := v1.GroupVersionKind {}
103
- for _ , elem := range strings .Split (tag , "," ) {
104
- kv := strings .Split (elem , "=" )
105
- if len (kv ) != 2 {
106
- log .Fatalf ("// +kubebuilder:informers: tags must be key value pairs. Expected " +
107
- "keys [group=core,version=v1,kind=Pod] " +
108
- "Got string: [%s]" , tag )
109
- }
110
- value := kv [1 ]
111
- switch kv [0 ] {
112
- case "group" :
113
- result .Group = value
114
- case "version" :
115
- result .Version = value
116
- case "kind" :
117
- result .Kind = value
118
- }
119
- }
120
- return result
121
- }
104
+ result := v1.GroupVersionKind {}
105
+ for _ , elem := range strings .Split (tag , "," ) {
106
+ kv := strings .Split (elem , "=" )
107
+ if len (kv ) != 2 {
108
+ log .Fatalf ("// +kubebuilder:informers: tags must be key value pairs. Expected " +
109
+ "keys [group=core,version=v1,kind=Pod] " +
110
+ "Got string: [%s]" , tag )
111
+ }
112
+ value := kv [1 ]
113
+ switch kv [0 ] {
114
+ case "group" :
115
+ result .Group = value
116
+ case "version" :
117
+ result .Version = value
118
+ case "kind" :
119
+ result .Kind = value
120
+ }
121
+ }
122
+ return result
123
+ }
0 commit comments