Skip to content

Commit a523fb6

Browse files
authored
Merge pull request #276 from pmorie/categories-controller-install
Add categories to the CRD installed by the controller
2 parents 2ca8b7a + ee77a60 commit a523fb6

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

cmd/internal/codegen/parse/crd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ func (b *APIs) parseCRDs() {
7777

7878
if HasCategories(resource.Type) {
7979
categoriesTag := getCategoriesTag(resource.Type)
80-
resource.CRD.Spec.Names.Categories = strings.Split(categoriesTag, ",")
80+
categories := strings.Split(categoriesTag, ",")
81+
resource.CRD.Spec.Names.Categories = categories
82+
resource.Categories = categories
8183
}
8284

8385
if HasStatusSubresource(resource.Type) {

cmd/internal/codegen/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ type APIResource struct {
166166
DocAnnotation map[string]string
167167
// HasStatusSubresource indicates that the resource has a status subresource
168168
HasStatusSubresource bool
169+
// Categories is a list of categories the resource is part of.
170+
Categories []string
169171
}
170172

171173
type APISubresource struct {

cmd/kubebuilder-gen/internal/resourcegen/versioned_generator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ var (
127127
{{ if .ShortName -}}
128128
ShortNames: []string{"{{.ShortName}}"},
129129
{{ end -}}
130+
{{ if .Categories -}}
131+
Categories: []string{
132+
{{ range .Categories -}}
133+
"{{ . }}",
134+
{{ end -}}
135+
},
136+
{{ end -}}
130137
},
131138
{{ if .NonNamespaced -}}
132139
Scope: "Cluster",

cmd/kubebuilder/create/resource/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type resourceTemplateArgs struct {
3636
PluralizedKind string
3737
NonNamespacedKind bool
3838
HasStatusSubresource bool
39+
Categories []string
3940
}
4041

4142
func doResource(dir string, args resourceTemplateArgs) bool {

cmd/kubebuilder/create/resource/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func createResource(boilerplate string) {
110110
inflect.NewDefaultRuleset().Pluralize(createutil.KindName),
111111
nonNamespacedKind,
112112
false,
113+
nil,
113114
}
114115

115116
dir, err := os.Getwd()

0 commit comments

Comments
 (0)