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

Disable cgo for all Antrea binaries #5988

Merged

Conversation

antoninbas
Copy link
Contributor

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes #5724

@antoninbas
Copy link
Contributor Author

We can revert some commits which had to be introduced to fix the UBI build specifically because cgo was enabled

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes antrea-io#5724

Signed-off-by: Antonin Bas <[email protected]>
This reverts commit 2afab06.

Signed-off-by: Antonin Bas <[email protected]>
Copy link
Contributor

@heanlan heanlan left a comment

Choose a reason for hiding this comment

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

disabling cgo for Flow-Aggregator looks good to me

Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM overall, one question.

@@ -12,30 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BUILD_TAG
FROM registry.access.redhat.com/ubi8 as antrea-build
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering why this ubi8 is no longer needed?

@xliuxu FYI, this change will conflict with your PR #5737

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the FYI. I can rebase the PR later.
BTW I think this change is to revert #5723

Copy link
Member

Choose a reason for hiding this comment

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

@luolanzone I think it's because it no longer relies on glibc shipped with ubi8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct. This change just reverts an earlier commit that I had to be introduced because of a glibc mismatch (I preserved the individual "revert" commits in the history for this PR, so you can take a look). Now that we disable cgo, the Antrea binaries no longer have a dependency on libc, and if there is a mismatch in version between the libc included in the golang Docker image and the libc included in the ubi Docker image, it doesn't matter anymore. Therefore we can revert to the golang Docker image, to avoid having to install Go manually.

Copy link
Contributor

@wenyingd wenyingd left a comment

Choose a reason for hiding this comment

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

Can we also disable cgo PHONY "bin" in Makefile ? I am asking this because we have another issue #5967 for VM agent case, which may build antrea-agent for VM scenario inside a Docker container runtime using Ubuntu 22.04, but run it on a VM on a different Linux OS version (e.g. ubuntu 18.04), then agent may fail because of the missing libraries.

-coverprofile=.coverage/coverage-unit.txt -covermode=atomic \
antrea.io/antrea/cmd/... antrea.io/antrea/pkg/... antrea.io/antrea/multicluster/cmd/... antrea.io/antrea/multicluster/controllers/...

.PHONY: .windows-test-unit
.windows-test-unit: .coverage
@echo
@echo "==> Running unit tests <=="
$(GO) test -race -coverpkg=antrea.io/antrea/cmd/...,antrea.io/antrea/pkg/... \
CGO_ENABLED=1 $(GO) test -race -coverpkg=antrea.io/antrea/cmd/...,antrea.io/antrea/pkg/... \
Copy link
Contributor

Choose a reason for hiding this comment

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

I used to see build errors with enabling cgo on Windows, does this change work?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cgo is required to run the race detector:

On macOS, the race detector has been rewritten not to use cgo: race-detector-enabled programs can be built and run without Xcode. On Linux and other Unix systems, and on Windows, a host C toolchain is required to use the race detector.

This is the only place where we enable it. By default, cgo is now disabled for every build operation.

@wenyingd
Copy link
Contributor

/test-vm-e2e

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

-coverprofile=.coverage/coverage-unit.txt -covermode=atomic \
antrea.io/antrea/cmd/... antrea.io/antrea/pkg/... antrea.io/antrea/multicluster/cmd/... antrea.io/antrea/multicluster/controllers/...

.PHONY: .windows-test-unit
.windows-test-unit: .coverage
@echo
@echo "==> Running unit tests <=="
$(GO) test -race -coverpkg=antrea.io/antrea/cmd/...,antrea.io/antrea/pkg/... \
CGO_ENABLED=1 $(GO) test -race -coverpkg=antrea.io/antrea/cmd/...,antrea.io/antrea/pkg/... \
Copy link
Member

Choose a reason for hiding this comment

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

@@ -12,30 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BUILD_TAG
FROM registry.access.redhat.com/ubi8 as antrea-build
Copy link
Member

Choose a reason for hiding this comment

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

@luolanzone I think it's because it no longer relies on glibc shipped with ubi8.

@antoninbas
Copy link
Contributor Author

Can we also disable cgo PHONY "bin" in Makefile ? I am asking this because we have another issue #5967 for VM agent case, which may build antrea-agent for VM scenario inside a Docker container runtime using Ubuntu 22.04, but run it on a VM on a different Linux OS version (e.g. ubuntu 18.04), then agent may fail because of the missing libraries.

Cgo is disabled for everything now (except when enabling the race detector for unit tests).
The only places where cgo is enabled will be where you see an explicit CGO_ENABLED=1.

@antoninbas
Copy link
Contributor Author

/test-vm-e2e

@antoninbas
Copy link
Contributor Author

/test-all

@antoninbas
Copy link
Contributor Author

One test case is currently failing for test-vm-e2e. This is unrelated to this PR and is being addressed separately in #6008

@antoninbas antoninbas merged commit 9fee7d2 into antrea-io:main Feb 21, 2024
49 of 54 checks passed
@antoninbas antoninbas deleted the disable-cgo-for-all-antrea-binaries branch February 21, 2024 04:48
@antoninbas antoninbas added the action/release-note Indicates a PR that should be included in release notes. label Feb 21, 2024
@antoninbas
Copy link
Contributor Author

