环境
Kubectl 版本
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.4", GitCommit:"c96aede7b5205121079932896c4ad89bb93260af", GitTreeState:"clean", BuildDate:"2020-06-18T02:59:13Z", GoVersion:"go1.14.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.4-80+89e0897d2cb807", GitCommit:"89e0897d2cb8073fbb8f700258573f1478d4826a", GitTreeState:"clean", BuildDate:"2021-11-22T03:53:35Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Kubernetes 版本(种类集群)
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9
- role: worker
image: kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9
- role: worker
image: kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9
Kubebuilder 版本
Version: main.version{KubeBuilderVersion:"3.1.0", KubernetesVendor:"1.19.2", GitCommit:"92e0349ca7334a0a8e5e499da4fb077eb524e94a", BuildDate:"2021-05-27T17:54:28Z", GoOs:"darwin", GoArch:"amd64"}
操作系统
Macos Big Sur 11.6
我使用 kubebuilder 来定义我自己的CRD
,如下所示,它包含 VolumeClaimTemplates
类型为的字段[]coreV1.PersistentVolumeClaim
package v1alpha1
import (
apps "k8s.io/api/apps/v1"
coreV1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
type DatabaseSetSpec struct {
...
// +optional
VolumeClaimTemplates []coreV1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty" protobuf:"bytes,4,rep,name=volumeClaimTemplates"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=ami-dbs
// DatabaseSet is the Schema for the databasesets API
type DatabaseSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DatabaseSetSpec `json:"spec,omitempty"`
Status DatabaseSetStatus `json:"status,omitempty"`
}
// DatabaseSetStatus defines the observed state of DatabaseSet
type DatabaseSetStatus struct {
...
}
//+kubebuilder:object:root=true
// DatabaseSetList contains a list of DatabaseSet
type DatabaseSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DatabaseSet `json:"items"`
}
func init() {
SchemeBuilder.Register(&DatabaseSet{}, &DatabaseSetList{})
}
但是当我像下面这样申请 CR 时,我发现该 metadata
文件是空的
apiVersion: apps.analyticdb.aliyun.com/v1alpha1
kind: DatabaseSet
metadata:
name: databaseset-sample
spec:
...
volumeClaimTemplates:
- metadata:
name: pvc-test
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "manual"
resources:
requests:
storage: 3Gi
这是从k8s ectd获取的yaml,可以发现它的元数据volumeClaimTemplates
是空的。
apiVersion: apps.analyticdb.aliyun.com/v1alpha1
kind: DatabaseSet
metadata:
creationTimestamp: "2021-12-24T09:46:22Z"
generation: 1
name: databaseset-sample
namespace: default
resourceVersion: "98727469"
uid: e64107f2-7a4b-473b-9275-39ab5e2e88dc
spec:
...
volumeClaimTemplates:
- metadata: {}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
storageClassName: manual
有谁知道为什么?</p>
当我用下面的评论标记volumeclaimtemplate字段时,metada
可以正确解码
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless