@@ -17,19 +17,20 @@ limitations under the License.
17
17
package parse
18
18
19
19
import (
20
+ "bytes"
21
+ "encoding/json"
20
22
"fmt"
21
23
"log"
22
24
"regexp"
25
+ "strconv"
23
26
"strings"
27
+ "text/template"
24
28
25
- "bytes"
26
- "encoding/json"
29
+ "github.com/pkg/errors"
27
30
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
28
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
32
"k8s.io/apimachinery/pkg/util/sets"
30
33
"k8s.io/gengo/types"
31
- "strconv"
32
- "text/template"
33
34
)
34
35
35
36
// parseCRDs populates the CRD field of each Group.Version.Resource,
@@ -74,6 +75,11 @@ func (b *APIs) parseCRDs() {
74
75
resource .CRD .Spec .Scope = "Namespaced"
75
76
}
76
77
78
+ if HasCategories (resource .Type ) {
79
+ categoriesTag := getCategoriesTag (resource .Type )
80
+ resource .CRD .Spec .Names .Categories = strings .Split (categoriesTag , "," )
81
+ }
82
+
77
83
if len (resource .ShortName ) > 0 {
78
84
resource .CRD .Spec .Names .ShortNames = []string {resource .ShortName }
79
85
}
@@ -457,3 +463,13 @@ func (b *APIs) getMembers(t *types.Type, found sets.String) (map[string]v1beta1.
457
463
defer found .Delete (t .Name .String ())
458
464
return members , result
459
465
}
466
+
467
+ // getCategoriesTag returns the value of the +kubebuilder:categories tags
468
+ func getCategoriesTag (c * types.Type ) string {
469
+ comments := Comments (c .CommentLines )
470
+ resource := comments .getTag ("kubebuilder:categories" , "=" )
471
+ if len (resource ) == 0 {
472
+ panic (errors .Errorf ("Must specify +kubebuilder:categories comment for type %v" , c .Name ))
473
+ }
474
+ return resource
475
+ }
0 commit comments