kubebuilder怎么开始
# 官网:https://book.kubebuilder.io/quick-start#create-a-project
版本
#go1.19、go1.20(官方文档里的版本)都不行
go1.18
docker 20.10.0
kubectl 1.21.14
kubebuilder 3.5 #https://github.com/kubernetes-sigs/kubebuilder/releases
步骤:
chmod +x kubebuilder && mv kubebuilder {你的GOPATH}/bin/
create api 一直报错,竟然是go安装的问题
报错内容:
kubebuilder create api --group webapp --version v1 --kind Guestbook
Create Resource [y/n]
y
Create Controller [y/n]
y
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
api/v1/guestbook_types.go
controllers/guestbook_controller.go
Update dependencies:
$ go mod tidy
Running make:
$ make generate
mkdir -p /root/k8s/operatortest/bin
GOBIN=/root/k8s/operatortest/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0
# runtime/internal/sys
/usr/local/go/src/runtime/internal/sys/consts.go:13:7: StackGuardMultiplier redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:27:7: other declaration of StackGuardMultiplier
/usr/local/go/src/runtime/internal/sys/consts.go:16:7: DefaultPhysPageSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:36:7: other declaration of DefaultPhysPageSize
/usr/local/go/src/runtime/internal/sys/consts.go:20:7: PCQuantum redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:40:7: other declaration of PCQuantum
/usr/local/go/src/runtime/internal/sys/consts.go:23:7: Int64Align redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:43:7: other declaration of Int64Align
/usr/local/go/src/runtime/internal/sys/consts.go:30:7: MinFrameSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:50:7: other declaration of MinFrameSize
/usr/local/go/src/runtime/internal/sys/consts.go:34:7: StackAlign redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:54:7: other declaration of StackAlign
/usr/local/go/src/runtime/internal/sys/stubs.go:9:7: PtrSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:24:7: other declaration of PtrSize
/usr/local/go/src/runtime/internal/sys/stubs.go:10:24: undefined: Uintreg
/usr/local/go/src/runtime/internal/sys/stubs.go:16:7: StackGuardMultiplier redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:27:7: other declaration of StackGuardMultiplier
# math
/usr/local/go/src/math/acosh.go:42:6: Acosh defined in both Go and assembly
/usr/local/go/src/math/asin.go:19:6: Asin defined in both Go and assembly
/usr/local/go/src/math/asin.go:56:6: Acos defined in both Go and assembly
/usr/local/go/src/math/asinh.go:39:6: Asinh defined in both Go and assembly
/usr/local/go/src/math/atan.go:95:6: Atan defined in both Go and assembly
/usr/local/go/src/math/atan2.go:29:6: Atan2 defined in both Go and assembly
/usr/local/go/src/math/atanh.go:47:6: Atanh defined in both Go and assembly
/usr/local/go/src/math/cbrt.go:25:6: Cbrt defined in both Go and assembly
/usr/local/go/src/math/erf.go:188:6: Erf defined in both Go and assembly
/usr/local/go/src/math/erf.go:272:6: Erfc defined in both Go and assembly
/usr/local/go/src/math/erf.go:272:6: too many errors
make: *** [/root/k8s/operatortest/bin/controller-gen] Error 2
Error: failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v3": exit status 2
测试办法:
#测试办法:
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0
报错如下:
/*
# runtime/internal/sys
/usr/local/go/src/runtime/internal/sys/consts.go:13:7: StackGuardMultiplier redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:27:7: other declaration of StackGuardMultiplier
/usr/local/go/src/runtime/internal/sys/consts.go:16:7: DefaultPhysPageSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:36:7: other declaration of DefaultPhysPageSize
/usr/local/go/src/runtime/internal/sys/consts.go:20:7: PCQuantum redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:40:7: other declaration of PCQuantum
/usr/local/go/src/runtime/internal/sys/consts.go:23:7: Int64Align redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:43:7: other declaration of Int64Align
/usr/local/go/src/runtime/internal/sys/consts.go:30:7: MinFrameSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:50:7: other declaration of MinFrameSize
/usr/local/go/src/runtime/internal/sys/consts.go:34:7: StackAlign redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:54:7: other declaration of StackAlign
/usr/local/go/src/runtime/internal/sys/stubs.go:9:7: PtrSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:24:7: other declaration of PtrSize
/usr/local/go/src/runtime/internal/sys/stubs.go:10:24: undefined: Uintreg
/usr/local/go/src/runtime/internal/sys/stubs.go:16:7: StackGuardMultiplier redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:27:7: other declaration of StackGuardMultiplier
# math
/usr/local/go/src/math/acosh.go:42:6: Acosh defined in both Go and assembly
/usr/local/go/src/math/asin.go:19:6: Asin defined in both Go and assembly
/usr/local/go/src/math/asin.go:56:6: Acos defined in both Go and assembly
/usr/local/go/src/math/asinh.go:39:6: Asinh defined in both Go and assembly
/usr/local/go/src/math/atan.go:95:6: Atan defined in both Go and assembly
/usr/local/go/src/math/atan2.go:29:6: Atan2 defined in both Go and assembly
/usr/local/go/src/math/atanh.go:47:6: Atanh defined in both Go and assembly
/usr/local/go/src/math/cbrt.go:25:6: Cbrt defined in both Go and assembly
/usr/local/go/src/math/erf.go:188:6: Erf defined in both Go and assembly
/usr/local/go/src/math/erf.go:272:6: Erfc defined in both Go and assembly
/usr/local/go/src/math/erf.go:272:6: too many errors
*/
解决办法
Had the same issue using wsl, completely remove go and reinstall solves the problem
sudo rm -rf /usr/local/go
自己去/home下remove path from .bashrc
sudo tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz
#add PATH back to .bashrc solves the problem
#在linux中,bashrc文件在“/home”目录下,也即用户的主目录下;该文件是一个隐藏文件,用于存储并加载系统的终端配置和环境变量,可以用“ls -a”命令查看,用“find -name .bashrc”命令查找文件在什么位置。