Skip to content

Commit e42c902

Browse files
committed
Make the Path field of the "+kubebuilder:resource" marker optional
Signed-off-by: Haiyan Meng <[email protected]>
1 parent c4d99a1 commit e42c902

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

pkg/crd/markers/crd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ func (s PrintColumn) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, versio
179179

180180
// Resource defines "+kubebuilder:resource"
181181
type Resource struct {
182-
Path string
182+
Path string `marker:",optional"`
183183
ShortName []string `marker:",optional"`
184184
Categories []string `marker:",optional"`
185185
Singular string `marker:",optional"`
186186
Scope string `marker:",optional"`
187187
}
188188

189189
func (s Resource) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, version string) error {
190-
crd.Names.Plural = s.Path
190+
if s.Path != "" {
191+
crd.Names.Plural = s.Path
192+
}
191193
crd.Names.ShortNames = s.ShortName
192194
crd.Names.Categories = s.Categories
193195

pkg/crd/testdata/cronjob_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ type CronJobStatus struct {
146146

147147
// +kubebuilder:object:root=true
148148
// +kubebuilder:subresource:status
149+
// +kubebuilder:resource
149150

150151
// CronJob is the Schema for the cronjobs API
151152
type CronJob struct {

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
names:
1111
kind: CronJob
1212
plural: cronjobs
13-
scope: ""
13+
scope: Namespaced
1414
versions:
1515
- name: v1
1616
schema:

0 commit comments

Comments
 (0)