vmware-archive / operator-builder

A Kubebuilder plugin to accelerate the development of Kubernetes operators
MIT License
41 stars 6 forks source link

bug(multi-version): error when generating manifests for multiple versions #190

Open scottd018 opened 2 years ago

scottd018 commented 2 years ago

Running make manifests results in the following:

/Users/sdustin/go/bin/controller-gen "crd:preserveUnknownFields=false,crdVersions=v1,trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
github.com/vmware-tanzu-labs/namespace-operator/apis/tenancy/v1alpha2:-: CRD for TanzuNamespace.tenancy.platform.cnr.vmware.com has no storage version
Error: not all generators ran successfully
run `controller-gen crd:preserveUnknownFields=false,crdVersions=v1,trivialVersions=true rbac:roleName=manager-role webhook paths=./... output:crd:artifacts:config=config/crd/bases -w` to see all available markers, or `controller-gen crd:preserveUnknownFields=false,crdVersions=v1,trivialVersions=true rbac:roleName=manager-role webhook paths=./... output:crd:artifacts:config=config/crd/bases -h` for usage
make: *** [manifests] Error 1

It appears adding +kubebuilder:storageversion will fix the issue (see https://github.com/kubernetes-sigs/controller-tools/issues/390). Anything else (e.g. I support v1beta2 but i submit a v1beta1 resources) will result in a conversion webhook doing the conversion.

This doesn't appear to work when I try it, however I'm still playing around with this.

scottd018 commented 2 years ago

This does work for multiple versions. Here is the snippet that works:

// +kubebuilder:storageversion
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// TanzuNamespace is the Schema for the tanzunamespaces API.
type TanzuNamespace struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty"`
    Spec              TanzuNamespaceSpec   `json:"spec,omitempty"`
    Status            TanzuNamespaceStatus `json:"status,omitempty"`
}

Given that only one version can implement this functionality, we need to discuss how to handle this in our project.

The challenge here is that:

1) We can't implement this statically on all generated API versions, because only one version can have this feature. 2) It will be incredibly difficult, considering that controller-gen does the manifest generation for us, to ignore and/or remove the storage-version from an older API version.