我正在尝试创建一个 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)
}
}
任何人都可以分享一些关于我在这里做错了什么的信息吗?
这项工作是在这篇博文之后进行的。