-
Notifications
You must be signed in to change notification settings - Fork 364
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
Build antrea-cni binary and release binaries without cgo #2189
Build antrea-cni binary and release binaries without cgo #2189
Conversation
Surprisingly, the antrea-cni binary is actually smaller with cgo disabled... I was expecting the opposite... $ make antrea-cni
GOOS=linux CGO_ENABLED=0 go build -o /home/abas/vmware/antrea/bin -ldflags ' -X antrea.io/antrea/pkg/version.Version=v1.1.0-dev -X antrea.io/antrea/pkg/version.GitSHA=3134f7ee -X antrea.io/antrea/pkg/version.GitTreeState=dirty -X antrea.io/antrea/pkg/version.ReleaseStatus=unreleased' antrea.io/antrea/cmd/antrea-cni
abas@ubuntu:~/vmware/antrea$ ls -l bin/antrea-cni
-rwxr-xr-x 1 abas abas 11673235 May 18 16:44 bin/antrea-cni $ make antrea-cni
GOOS=linux CGO_ENABLED=1 go build -o /home/abas/vmware/antrea/bin -ldflags ' -X antrea.io/antrea/pkg/version.Version=v1.1.0-dev -X antrea.io/antrea/pkg/version.GitSHA=3134f7ee -X antrea.io/antrea/pkg/version.GitTreeState=dirty -X antrea.io/antrea/pkg/version.ReleaseStatus=unreleased' antrea.io/antrea/cmd/antrea-cni
abas@ubuntu:~/vmware/antrea$ ls -l bin/antrea-cni
-rwxr-xr-x 1 abas abas 11741710 May 18 16:45 bin/antrea-cni |
Codecov Report
@@ Coverage Diff @@
## main #2189 +/- ##
===========================================
+ Coverage 41.02% 61.09% +20.07%
===========================================
Files 134 273 +139
Lines 16683 20646 +3963
===========================================
+ Hits 6844 12614 +5770
+ Misses 9253 6713 -2540
- Partials 586 1319 +733
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, a question left
Makefile
Outdated
.PHONY: windows-bin | ||
windows-bin: | ||
@mkdir -p $(BINDIR) | ||
GOOS=windows $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/antrea/cmd/antrea-cni antrea.io/antrea/cmd/antrea-agent | ||
GOOS=windows CGO_ENABLED=0 $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/antrea/cmd/antrea-cni | ||
GOOS=windows $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/antrea/cmd/antrea-agent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't antrea-agent run as a process on windows? Should it also have cgo disabled, assuming it could be complied on windows OS (so no cross-compiling)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder, you are correct. In the case of the antrea/antrea-windows
Docker image, we actually build the binaries without cross-compilation. Then when running on Windows in the "Docker mode" (as opposed to "containerd mode"...) we copy the antrea-agent binary to the host and run it as a host process:
antrea/build/yamls/antrea-windows.yml
Line 7 in 971d66c
cp /k/antrea/bin/* /host/k/antrea/bin/ |
f2851b2
to
1e53e11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/test-all |
antrea-cni can be installed (by the initContainer) on systems with incompatible system libraries. To increase portability, we build antrea-cni without cgo by setting CG_ENABLED to 0. Same goes for release binaries (e.g. antctl). Note that when cross-compiling, cgo is disabled by default, so there is no change there (e.g. antctl binary for macOS). It's only for native Linux amd64 builds that there is an actual change. Fixes antrea-io#2095 Signed-off-by: Antonin Bas <[email protected]>
1e53e11
to
7865e2c
Compare
@tnqn oops I forgot to sign my commit, shame on me :P I need another approval... |
/test-all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
antrea-cni can be installed (by the initContainer) on systems with
incompatible system libraries. To increase portability, we build
antrea-cni without cgo by setting CG_ENABLED to 0.
Same goes for release binaries (e.g. antctl). Note that when
cross-compiling, cgo is disabled by default, so there is no change there
(e.g. antctl binary for macOS). It's only for native Linux amd64 builds
that there is an actual change.
Fixes #2095