Skip to content

Supported to compile statically? #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
luxas opened this issue Apr 18, 2016 · 5 comments
Closed

Supported to compile statically? #1227

luxas opened this issue Apr 18, 2016 · 5 comments

Comments

@luxas
Copy link

luxas commented Apr 18, 2016

kubelet in Kubernetes depends on cAdvisor, and if kubelet is compiled statically, it complains loudly that cAdvisor isn't bundled and exits.

So I wonder if there are some technical difficulties to compile cAdvisor statically?
I haven't tested it yet

If cAdvisor works fine when it's statically built, we may close this and open one on the Kubernetes side.

@luxas
Copy link
Author

luxas commented Apr 18, 2016

/cc @vishh

@djtm
Copy link

djtm commented Apr 22, 2016

Static compile works fine, haven't gone through the tests though:

export GOPATH=~/src/go
export PATH="$PATH:$GOPATH/bin"
apt-get install golang-go # build does not work in alpine
# https://github.com/kubernetes/kubernetes/issues/19464
git clone --depth 1 https://github.com/google/cadvisor.git
go get github.com/tools/godep
go get -d github.com/google/cadvisor
# build statically for scratch image
godep go build --ldflags '-extldflags "-static"' github.com/google/cadvisor

The important part is --ldflags '-extldflags "-static"'
Static scratch image at https://hub.docker.com/r/djtm/cadvisor-386/
You can use the same run command as usual.

@vishh
Copy link
Contributor

vishh commented Apr 22, 2016

If you can push a patch with this change, we can have the CI run all the tests.

@luxas
Copy link
Author

luxas commented Apr 22, 2016

It seems like it's these files that are using cgo:

  • utils/cpuload/netlink/defs.go
  • utils/procfs/jiffy.go

Of course, the best way of fixing it would be to workaround/not have to depend on these C libraries, but I guess it's just fine with static CGO linking.
I'm sending a patch so we'll see if it passes.

@dashpole
Copy link
Collaborator

closing via #1299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants