Operator-sdk: operator-sdk generate openapi not preserving shortNames in CRD

Created on 24 Jun 2019  路  3Comments  路  Source: operator-framework/operator-sdk

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: 33b3bfe10176f8647f5354516fff29dea42b6342
  • Kubernetes version information:

    v1.12.8

  • Kubernetes cluster kind:

Additional context
Add any other context about the question here.

kindocumentation triagsupport

Most helpful comment

@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

All 3 comments

@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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smiklosovic picture smiklosovic  路  4Comments

camilamacedo86 picture camilamacedo86  路  5Comments

danielsig727 picture danielsig727  路  4Comments

flickerfly picture flickerfly  路  5Comments

lsalazar1 picture lsalazar1  路  4Comments