Bug fix:'operator-sdk add crd' doesn't work after add kubebuilder tags#1660
Bug fix:'operator-sdk add crd' doesn't work after add kubebuilder tags#1660estroz merged 5 commits intooperator-framework:masterfrom xm2:master
Conversation
|
Hi @xm2. Thanks for your PR. I'm waiting for a operator-framework or openshift member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
cc @estroz ^ |
|
/ok-to-test |
|
Does running EDIT: The reason that command works is because it sets the repo field of |
|
@xm2 can you rebase onto/merge with |
|
@xm2 Since this is a bug fix, can you please add a line to the Bugfix section of the CHANGELOG in the same format as the other changelogs. @estroz PTAL. |
Co-Authored-By: Eric Stroczynski <estroczy@redhat.com>
|
@xm2 you'll have to merge your branch with master to fix the CI error unfortunately. |
|
New changes are detected. LGTM label has been removed. |
|
@xm2 awesome, and thanks for the PR! |
Description of the change:
Bug fix: 'operator-sdk add crd' doesn't work after add kubebuilder tags in _types.go
Motivation for the change:
kubebuildertags in _types.go files, e.g. validation tag or scale subresource tag,type AppServiceSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html + // +kubebuilder:validation:Maximum=100 + // +kubebuilder:validation:Minimum=1 + Replicas *int32 `json:"size,omitempty"` } // AppServiceStatus defines the observed state of AppService // +k8s:openapi-gen=true type AppServiceStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html + Replicas int32 `json:"replicas,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // AppService is the Schema for the appservices API // +k8s:openapi-gen=true // +kubebuilder:subresource:status +// +kubebuilder:subresource:scale:specpath=.spec.size,statuspath=.status.replicas type AppService struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` Spec AppServiceSpec `json:"spec,omitempty"` Status AppServiceStatus `json:"status,omitempty"` }operator-sdk add crd --api-version=app.example.com/v1alpha1 --kind=AppServiceto re-generated crd yaml based on new kubebuilder tag, it failed:Root cause analysis:
From investigation, this error is reported when the
Repoin input.Config is not set and no "PROJECT" file in project root path when callValidateAndInitFields()incontroller-tools/pkg/crd/generator/generator.go.To fix the error, either add "Repo" in input.Config, or, add "PROJECT"file in project root path.
BUT "PROJECT" is a file in
kubebuildergenerated project, it doesn't exist in operator-sdk project.So in the code change, fix the bug by adding "Repo" in input.Config.
Test Result
After the fix, the _crd.yaml can be generated correctly with new "kubebuilder" tags: