Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator-sdk generate openapi not preserving shortNames in CRD #1593

Closed
bobdonat opened this issue Jun 24, 2019 · 3 comments
Closed

operator-sdk generate openapi not preserving shortNames in CRD #1593

bobdonat opened this issue Jun 24, 2019 · 3 comments
Assignees
Labels
kind/documentation Categorizes issue or PR as related to documentation. triage/support Indicates an issue that is a support question.

Comments

@bobdonat
Copy link

Type of question

Are you asking about community best practices, how to implement a specific feature, or about general context and help around the operator-sdk?

How to implement a specific feature

Question

What did you do?
I would like to regenerate the CRD and preserve shortNames. I am having trouble with the correct syntax to preserve shortNames. Please let me know what needs to done to preserve and which file needs changing.

What did you expect to see?
shortNames preserved after "operator-sdk generate openapi"

What did you see instead? Under which circumstances?
A clear and concise description of what you expected to happen (or insert a code snippet).

Environment

  • operator-sdk version:
    operator-sdk version: v0.8.1, commit: 33b3bfe

  • Kubernetes version information:

    v1.12.8

  • Kubernetes cluster kind:

Additional context
Add any other context about the question here.

@hasbro17
Copy link
Contributor

@bobdonat operator-sdk generate openapi will regenerate your CRD and validation every time.
So your edits to the CRD manifest will not be preserved.

The SDK supports defaulting the CRD fields like short names shortNames and singular name singular via +kubebuilder tags defined in your pkg/apis/<group>/<version>/<kind>_types.go file.

E.g with:

// +kubebuilder:resource:path=services,shortName=mc;mcache
// +kubebuilder:singular=memcached
type Memcached struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   MemcachedSpec   `json:"spec,omitempty"`
	Status MemcachedStatus `json:"status,omitempty"`
}

operator-sdk generate openapi should result in:

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: memcacheds.cache.example.com
spec:
  group: cache.example.com
  names:
    kind: Memcached
    listKind: MemcachedList
    singular: memcached
    shortNames:
    - mc
    - mcache
...

We're lacking docs on these CRD +kubebuilder tags but @estroz is working to reference them as they change upstream in kubebuilder and controller-tools.

For now you can checkout the legacy documentation on this:
https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html

Past related work: #1323 #1278

@hasbro17 hasbro17 self-assigned this Jun 24, 2019
@hasbro17 hasbro17 added triage/support Indicates an issue that is a support question. kind/documentation Categorizes issue or PR as related to documentation. labels Jun 24, 2019
@bobdonat
Copy link
Author

Thank you. I was able to generate a CRD with the shortName preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

2 participants