最近在準(zhǔn)備學(xué)習(xí)下kubernetes operator的開發(fā),在通過kubebuilder 腳手架創(chuàng)建operator項(xiàng)目時(shí),出現(xiàn)報(bào)錯:Error: failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v4": exit status 1
詳情如下:
% kubebuilder init --domain demo.io --plugins=go/v4
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.17.0
go: downloading github.com/golang/protobuf v1.5.3
go: downloading github.com/prometheus/procfs v0.12.0
go: sigs.k8s.io/controller-runtime imports
sigs.k8s.io/controller-runtime/pkg/builder imports
sigs.k8s.io/controller-runtime/pkg/client/apiutil imports
k8s.io/client-go/discovery imports
github.com/golang/protobuf/proto: zip: not a valid zip file
go: sigs.k8s.io/controller-runtime imports
sigs.k8s.io/controller-runtime/pkg/builder imports
sigs.k8s.io/controller-runtime/pkg/webhook/admission imports
sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics imports
github.com/prometheus/client_golang/prometheus imports
github.com/prometheus/procfs: zip: not a valid zip file
go: sigs.k8s.io/controller-runtime imports
sigs.k8s.io/controller-runtime/pkg/builder imports
sigs.k8s.io/controller-runtime/pkg/client/apiutil imports
k8s.io/client-go/discovery imports
github.com/google/gnostic-models/openapiv2 imports
github.com/google/gnostic-models/compiler imports
github.com/golang/protobuf/ptypes/any: zip: not a valid zip file
go: sigs.k8s.io/controller-runtime imports
sigs.k8s.io/controller-runtime/pkg/builder imports
sigs.k8s.io/controller-runtime/pkg/client/apiutil imports
k8s.io/client-go/discovery imports
github.com/google/gnostic-models/openapiv2 imports
github.com/google/gnostic-models/compiler imports
github.com/google/gnostic-models/extensions imports
github.com/golang/protobuf/ptypes: zip: not a valid zip file
Error: failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v4": exit status 1
Usage:
kubebuilder init [flags]
Examples:
# Initialize a new project with your domain and name in copyright
kubebuilder init --plugins go/v4 --domain example.org --owner "Your name"
# Initialize a new project defining a specific project version
kubebuilder init --plugins go/v4 --project-version 3
Flags:
--domain string domain for groups (default "my.domain")
--fetch-deps ensure dependencies are downloaded (default true)
-h, --help help for init
--license string license to use to boilerplate, may be one of 'apache2', 'none' (default "apache2")
--owner string owner to add to the copyright
--project-name string name of this project
--project-version string project version (default "3")
--repo string name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.
--skip-go-version-check if specified, skip checking the Go version
Global Flags:
--plugins strings plugin keys to be used for this subcommand execution
FATA failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v4": exit status 1
原因和解決方法
問題原因:go mod代理服務(wù)器下載出錯;導(dǎo)致在下載時(shí)出現(xiàn)": zip: not a valid zip file"
通過go env GOPROXY
命令查看代理服務(wù)器:
% go env GOPROXY
https://mirrors.aliyun.com/goproxy/,https://goproxy.cn
優(yōu)先使用aliyun的代理服務(wù),調(diào)整直接使用https://goproxy.cn文章來源:http://www.zghlxwxcb.cn/news/detail-857364.html
% go env -w GOPROXY=https://goproxy.cn,direct
重新執(zhí)行kubebuilder init 正常完成文章來源地址http://www.zghlxwxcb.cn/news/detail-857364.html
% kubebuilder init --domain demo.io --plugins=go/v4
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.17.0
INFO Update dependencies:
$ go mod tidy
go: downloading github.com/onsi/ginkgo/v2 v2.14.0
go: downloading github.com/onsi/gomega v1.30.0
go: downloading github.com/stretchr/testify v1.8.4
go: downloading github.com/go-logr/zapr v1.3.0
go: downloading go.uber.org/zap v1.26.0
go: downloading go.uber.org/goleak v1.3.0
go: downloading github.com/rogpeppe/go-internal v1.10.0
go: downloading go.uber.org/multierr v1.11.0
go: downloading github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
go: downloading golang.org/x/tools v0.16.1
Next: define a resource with:
$ kubebuilder create api
到了這里,關(guān)于go mod出現(xiàn)zip: not a valid zip file的解決辦法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!