@wenyingd does this need to be backported to older releases?

@wenyingd
Copy link
Contributor

@wenyingd does this need to be backported to older releases?

Sorry for missing the ask, yes, we need to back port the change. cc @luolanzone

luolanzone pushed a commit to luolanzone/antrea that referenced this pull request Mar 20, 2024
* Disable cgo for all Antrea binaries

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes antrea-io#5724

* Revert "Add git to antrea-build image for UBI build (antrea-io#5727)"

This reverts commit 2f8441b.

* Revert "Fix antrea-ubi image build (antrea-io#5723)"

This reverts commit 2afab06.

---------

Signed-off-by: Antonin Bas <[email protected]>
@luolanzone
Copy link
Contributor

I have backported this to v1.15, I suppose v1.14 is also needed? @antoninbas @wenyingd
Do we need to back port to v1.13? I think we still need to do a patch release for v1.13 this time.

@wenyingd
Copy link
Contributor

I suppose v1.14 is also needed? @antoninbas @wenyingd Do we need to back port to v1.13? I think we still need to do a patch release for v1.13 this time.

Focusing on VM Agent case, it is supposed to be required after we bump up the base Ubuntu to 22.04 in the antrea images. So we shall back port the change to all the versions which are still in the maintenance cycle.

antoninbas added a commit to antoninbas/antrea that referenced this pull request Mar 20, 2024
Because we are now disabling cgo when building all Antrea binaries,
there is no need to install Go manually when building the UBI images. It
was required before because of incompatibility between the glibc
versions in the golang image and the ubi8 base image. We can now use the
standard golang image to compile the Antrea binaries (without cgo, there
is no dependency on glibc), then copy these binaries to the ubi8 image.

PR antrea-io#5988, which disabled cgo,
removed the unnecessary code from Dockerfile.build.ubi, but not from
the other Dockerfiles (Dockerfile.build.agent.ubi and
Dockerfile.build.controller.ubi).

Signed-off-by: Antonin Bas <[email protected]>
tnqn pushed a commit that referenced this pull request Mar 21, 2024
* Disable cgo for all Antrea binaries

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes #5724

* Revert "Add git to antrea-build image for UBI build (#5727)"

This reverts commit 2f8441b.

* Revert "Fix antrea-ubi image build (#5723)"

This reverts commit 2afab06.

---------

Signed-off-by: Antonin Bas <[email protected]>
antoninbas added a commit that referenced this pull request Mar 21, 2024
Because we are now disabling cgo when building all Antrea binaries,
there is no need to install Go manually when building the UBI images. It
was required before because of incompatibility between the glibc
versions in the golang image and the ubi8 base image. We can now use the
standard golang image to compile the Antrea binaries (without cgo, there
is no dependency on glibc), then copy these binaries to the ubi8 image.

PR #5988, which disabled cgo,
removed the unnecessary code from Dockerfile.build.ubi, but not from
the other Dockerfiles (Dockerfile.build.agent.ubi and
Dockerfile.build.controller.ubi).

Signed-off-by: Antonin Bas <[email protected]>
luolanzone pushed a commit to luolanzone/antrea that referenced this pull request Mar 22, 2024
* Disable cgo for all Antrea binaries

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes antrea-io#5724

* Revert "Add git to antrea-build image for UBI build (antrea-io#5727)"

This reverts commit 2f8441b.

* Revert "Fix antrea-ubi image build (antrea-io#5723)"

This reverts commit 2afab06.

---------

Signed-off-by: Antonin Bas <[email protected]>
tnqn pushed a commit that referenced this pull request Mar 25, 2024
* Disable cgo for all Antrea binaries

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes #5724

* Revert "Add git to antrea-build image for UBI build (#5727)"

This reverts commit 2f8441b.

* Revert "Fix antrea-ubi image build (#5723)"

This reverts commit 2afab06.

---------

Signed-off-by: Antonin Bas <[email protected]>
luolanzone pushed a commit to luolanzone/antrea that referenced this pull request Mar 26, 2024
* Disable cgo for all Antrea binaries

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes antrea-io#5724

* Revert "Add git to antrea-build image for UBI build (antrea-io#5727)"

This reverts commit 2f8441b.

* Revert "Fix antrea-ubi image build (antrea-io#5723)"

This reverts commit 2afab06.

---------

Signed-off-by: Antonin Bas <[email protected]>
tnqn pushed a commit that referenced this pull request Mar 27, 2024
* Disable cgo for all Antrea binaries

Instead of selectively disabling cgo for some binaries (e.g., release
assets), we now unconditionally disable cgo for all binaries, even those
that only run inside the container image for which they were built
(e.g., antrea-controller). After some analysis, there seems to be no
downside in doing this. We also get some benefits such as reduced build
time for the default make command.

Fixes #5724

* Revert "Add git to antrea-build image for UBI build (#5727)"

This reverts commit 2f8441b.

* Revert "Fix antrea-ubi image build (#5723)"

This reverts commit 2afab06.

---------

Signed-off-by: Antonin Bas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate disabling cgo for all Antrea binaries
6 participants