我正在尝试创建一个 kubernetes 自定义资源定义(名为Block),但不断出现以下错误:Failed to list *v1alpha1.Block: the server could not find the requested resource (get blocks.kubechain.com).此问题是从List对此 CRD 的控制器调用中引发的:indexer, controller := cache.NewIndexerInformer( &cache.ListWatch{ ListFunc: func(lo metav1.ListOptions) (result k8sruntime.Object, err error) { return clientSet.Block(ns).List(lo) }, WatchFunc: func(lo metav1.ListOptions) (watch.Interface, error) { return clientSet.Block(ns).Watch(lo) }, }, &v1alpha1.Block{}, 1*time.Minute, cache.ResourceEventHandlerFuncs{}, cache.Indexers{}, )对于某些上下文,这里是register.go我将上述资源注册到方案生成器的文件:// GroupName is the api prefix.const GroupName = "kubechain.com"// GroupVersion is the version of the api.const GroupVersion = "v1alpha1"// SchemeGroupVersion is the group version object.var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion}var ( // SchemeBuilder adds the new CRDs Block and Blockchain. SchemeBuilder = runtime.NewSchemeBuilder(AddKnownTypes) // AddToScheme uses SchemeBuilder to add new CRDs. AddToScheme = SchemeBuilder.AddToScheme)// AddKnownTypes .func AddKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Block{}, &BlockList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil}这是我实际从前一个文件scheme.go运行的文件:AddToSchemevar Scheme = runtime.NewScheme()var Codecs = serializer.NewCodecFactory(Scheme)var ParameterCodec = runtime.NewParameterCodec(Scheme)var localSchemeBuilder = runtime.SchemeBuilder{ v1alpha1.AddToScheme,}var AddToScheme = localSchemeBuilder.AddToSchemefunc init() { metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) if err := AddToScheme(Scheme); err != nil { panic(err) }}谁能分享一些关于我在这里做错了什么的信息?这项工作是在这篇博文之后进行的。
1 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
我见过类似的错误。这是 RBAC 问题。但错误信息具有误导性。
如果您的集群启用了 RBAC,请确保您的控制器具有资源get
权限。list
blocks.kubechain.com
- 1 回答
- 0 关注
- 128 浏览
添加回答
举报
0/150
提交
取消