shenkonghui / issue

问题记录
0 stars 0 forks source link

k8s crd设置map[string]interface{}, 提示map values must be a named type, not *ast.MapType #184

Closed shenkonghui closed 1 year ago

shenkonghui commented 1 year ago
 make manifests
/Users/shenkonghui/src/work/middleware-backup-controller/bin/controller-gen "crd:trivialVersions=true,preserveUnknownFields=false" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/shenkonghui/src/work/middleware-backup-controller/api/v1/middlewarebackup_types.go:116:31: map values must be a named type, not *ast.MapType
/Users/shenkonghui/src/work/middleware-backup-controller/api/v1/backupresult_types.go:38:31: map values must be a named type, not *ast.MapType
/Users/shenkonghui/src/work/middleware-backup-controller/api/v1/middlewarebackupschedule_types.go:71:29: map values must be a named type, not *ast.MapType
shenkonghui commented 1 year ago

建议不要使用map, 而是使用RawExtension,如下

type Provider struct {

    Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
    ControlPlaneConfig *runtime.RawExtension `json:"controlPlaneConfig,omitempty" protobuf:"bytes,2,opt,name=controlPlaneConfig"`
    InfrastructureConfig *runtime.RawExtension `json:"infrastructureConfig,omitempty" protobuf:"bytes,3,opt,name=infrastructureConfig"`

}

如果一定要使用, 加上以下注释,自动设置UnknownFields, 忽略掉这个错误就行 // +kubebuilder:validation:XPreserveUnknownFields