kubebuilder Operator 使用过程的 FaQ 汇总
FaQ
make run 错误
1.662972455727089e+09 ERROR setup problem running manager {"error": "open /var/folders/ql/nw5zyrg905z78mq4kwmq1lg00000gn/T/k8s-webhook-server/serving-certs/tls.crt: no such file or directory"}
main.main
/Users/xiexianbin/workspace/code/github.com/kbcx/xca-operator/main.go:116
runtime.main
/usr/local/Cellar/go/1.19/libexec/src/runtime/proc.go:250
exit status 1
make: *** [run] Error 1
- 原因:
main.go
SetupWebhookWithManager
导致的问题
if err = (&xcav1alpha1.Xtls{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Xtls")
os.Exit(1)
}
setupLog.Info("ENABLE_WEBHOOKS setting", "ENABLE_WEBHOOKS", os.Getenv("ENABLE_WEBHOOKS"))
if os.Getenv("ENABLE_WEBHOOKS") == "true" {
if err = (&xcav1alpha1.Xtls{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Xtls")
os.Exit(1)
}
}
通过变量指定不启用 Webhooks:export ENABLE_WEBHOOKS=false
日志使用问题
- Observed a panic in reconciler: odd number of arguments passed as key-value pairs for logging 问题
logger := log.FromContext(ctx)
与 logger.Info(k,v)
字段重复
Mac make test 错误
/Users/xiexianbin/workspace/code/github.com/kbcx/xca-operator/controllers/suite_test.go:53
Unexpected error:
<*fmt.wrapError | 0xc00043e700>: {
msg: "unable to start control plane itself: failed to start the controlplane. retried 5 times: exec: \"etcd\": executable file not found in $PATH",
err: <*fmt.wrapError | 0xc00043e6e0>{
msg: "failed to start the controlplane. retried 5 times: exec: \"etcd\": executable file not found in $PATH",
err: <*exec.Error | 0xc00043e6a0>{
Name: "etcd",
Err: <*errors.errorString | 0xc0001103c0>{
s: "executable file not found in $PATH",
},
},
},
}
unable to start control plane itself: failed to start the controlplane. retried 5 times: exec: "etcd": executable file not found in $PATH
occurred
下载 https://storage.googleapis.com/storage/v1/b/kubebuilder-tools/o/kubebuilder-tools-1.24.2-darwin-amd64.tar.gz
// 安装 envtest,需要翻墙下载依赖
$ ./bin/setup-envtest use
Version: 1.25.0
OS/Arch: darwin/amd64
md5: KzqRlFTKdS1HlJ/n7W0+LQ==
Path: /Users/xiexianbin/Library/Application Support/io.kubebuilder.envtest/k8s/1.25.0-darwin-amd64
// 查看下载的内容
$ ls ${HOME}/Library/Application\ Support/io.kubebuilder.envtest/k8s/1.25.0-darwin-amd64
etcd kube-apiserver kubectl
// 添加环境变量
$ export PATH=$PATH:${HOME}/Library/Application\ Support/io.kubebuilder.envtest/k8s/1.25.0-darwin-amd64
// 重新测试,正常
$ make test
参考