Skip to content
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

Conversation

antoninbas
Copy link
Contributor

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

@antoninbas antoninbas requested review from tnqn and jianjuns May 18, 2021 23:49
@antoninbas
Copy link
Contributor Author

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

@antoninbas antoninbas added the area/build-release Issues or PRs related to building and releasing label May 18, 2021
@antoninbas antoninbas added this to the Antrea v1.1 release milestone May 18, 2021
@codecov-commenter
Copy link

codecov-commenter commented May 19, 2021

Codecov Report

Merging #2189 (1e53e11) into main (5c5cae5) will increase coverage by 20.07%.
The diff coverage is n/a.

❗ Current head 1e53e11 differs from pull request most recent head 7865e2c. Consider uploading reports for the commit 7865e2c to get more accurate results
Impacted file tree graph

@@             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     
Flag Coverage Δ
e2e-tests ∅ <ø> (?)
kind-e2e-tests 52.03% <ø> (?)
unit-tests 41.04% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/apiserver/handlers/webhook/mutation_labels.go 24.71% <0.00%> (ø)
...er/crdmirroring/crdhandler/clusternetworkpolicy.go 13.46% <0.00%> (ø)
...lientset/versioned/typed/security/v1alpha1/tier.go 27.39% <0.00%> (ø)
...ormers/externalversions/core/v1alpha2/interface.go 100.00% <0.00%> (ø)
pkg/apiserver/apiserver.go 89.51% <0.00%> (ø)
...formers/externalversions/security/v1alpha1/tier.go 64.28% <0.00%> (ø)
pkg/features/antrea_features.go 16.66% <0.00%> (ø)
pkg/legacyapis/system/v1beta1/register.go 90.00% <0.00%> (ø)
pkg/agent/metrics/prometheus.go 27.27% <0.00%> (ø)
...s/externalversions/clusterinformation/interface.go 0.00% <0.00%> (ø)
... and 229 more

tnqn
tnqn previously approved these changes May 19, 2021
Copy link
Member

@tnqn tnqn left a 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
Copy link
Member

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)?

Copy link
Contributor Author

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:

cp /k/antrea/bin/* /host/k/antrea/bin/
. So it's definitely a valid assumption.

@antoninbas antoninbas force-pushed the build-antrea-cni-and-release-assets-without-cgo branch from f2851b2 to 1e53e11 Compare May 19, 2021 17:55
@antoninbas antoninbas requested a review from tnqn May 19, 2021 17:59
tnqn
tnqn previously approved these changes May 20, 2021
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@antoninbas
Copy link
Contributor Author

/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]>
@antoninbas antoninbas force-pushed the build-antrea-cni-and-release-assets-without-cgo branch from 1e53e11 to 7865e2c Compare May 20, 2021 19:06
@antoninbas
Copy link
Contributor Author

@tnqn oops I forgot to sign my commit, shame on me :P I need another approval...

@antoninbas
Copy link
Contributor Author

/test-all

Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@antoninbas antoninbas merged commit 55994b1 into antrea-io:main May 20, 2021
@antoninbas antoninbas deleted the build-antrea-cni-and-release-assets-without-cgo branch May 20, 2021 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build-release Issues or PRs related to building and releasing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some deployed cni plugins are not statically compiled
4 participants