Kubernetes Custom CRD: “Failed to list …: the server could not find the requested resource”

不问归期 提交于 2019-12-13 15:25:59

问题


I am trying to create a kubernetes Custom Resource Definition (named Block) but keep hitting the following error:

Failed to list *v1alpha1.Block: the server could 
not find the requested resource (get 
blocks.kubechain.com).

This issue is raised from a call to List on a Controller for this 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{},
    )

For some context here is the register.go file where I register the above resourced to the a scheme builder:

// 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
}

And here is the scheme.go file where I actually run AddToScheme from the former file:

var Scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(Scheme)
var ParameterCodec = runtime.NewParameterCodec(Scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
    v1alpha1.AddToScheme,
}

var AddToScheme = localSchemeBuilder.AddToScheme

func init() {
    metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
    if err := AddToScheme(Scheme); err != nil {
        panic(err)
    }
}

Can anyone share some information as to what I am doing wrong here??

This work is following this blog post.


回答1:


I have seen similar error. It was RBAC issue. But the error message was misleading.

If your cluster has RBAC enabled, make sure your controller has get,list permission for blocks.kubechain.com resource.



来源:https://stackoverflow.com/questions/53021171/kubernetes-custom-crd-failed-to-list-the-server-could-not-find-the-reques

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!