Kubernetes在Ubuntu中找不到正确的Go语言版本。

huangapple go评论81阅读模式
英文:

The kubernetes can't find correct go in ubuntu

问题

我的操作系统是ubuntu 14.04.3服务器,我想要构建kubernetes

首先,我使用"apt-get"命令安装Golang,但是版本是1.2.1,所以我使用apt-get --purge autoremove命令将其卸载,并从golang网站安装最新的1.5.1版本。

但是执行make命令时,似乎kubernetes始终认为当前的golang版本是1.2.1

$ make
hack/build-go.sh
+++ [1203 06:20:30] Building go targets for linux/amd64:
    cmd/kube-proxy
    cmd/kube-apiserver
    cmd/kube-controller-manager
    cmd/kubelet
    cmd/kubemark
    cmd/hyperkube
    cmd/linkcheck
    plugin/cmd/kube-scheduler
    cmd/kubectl
    cmd/integration
    cmd/gendocs
    cmd/genkubedocs
    cmd/genman
    cmd/mungedocs
    cmd/genbashcomp
    cmd/genconversion
    cmd/gendeepcopy
    cmd/genswaggertypedocs
    examples/k8petstore/web-server/src
    github.com/onsi/ginkgo/ginkgo
    test/e2e/e2e.test
+++ [1203 06:20:30] +++ Warning: stdlib pkg with cgo flag not found.
+++ [1203 06:20:30] +++ Warning: stdlib pkg cannot be rebuilt since /usr/local/go/pkg is not writable by nan
+++ [1203 06:20:30] +++ Warning: Make /usr/local/go/pkg writable for nan for a one-time stdlib install, Or
+++ [1203 06:20:30] +++ Warning: Rebuild stdlib using the command 'CGO_ENABLED=0 go install -a -installsuffix cgo std'
+++ [1203 06:20:30] +++ Falling back to go build, which is slower
    # k8s.io/kubernetes/pkg/util/yaml
_output/local/go/src/k8s.io/kubernetes/pkg/util/yaml/decoder.go:26: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/ghodss/yaml.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/util/validation
_output/local/go/src/k8s.io/kubernetes/pkg/util/validation/errors.go:23: import /home/nan/kubernetes/_output/local/go/pkg/linux_amd64/k8s.io/kubernetes/pkg/util/errors.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/api/resource
_output/local/go/src/k8s.io/kubernetes/pkg/api/resource/quantity.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/speter.net/go/exp/math/dec/inf.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/spf13/cobra
Godeps/_workspace/src/github.com/spf13/cobra/command.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/inconshreveable/mousetrap.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/util/iptables
_output/local/go/src/k8s.io/kubernetes/pkg/util/iptables/iptables.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/coreos/go-semver/semver.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/prometheus/common/expfmt
Godeps/_workspace/src/github.com/prometheus/common/expfmt/decode.go:23: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/prometheus/client_model/go.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/emicklei/go-restful
Godeps/_workspace/src/github.com/emicklei/go-restful/container.go:16: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/emicklei/go-restful/log.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
!!! Error in /home/nan/kubernetes/hack/lib/golang.sh:376
  'CGO_ENABLED=0 go build -o "${outfile}" "${goflags[@]:+${goflags[@]}}" -ldflags "${goldflags}" "${binary}"' exited with status 2
Call stack:
  1: /home/nan/kubernetes/hack/lib/golang.sh:376 kube::golang::build_binaries_for_platform(...)
  2: /home/nan/kubernetes/hack/lib/golang.sh:535 kube::golang::build_binaries(...)
  3: hack/build-go.sh:26 main(...)
Exiting with status 1
!!! Error in /home/nan/kubernetes/hack/lib/golang.sh:456
  '( kube::golang::setup_env; local host_platform; host_platform=$(kube::golang::host_platform); local goflags goldflags; eval "goflags=(${KUBE_GOFLAGS:-})"; goldflags="${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)"; local use_go_build; local -a targets=(); local arg; for arg in "$@";
do
    if [[ "${arg}" == "--use_go_build" ]]; then
        use_go_build=true;
    else
        if [[ "${arg}" == -* ]]; then
            goflags+=("${arg}");
        else
            targets+=("${arg}");
        fi;
    fi;
