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


    最近在准备学习下kubernetes operate的开发,在通过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
  • 相关阅读:
    基于PHP+MySQL蛋糕甜点销售网站的设计与开发
    推荐一款实用的用户画像工具--快鲸scrm
    MATLAB程序设计与应用 4.2 程序控制结构
    C++基础与深度解析 | 输入与输出 | 文件与内存操作 | 流的状态、定位与同步
    R语言—向量
    [ROS笔记本]QT5问题cmake编译
    Java面试题及答案整理( 2022最新版,持续更新)
    「秋招」这份各大厂面试万金油手册,吃透保你进大厂
    并发、并行和多线程关系
    第五篇,STM32系统定时器和通用定时器编程
  • 原文地址:https://blog.csdn.net/Mr_rain/article/details/136434520