当前位置:   article > 正文

go mod出现zip: not a valid zip file的解决办法

zip: not a valid zip file

最近在准备学习下kubernetes operator的开发,在通过kubebuilder 脚手架创建operator项目时,出现报错:
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

原因和解决方法

问题原因:go mod代理服务器下载出错;导致在下载时出现": zip: not a valid zip file"

通过go env GOPROXY命令查看代理服务器:

% go env GOPROXY
https://mirrors.aliyun.com/goproxy/,https://goproxy.cn
  • 1
  • 2

优先使用aliyun的代理服务,调整直接使用https://goproxy.cn

% go env -w GOPROXY=https://goproxy.cn,direct
  • 1

重新执行kubebuilder init 正常完成

% 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/455335
推荐阅读
相关标签
  

闽ICP备14008679号