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

Enable multi-platform support for bridge marker image builds #77

Merged

Conversation

ashokpariya0
Copy link
Contributor

@ashokpariya0 ashokpariya0 commented Nov 25, 2024

These changes enable building and pushing bridge marker container images for multiple platforms (amd64, s390x, arm64) from a single Dockerfile. Enhanced multi-platform support in the build process by adding a PLATFORMS argument in the Makefile for amd64, s390x, and arm64 architectures. Multi-platform build support is provided for both Docker and Podman container runtimes.

What this PR does / why we need it:
The upstream bridge-marker image ([link](https://quay.io/repository/kubevirt/bridge-marker?tab=tags&tag=latest)) currently supports only the amd64 architecture. The proposed changes in this PR enable multi-platform support for the bridge-marker image, broadening its compatibility to include additional architectures.

Special notes for your reviewer:
Multiplatform build instruction: https://gist.github.com/ashokpariya0/30d5efc0e9525c266ef9e65fe4291860

Multi-platform build support is enabled for both Docker and Podman container runtimes, and the necessary changes have been made accordingly.
The PLATFORMS variable defines the target platforms for building the manager image, allowing support for multiple architectures.

To use this feature, you need to:

Release note:

None

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 25, 2024
@kubevirt-bot
Copy link

Hi @ashokpariya0. Thanks for your PR.

I'm waiting for a kubevirt member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Collaborator

@oshoval oshoval left a comment

Choose a reason for hiding this comment

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

Thanks looks great

Makefile Outdated
@@ -1,6 +1,16 @@
REGISTRY ?= quay.io/kubevirt
IMAGE_TAG ?= latest
IMAGE_GIT_TAG ?= $(shell git describe --abbrev=8 --tags)
PLATFORMS ?= linux/amd64,linux/s390x
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets see please we are good to with having s390x by default, or better do the auto detection trick as done on cnao please
it is important to have fast deployment generally speaking imho

Makefile Outdated
Comment on lines 12 to 13
MARKER_IMAGE_TAGGED_1 := ${REGISTRY}/bridge-marker:${IMAGE_TAG}
MARKER_IMAGE_TAGGED_2 := ${REGISTRY}/bridge-marker:${IMAGE_GIT_TAG}
Copy link
Collaborator

Choose a reason for hiding this comment

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

please renamed to MARKER_IMAGE_TAGGED
and MARKER_IMAGE_GIT_TAGGED

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Makefile Outdated
build-multiarch-marker-podman:
ARCH=$(ARCH) PLATFORMS=$(PLATFORMS) MARKER_IMAGE_TAGGED_1=$(MARKER_IMAGE_TAGGED_1) MARKER_IMAGE_TAGGED_2=$(MARKER_IMAGE_TAGGED_2) ./hack/build-marker-podman.sh

.PHONY: build build-multiarch-marker-docker build-multiarch-marker-podman format docker-build docker-push manifests cluster-up cluster-down cluster-sync vendor marker tools
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use one per line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

build/Dockerfile Outdated
RUN dnf install -y tar gzip jq && dnf clean all
RUN ARCH=$(uname -m | sed 's/x86_64/amd64/') && \
GO_VERSION=$(curl -L -s "https://go.dev/dl/?mode=json" | jq -r '.[0].version') && \
curl -L "https://go.dev/dl/${GO_VERSION}.linux-${ARCH}.tar.gz" -o go.tar.gz && \
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets take go version from go.mod please, as done on other network repos
easier to maintain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in latest commit.

build/Dockerfile Outdated
rm go.tar.gz
ENV PATH=$PATH:/usr/local/go/bin
WORKDIR /go/src/bridge-marker
COPY . .
Copy link
Collaborator

Choose a reason for hiding this comment

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

please see k8snetworkplumbingwg/ovs-cni#336
nice to copy the go.mod / go.sum, and then have a layer of go mod download
and just at the end the copy . . in order to have docker layers that enable caching better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS"

BUILD_ARGS="--no-cache --build-arg BUILD_ARCH=$ARCH -f build/Dockerfile -t $MARKER_IMAGE_TAGGED_1 -t $MARKER_IMAGE_TAGGED_2 . --push"
Copy link
Collaborator

Choose a reason for hiding this comment

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

why --no-cache ?
we do need it at least locally usually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in latest commit.


IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS"

# Remove any existing manifests and images
Copy link
Collaborator

Choose a reason for hiding this comment

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

please drop comments all over, unless non trivial


for platform in "${PLATFORM_LIST[@]}"; do
podman build \
--no-cache \
Copy link
Collaborator

Choose a reason for hiding this comment

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

why no cache ?
speed is important please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

if ! docker buildx > /dev/null 2>&1; then
mkdir -p ~/.docker/cli-plugins
BUILDX_VERSION=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | jq -r .tag_name)
curl -L https://github.com/docker/buildx/releases/download/"${BUILDX_VERSION}"/buildx-"${BUILDX_VERSION}".linux-amd64 --output ~/.docker/cli-plugins/docker-buildx
Copy link
Collaborator

Choose a reason for hiding this comment

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

linux-amd64 hardcoded, is it fine? or we want multi support
what if compiled directly on non amd64, (not cross) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -2,7 +2,8 @@

destination=$1
version=$(grep "^go " go.mod |awk '{print $2}')
tarball=go$version.linux-amd64.tar.gz
arch=$(uname -m | sed 's/x86_64/amd64/')
Copy link
Collaborator

@oshoval oshoval Dec 1, 2024

Choose a reason for hiding this comment

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

lets add auto detection please ?
like kubevirt/cluster-network-addons-operator#1928

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added auto detection as default mode.

Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't it be ? (unless for go binary the naming are different)
uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes added for arm64.

@ashokpariya0 ashokpariya0 force-pushed the enable-multi-platform-bridge-marker branch from b59b33f to d1c0939 Compare December 3, 2024 07:30
@ashokpariya0
Copy link
Contributor Author

@oshoval All review comments have been addressed, Please take look.

These changes enable building and pushing bridge marker container images for multiple
platforms (amd64, s390x, arm64) from a single Dockerfile.
Enhanced multi-platform support in the build process by adding a PLATFORMS
argument in the Makefile for amd64, s390x, and arm64 architectures.
Multi-platform build support is provided for both Docker and Podman container runtimes.

Signed-off-by: Ashok Pariya <[email protected]>
@ashokpariya0 ashokpariya0 force-pushed the enable-multi-platform-bridge-marker branch from d1c0939 to 022e5e2 Compare December 3, 2024 07:49
Copy link
Collaborator

@oshoval oshoval left a comment

Choose a reason for hiding this comment

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

Looks great, thank you

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2024
@oshoval
Copy link
Collaborator

oshoval commented Dec 3, 2024

@RamLavi @qinqon
please take a look

@@ -2,7 +2,8 @@

destination=$1
version=$(grep "^go " go.mod |awk '{print $2}')
tarball=go$version.linux-amd64.tar.gz
arch=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
Copy link
Collaborator

@oshoval oshoval Dec 3, 2024

Choose a reason for hiding this comment

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

kubevirt/kubesecondarydns@d03ce8e

here the logic is bit different (for s390x), are both fine ? or one should be fixed
thanks

Copy link
Contributor Author

@ashokpariya0 ashokpariya0 Dec 3, 2024

Choose a reason for hiding this comment

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

kubevirt/kubesecondarydns@d03ce8e

Both are same for s390x case.
Both approaches are fine. However, one thing to note is that linux/ppc64le will fail with [this commit](kubevirt/kubesecondarydns@d03ce8e), as it explicitly supports only amd64, arm64, and s390x.

Copy link
Collaborator

@oshoval oshoval Dec 3, 2024

Choose a reason for hiding this comment

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

thank you
i think we dont support ppc64le atm, please raise it there as well if you want (for visibility)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you i think we dont support ppc64le atm, please raise it there as well if you want (for visibility)

okay, I can see for ipam controller (https://github.com/kubevirt/ipam-extensions/blob/925bee6139751fcb241a435bae8b79ce1dfce595/Makefile#L121C50-L121C63)

Copy link
Collaborator

@oshoval oshoval Dec 3, 2024

Choose a reason for hiding this comment

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

yes but i dont think we need to support ppc64le generally speaking on other sig network repos
@phoracek please keep me honest here, i think we discussed it once

EDIT - anyhow, imho, even if we need it, it should be on a follow-up all over,
not to be mixed with the current effort which lays the foundations and support for new archs already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oshoval Just to inform you, I noticed that linux/ppc64le is supported for components like the bridge-operator, OVS, Multus CNI, etc.

ENV PATH=$PATH:/usr/local/go/bin
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o build/_output/bin/marker github.com/kubevirt/bridge-marker/cmd/marker
Copy link
Collaborator

@oshoval oshoval Dec 3, 2024

Choose a reason for hiding this comment

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

imho it is better to be explicit with what we build please
./cmd/marker

EDIT - as we spoke, since it was like that, lets keep it

@oshoval
Copy link
Collaborator

oshoval commented Dec 10, 2024

Thanks
/lgtm

@phoracek
can you please take a look ?

@phoracek
Copy link
Member

/retest

Copy link
Member

@phoracek phoracek left a comment

Choose a reason for hiding this comment

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

/approve

@kubevirt-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: phoracek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2024
@kubevirt-bot kubevirt-bot merged commit 892ccdd into kubevirt:main Dec 10, 2024
4 checks passed
@oshoval
Copy link
Collaborator

oshoval commented Dec 10, 2024

Thanks
need to find what creates release and update it as well / issue a release right ?
(unless part of it was already done)

@ashokpariya0
Copy link
Contributor Author

Thanks need to find what creates release and update it as well / issue a release right ? (unless part of it was already done)

Yes we need that info as we have to do export PLATFORMS=all before we build and push images:
More details is available on https://gist.github.com/ashokpariya0/30d5efc0e9525c266ef9e65fe4291860

@oshoval
Copy link
Collaborator

oshoval commented Dec 10, 2024

Hi @phoracek
is it possible that it doesn't have automation and you release this one manually ?

@oshoval
Copy link
Collaborator

oshoval commented Dec 10, 2024

@ashokpariya0
Copy link
Contributor Author

Please see here the post submit https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/logs/main-bridge-marker/1866476397598347264 https://github.com/kubevirt/project-infra/blob/main/github/ci/prow-deploy/files/jobs/kubevirt/bridge-marker/bridge-marker-postsubmits.yaml

Thanks Petr

Once you add the "all", we need to tag and then it will release with tag

Great! Can I create a PR to add export PLATFORMS=all in the above YAML file under the project-infra repository?

@oshoval
Copy link
Collaborator

oshoval commented Dec 10, 2024

sure thanks

@ashokpariya0
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants