2 Copyright 2018 The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
22 rbacv1 "k8s.io/api/rbac/v1"
23 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
24 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25 "k8s.io/apimachinery/pkg/runtime/schema"
26 "k8s.io/apimachinery/pkg/util/sets"
30 // APIs is the information of a collection of API
32 // Domain is the domain portion of the group - e.g. k8s.io
35 // Package is the name of the root API package - e.g. github.com/my-org/my-repo/pkg/apis
38 // Pkg the Package for the root API package
41 // Groups is the list of API groups found under the apis package
42 Groups map[string]*APIGroup
44 Rules []rbacv1.PolicyRule
46 Informers map[v1.GroupVersionKind]bool
49 // GetRules get rules of the APIs
50 func (apis *APIs) GetRules() []rbacv1.PolicyRule {
51 rules := []rbacv1.PolicyRule{}
52 rulesIndex := map[v1.GroupResource]sets.String{}
53 for _, rule := range apis.Rules {
54 for _, g := range rule.APIGroups {
55 for _, r := range rule.Resources {
56 gr := v1.GroupResource{
60 if _, found := rulesIndex[gr]; !found {
61 rulesIndex[gr] = sets.NewString()
63 rulesIndex[gr].Insert(rule.Verbs...)
67 for gr, v := range rulesIndex {
70 rule := rbacv1.PolicyRule{
71 Resources: []string{gr.Resource},
72 APIGroups: []string{gr.Group},
75 rules = append(rules, rule)
80 // APIGroup contains information of an API group.
81 type APIGroup struct {
82 // Package is the name of the go package the api group is under - e.g. github.com/me/apiserver-helloworld/apis
84 // Domain is the domain portion of the group - e.g. k8s.io
86 // Group is the short name of the group - e.g. mushroomkingdom
89 // Versions is the list of all versions for this group keyed by name
90 Versions map[string]*APIVersion
92 UnversionedResources map[string]*APIResource
94 // Structs is a list of unversioned definitions that must be generated
100 // Struct contains information of a struct.
102 // Name is the name of the type
110 // Fields is the list of fields appearing in the struct
114 // Field contains information of a field.
116 // Name is the name of the field
118 // For versioned Kubernetes types, this is the versioned package
119 VersionedPackage string
120 // For versioned Kubernetes types, this is the unversioned package
121 UnversionedImport string
122 UnversionedType string
125 // APIVersion contains information of an API version.
126 type APIVersion struct {
127 // Domain is the group domain - e.g. k8s.io
129 // Group is the group name - e.g. mushroomkingdom
131 // Version is the api version - e.g. v1beta1
133 // Resources is a list of resources appearing in the API version keyed by name
134 Resources map[string]*APIResource
135 // Pkg is the Package object from code-gen
139 // APIResource contains information of an API resource.
140 type APIResource struct {
141 // Domain is the group domain - e.g. k8s.io
143 // Group is the group name - e.g. mushroomkingdom
145 // Version is the api version - e.g. v1beta1
147 // Kind is the resource name - e.g. PeachesCastle
149 // Resource is the resource name - e.g. peachescastles
151 // REST is the rest.Storage implementation used to handle requests
152 // This field is optional. The standard REST implementation will be used
155 // Subresources is a map of subresources keyed by name
156 Subresources map[string]*APISubresource
157 // Type is the Type object from code-gen
159 // Strategy is name of the struct to use for the strategy
161 // Strategy is name of the struct to use for the strategy
162 StatusStrategy string
163 // NonNamespaced indicates that the resource kind is non namespaced
168 JSONSchemaProps v1beta1.JSONSchemaProps
169 CRD v1beta1.CustomResourceDefinition
171 ValidationComments string
172 // DocAnnotation is a map of annotations by name for doc. e.g. warning, notes message
173 DocAnnotation map[string]string
174 // Categories is a list of categories the resource is part of.
178 // APISubresource contains information of an API subresource.
179 type APISubresource struct {
180 // Domain is the group domain - e.g. k8s.io
182 // Group is the group name - e.g. mushroomkingdom
184 // Version is the api version - e.g. v1beta1
186 // Kind is the resource name - e.g. PeachesCastle
188 // Resource is the resource name - e.g. peachescastles
190 // Request is the subresource request type - e.g. ScaleCastle
192 // REST is the rest.Storage implementation used to handle requests
194 // Path is the subresource path - e.g. scale
197 // ImportPackage is the import statement that must appear for the Request
200 // RequestType is the type of the request
201 RequestType *types.Type
203 // RESTType is the type of the request handler
207 // Controller contains information of a controller.
208 type Controller struct {
209 Target schema.GroupVersionKind