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
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
Kubernetes version information:
v1.12.8
Kubernetes cluster kind:
Additional context
Add any other context about the question here.
@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
Another older example from controller-tools:
https://github.com/kubernetes-sigs/controller-tools/blob/ef510a1e684c475ddcc8a944501e139ff7e315a2/pkg/crd/generator/testData/pkg/apis/fun/v1alpha1/toy_types.go#L89-L104
Thank you. I was able to generate a CRD with the shortName preserved.
Most helpful comment
@bobdonat
operator-sdk generate openapiwill 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
shortNamesand singular namesingularvia+kubebuildertags defined in yourpkg/apis/<group>/<version>/<kind>_types.gofile.E.g with:
operator-sdk generate openapishould result in:We're lacking docs on these CRD
+kubebuildertags 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