我正在尝试创建一个 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)
}
}
谁能分享一些关于我在这里做错了什么的信息?
这项工作是在这篇博文之后进行的。
芜湖不芜
相关分类