我是Kubernetes的新人.在制作自定义K8 schduler插件时遇到这个错误.我使用这个链接Kube-Scheduler-Plugin做了一切,一切都完成了,但当我运行时

./hack/update-codegen.sh

该文件没有创建DeepCopyBody,因为当我运行make命令时它会出现此错误

$ make
fatal: No names found, cannot describe anything.
fatal: No names found, cannot describe anything.
fatal: No names found, cannot describe anything.
GOOS=linux CGO_ENABLED=0 go build -ldflags '-w' -o bin/controller cmd/controller/controller.go
GOOS=linux CGO_ENABLED=0 go build -ldflags '-X k8s.io/component-base/version.gitVersion=v0.0.20240430 -w' -o bin/kube-scheduler cmd/scheduler/main.go
# sigs.k8s.io/scheduler-plugins/apis/config
apis/config/register.go:47:3: cannot use &PIDControllerArgs{} (value of type *PIDControllerArgs) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to scheme.AddKnownTypes: *PIDControllerArgs does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)
make: *** [Makefile:62: build-scheduler] Error 1

我进行了故障排除,但无法找到问题并按应有的方式使用标签.任何人都能进一步 bootstrap 正确的方向进行故障排除吗?谢谢你

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PIDControllerArgs struct {
    metav1.TypeMeta

    // EndpointURL is the URL to which score requests will be sent.
    EndpointURL *string

    // MaxIdleConnections defines the maximum number of idle connections to the     server.
    MaxIdleConnections *int

    // IdleConnectionTimeoutSec defines the timeout for idle connections in seconds.
    IdleConnectionTimeoutSec *int

    // RequestTimeoutSec defines the timeout for requests in seconds.
    RequestTimeoutSec *int
}

/connect/v1/typ.go

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:defaulter-gen=true
type PIDControllerArgs struct {
    metav1.TypeMeta `json:",inline"`

    // EndpointURL is the URL to which score requests will be sent.
    EndpointURL *string `json:"endpointURL,omitempty"`

    // MaxIdleConnections defines the maximum number of idle connections to the server.
    MaxIdleConnections *int `json:"maxIdleConnections,omitempty"`

    // IdleConnectionTimeoutSec defines the timeout for idle connections in seconds.
    IdleConnectionTimeoutSec *int `json:"idleConnectionTimeoutSec,omitempty"`

    // RequestTimeoutSec defines the timeout for requests in seconds.
    RequestTimeoutSec *int `json:"requestTimeoutSec,omitempty"`
}

推荐答案

每个要生成代码的包中应该有doc.go个文件:

.
└── pkg
    └── apis
        └── config
            ├── doc.go
            ├── types.go
            └── v1
                ├── doc.go
                └── types.go

doc.go个文件应包含:

// +k8s:deepcopy-gen=package,register
package {name}

其中{name}替换为包名称:configv1

2 types.go文件中的 struct 应该包括您拥有的 comments :

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

那么make应该可以工作,或者如果您安装了deepcopy-gen:

go install k8s.io/code-generator/cmd/deepcopy-gen@latest

您可以:

deepcopy-gen \
--v=9 \
./pkg/apis/config/...

这将导致两个包中都有generated.deepcopy.go个文件.

由于 struct 上没有DeepCopyObject个方法,runtime#Object接口将不满足,因此会出现错误消息(如下所示).generated.deepcopy.go个文件满足此要求.

cannot use PIDControllerArgs as "k8s.io/apimachinery/pkg/runtime".Object

请参阅deepcopy-gen文档.

Go相关问答推荐

Go 1.22 net/http群组路由

gorm如何声明未自动更新的unix时间戳米尔斯字段

gorm插入不支持的数据

如何使用Promela建模语言对Golang RWLock进行建模

如何防止程序B存档/删除围棋中程序A当前打开的文件?

GO框架Echo中间件的使用

无法获取RPC描述符

exec的可执行决议.命令+路径

如果第一次匹配条件,如何跳过切片中的值

这种合并排序的实现有什么问题?

为什么标准库中的 IsSorted 会反向迭代切片?

同一文件上的多个 Arrow CSV 阅读器返回 null

Neptune 在连接到启用 IAM 的 Neptune 实例时抛出握手错误错误

转换朴素递归硬币问题时的记忆错误

通过环境变量配置 OTLP 导出器

具有未导出字段的 struct 类型之间的转换

为什么import和ImportSpec之间可以出现多行注释,而PackageName和ImportPath之间不能出现?

在 connect-go 拦截器中修改响应体

有没有办法在一个 goroutine 返回后延迟后取消上下文?

在 Go 中,为什么 exec.Command() 失败但 os.StartProcess() 成功启动winget.exe?