4

我正在尝试创建一个 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实际运行的文件:AddToScheme

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

任何人都可以分享一些关于我在这里做错了什么的信息吗?

这项工作是在这篇博文之后进行的。

4

1 回答 1

3

我见过类似的错误。这是 RBAC 问题。但错误信息具有误导性。

get如果您的集群启用了 RBAC ,请确保您的控制器具有资源list权限blocks.kubechain.com

于 2018-10-28T13:17:04.943 回答