done; if [[ ${#targets[@]} -eq 0 ]]; then
    targets=("${KUBE_ALL_TARGETS[@]}");
fi; local -a platforms=("${KUBE_BUILD_PLATFORMS[@]:+${KUBE_BUILD_PLATFORMS[@]}}"); if [[ ${#platforms[@]} -eq 0 ]]; then
    platforms=("${host_platform}");
fi; local binaries; binaries=($(kube::golang::binaries_from_targets "${targets[@]}")); local parallel=false; if [[ ${#platforms[@]} -gt 1 ]]; then
    local gigs; gigs=$(kube::golang::get_physmem); if [[ ${gigs} -ge ${KUBE_PARALLEL_BUILD_MEMORY} ]]; then
        kube::log::status "Multiple platforms requested and available ${gigs}G >= threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in parallel"; parallel=true;
    else
        kube::log::status "Multiple platforms requested, but available ${gigs}G < threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in serial"; parallel=false;
    fi;
fi; if [[ "${parallel}" == "true" ]]; then
    kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}"; local platform; for platform in "${platforms[@]}";
    do
        ( kube::golang::set_platform_envs "${platform}"; kube::log::status "${platform}: go build started"; kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}; kube::log::status "${platform}: go build finished" ) &> "/tmp//${platform//\//_}.build" &;
    done; local fails=0; for job in $(jobs -p);
    do
        wait ${job} || let "fails+=1";
    done; for platform in "${platforms[@]}";
    do
        cat "/tmp//${platform//\//_}.build";
    done; exit ${fails};
else
    for platform in "${platforms[@]}";
    do
        kube::log::status "Building go targets for ${platform}:" "${targets[@]}"; kube::golang::set_platform_envs "${platform}"; kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-};
    done;
fi )' exited with status 1
Call stack:
  1: /home/nan/kubernetes/hack/lib/golang.sh:456 kube::golang::build_binaries(...)
  2: hack/build-go.sh:26 main(...)
Exiting with status 1
make: *** [all] Error 1

但是在"PATH"中的go1.5.1

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin
$ which go
/usr/local/go/bin/go
$ go version
go version go1.5.1 linux/amd64

那么我该如何解决这个问题?

英文:

My OS is ubuntu 14.04.3 Server, and I want to build kubernetes.

Firstly, I use "apt-get" command install Golang, but the version is 1.2.1, so I use apt-get --purge autoremove command to remove it.And install the newest 1.5.1 from golang website.

But executing make command, it seems kubernetes always "think" current golang is 1.2.1:

$ make
hack/build-go.sh
+++ [1203 06:20:30] Building go targets for linux/amd64:
    cmd/kube-proxy
    cmd/kube-apiserver
    cmd/kube-controller-manager
    cmd/kubelet
    cmd/kubemark
    cmd/hyperkube
    cmd/linkcheck
    plugin/cmd/kube-scheduler
    cmd/kubectl
    cmd/integration
    cmd/gendocs
    cmd/genkubedocs
    cmd/genman
    cmd/mungedocs
    cmd/genbashcomp
    cmd/genconversion
    cmd/gendeepcopy
    cmd/genswaggertypedocs
    examples/k8petstore/web-server/src
    github.com/onsi/ginkgo/ginkgo
    test/e2e/e2e.test
+++ [1203 06:20:30] +++ Warning: stdlib pkg with cgo flag not found.
+++ [1203 06:20:30] +++ Warning: stdlib pkg cannot be rebuilt since /usr/local/go/pkg is not writable by nan
+++ [1203 06:20:30] +++ Warning: Make /usr/local/go/pkg writable for nan for a one-time stdlib install, Or
+++ [1203 06:20:30] +++ Warning: Rebuild stdlib using the command &#39;CGO_ENABLED=0 go install -a -installsuffix cgo std&#39;
+++ [1203 06:20:30] +++ Falling back to go build, which is slower
    # k8s.io/kubernetes/pkg/util/yaml
_output/local/go/src/k8s.io/kubernetes/pkg/util/yaml/decoder.go:26: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/ghodss/yaml.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/util/validation
_output/local/go/src/k8s.io/kubernetes/pkg/util/validation/errors.go:23: import /home/nan/kubernetes/_output/local/go/pkg/linux_amd64/k8s.io/kubernetes/pkg/util/errors.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/api/resource
_output/local/go/src/k8s.io/kubernetes/pkg/api/resource/quantity.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/speter.net/go/exp/math/dec/inf.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/spf13/cobra
Godeps/_workspace/src/github.com/spf13/cobra/command.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/inconshreveable/mousetrap.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/util/iptables
_output/local/go/src/k8s.io/kubernetes/pkg/util/iptables/iptables.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/coreos/go-semver/semver.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/prometheus/common/expfmt
Godeps/_workspace/src/github.com/prometheus/common/expfmt/decode.go:23: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/prometheus/client_model/go.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/emicklei/go-restful
Godeps/_workspace/src/github.com/emicklei/go-restful/container.go:16: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/emicklei/go-restful/log.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
!!! Error in /home/nan/kubernetes/hack/lib/golang.sh:376
  &#39;CGO_ENABLED=0 go build -o &quot;${outfile}&quot; &quot;${goflags[@]:+${goflags[@]}}&quot; -ldflags &quot;${goldflags}&quot; &quot;${binary}&quot;&#39; exited with status 2
Call stack:
  1: /home/nan/kubernetes/hack/lib/golang.sh:376 kube::golang::build_binaries_for_platform(...)
  2: /home/nan/kubernetes/hack/lib/golang.sh:535 kube::golang::build_binaries(...)
  3: hack/build-go.sh:26 main(...)
Exiting with status 1
!!! Error in /home/nan/kubernetes/hack/lib/golang.sh:456
  &#39;( kube::golang::setup_env; local host_platform; host_platform=$(kube::golang::host_platform); local goflags goldflags; eval &quot;goflags=(${KUBE_GOFLAGS:-})&quot;; goldflags=&quot;${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)&quot;; local use_go_build; local -a targets=(); local arg; for arg in &quot;$@&quot;;
do
    if [[ &quot;${arg}&quot; == &quot;--use_go_build&quot; ]]; then
        use_go_build=true;
    else
        if [[ &quot;${arg}&quot; == -* ]]; then
            goflags+=(&quot;${arg}&quot;);
        else
            targets+=(&quot;${arg}&quot;);
        fi;
    fi;
done; if [[ ${#targets[@]} -eq 0 ]]; then
    targets=(&quot;${KUBE_ALL_TARGETS[@]}&quot;);
fi; local -a platforms=(&quot;${KUBE_BUILD_PLATFORMS[@]:+${KUBE_BUILD_PLATFORMS[@]}}&quot;); if [[ ${#platforms[@]} -eq 0 ]]; then
    platforms=(&quot;${host_platform}&quot;);
fi; local binaries; binaries=($(kube::golang::binaries_from_targets &quot;${targets[@]}&quot;)); local parallel=false; if [[ ${#platforms[@]} -gt 1 ]]; then
    local gigs; gigs=$(kube::golang::get_physmem); if [[ ${gigs} -ge ${KUBE_PARALLEL_BUILD_MEMORY} ]]; then
        kube::log::status &quot;Multiple platforms requested and available ${gigs}G &gt;= threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in parallel&quot;; parallel=true;
    else
        kube::log::status &quot;Multiple platforms requested, but available ${gigs}G &lt; threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in serial&quot;; parallel=false;
    fi;
fi; if [[ &quot;${parallel}&quot; == &quot;true&quot; ]]; then
    kube::log::status &quot;Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):&quot; &quot;${targets[@]}&quot;; local platform; for platform in &quot;${platforms[@]}&quot;;
    do
        ( kube::golang::set_platform_envs &quot;${platform}&quot;; kube::log::status &quot;${platform}: go build started&quot;; kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}; kube::log::status &quot;${platform}: go build finished&quot; ) &amp;&gt; &quot;/tmp//${platform//\//_}.build&quot; &amp;
    done; local fails=0; for job in $(jobs -p);
    do
        wait ${job} || let &quot;fails+=1&quot;;
    done; for platform in &quot;${platforms[@]}&quot;;
    do
        cat &quot;/tmp//${platform//\//_}.build&quot;;
    done; exit ${fails};
else
    for platform in &quot;${platforms[@]}&quot;;
    do
        kube::log::status &quot;Building go targets for ${platform}:&quot; &quot;${targets[@]}&quot;; kube::golang::set_platform_envs &quot;${platform}&quot;; kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-};
    done;
fi )&#39; exited with status 1
Call stack:
  1: /home/nan/kubernetes/hack/lib/golang.sh:456 kube::golang::build_binaries(...)
  2: hack/build-go.sh:26 main(...)
Exiting with status 1
make: *** [all] Error 1

But the go in "PATH" is 1.5.1:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin
$ which go
/usr/local/go/bin/go
$ go version
go version go1.5.1 linux/amd64

So how can I fix this issue?

答案1

得分: 1

根据“如何完全删除一个软件包?”中的解释,sudo apt-get --purge autoremove 可能已经完全删除了 go。但这并不意味着它已经清理了之前编译的内容。

确保在执行 make clean 后删除 /home/nan/kubernetes/Godeps/_workspace/home/nan/kubernetes/_output 目录(参见 issue 16771)。
确保 /usr/local/go/pkg 目录对用户 nan 有写权限(参见 hack/lib/golang.sh)。

最后,issue 16229 提到:

> 至少更新文档以指示不能使用 go>1.4。

所以尝试只安装 go 1.4.x。

更新:OP Nan Xiao评论中报告说已经成功使用 go 1.5.1 或 1.5.2 构建了它。

英文:

As explained in "How can you completely remove a package?", a sudo apt-get --purge autoremove might have removed go completely.
But that doesn't mean it has cleaned what was compiled before

Make sure that /home/nan/kubernetes/Godeps/_workspace and /home/nan/kubernetes/_output are deleted after a make clean (See issue 16771).
Make sure /usr/local/go/pkg is writable for the user nan. (See hack/lib/golang.sh)

Finally, issue 16229 mentions:

> Would be nice to at least update the docs to indicate that you can't use go>1.4.

So try and install go 1.4.x only.

Update: the OP Nan Xiao reports in the comments having managed to build it with go 1.5.1 or 1.5.2 without any more issue.

huangapple
  • 本文由 发表于 2015年12月4日 11:45:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/34080574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定