我正在嘗試創(chuàng)建一個(gè) kubernetes 自定義資源定義(名為Block),但不斷出現(xiàn)以下錯(cuò)誤:Failed to list *v1alpha1.Block: the server could not find the requested resource (get blocks.kubechain.com).此問題是從List對此 CRD 的控制器調(diào)用中引發(fā)的: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}這是我實(shí)際從前一個(gè)文件scheme.go運(yùn)行的文件: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) }}誰能分享一些關(guān)于我在這里做錯(cuò)了什么的信息?這項(xiàng)工作是在這篇博文之后進(jìn)行的。
1 回答

蕪湖不蕪
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
我見過類似的錯(cuò)誤。這是 RBAC 問題。但錯(cuò)誤信息具有誤導(dǎo)性。
如果您的集群啟用了 RBAC,請確保您的控制器具有資源get
權(quán)限。list
blocks.kubechain.com
- 1 回答
- 0 關(guān)注
- 179 瀏覽
添加回答
舉報(bào)
0/150
提交
取消