Repository: kubernetes-sigs/controller-tools
Pull request #252 (2019-07-11 22:10:01)

Make the `Path` field of the "+kubebuilder:resource" marker optional
Fix: https://github.com/kubernetes-sigs/controller-tools/issues/239

This PR also adds `-race` flag into `go test`

This should unblock https://github.com/kubernetes-sigs/kubebuilder/pull/763

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/controller-tools/pull/252#" title="Author self-approved">haiyanmeng</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **droot**
You can assign the PR to them by writing `/assign @droot` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fcontroller-tools).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/controller-tools/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["droot"]} -->

Patch:
diff --git a/pkg/crd/markers/crd.go b/pkg/crd/markers/crd.go
index 73ad7122..2bc524ff 100644
--- a/pkg/crd/markers/crd.go
+++ b/pkg/crd/markers/crd.go
@@ -179,7 +179,7 @@ func (s PrintColumn) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, versio
 
 // Resource defines "+kubebuilder:resource"
 type Resource struct {
-	Path       string
+	Path       string   `marker:",optional"`
 	ShortName  []string `marker:",optional"`
 	Categories []string `marker:",optional"`
 	Singular   string   `marker:",optional"`
@@ -187,7 +187,9 @@ type Resource struct {
 }
 
 func (s Resource) ApplyToCRD(crd *apiext.CustomResourceDefinitionSpec, version string) error {
-	crd.Names.Plural = s.Path
+	if s.Path != "" {
+		crd.Names.Plural = s.Path
+	}
 	crd.Names.ShortNames = s.ShortName
 	crd.Names.Categories = s.Categories
 


Test patch:
diff --git a/pkg/crd/testdata/cronjob_types.go b/pkg/crd/testdata/cronjob_types.go
index ec4faa99..3e882d4e 100644
--- a/pkg/crd/testdata/cronjob_types.go
+++ b/pkg/crd/testdata/cronjob_types.go
@@ -146,6 +146,7 @@ type CronJobStatus struct {
 
 // +kubebuilder:object:root=true
 // +kubebuilder:subresource:status
+// +kubebuilder:resource
 
 // CronJob is the Schema for the cronjobs API
 type CronJob struct {
diff --git a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
index dc5d985e..31b60fb1 100644
--- a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
+++ b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
@@ -10,7 +10,7 @@ spec:
   names:
     kind: CronJob
     plural: cronjobs
-  scope: ""
+  scope: Namespaced
   versions:
   - name: v1
     schema:
diff --git a/test.sh b/test.sh
index 6e4c6643..8269550a 100755
--- a/test.sh
+++ b/test.sh
@@ -134,7 +134,7 @@ golangci-lint run --disable-all \
 
 header_text "running go test"
 
-go test ./pkg/... ./cmd/... -parallel 4
+go test -race ./pkg/... ./cmd/... -parallel 4
 
 # ensure that Gopkg.{toml,lock} are up-to-date
 header_text "ensuring that Gopkg.{toml,lock} are up to date..."