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 dynamic host architecture detection. #1928

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

ashokpariya0
Copy link
Contributor

@ashokpariya0 ashokpariya0 commented Nov 29, 2024

This update sets the platform dynamically based on the host architecture, enhancing flexibility for building multi-platform images across different architectures.

What this PR does / why we need it:
Instead of setting the platform value to amd64, these changes configure it dynamically based on the host architecture.
Enhance multi-architecture build support and optimize error handling
Automatically include all supported platforms when PLATFORMS=all is exported.
Removed --no-cache flag to speed up builds by utilizing cached layers.
Improved error handling for expected failures to provide cleaner logs.
Implemented architecture auto-detection for Docker buildx installation to support various platforms.

Special notes for your reviewer:
gist link: https://gist.github.com/ashokpariya0/19b6f235a3fe149d16d82d92c84ce542

Release note:

None

This update sets the platform dynamically based on the host architecture,
enhancing flexibility for building multi-platform images across different architectures.

Signed-off-by: Ashok Pariya <[email protected]>
@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. labels Nov 29, 2024
@kubevirt-bot
Copy link
Collaborator

Hi @ashokpariya0. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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
I assume it works for all the platforms mentioned on the comment

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 1, 2024
@@ -13,13 +13,13 @@ OPERATOR_IMAGE ?= cluster-network-addons-operator
REGISTRY_IMAGE ?= cluster-network-addons-registry
export OCI_BIN ?= $(shell if podman ps >/dev/null 2>&1; then echo podman; elif docker ps >/dev/null 2>&1; then echo docker; fi)
TLS_SETTING := $(if $(filter $(OCI_BIN),podman),--tls-verify=false,)
PLATFORMS ?= linux/amd64
ARCH := $(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
PLATFORMS ?= linux/${ARCH}
Copy link
Collaborator

Choose a reason for hiding this comment

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

wdyt about adding an option to set export PLATFORMS=all
which will be translated internally to linux/amd64,linux/arm64,linux/s390x ?
it is less explicit but 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.

@oshoval That's a great idea! Adding an export PLATFORMS=all option would simplify the configuration and make it easier to maintain, especially as we add more platforms in the future. I'll include this change in a follow-up PR.
All tests have passed, and there is one pending tide test awaiting the approval label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated PLATFORMS to automatically include all supported platforms when export PLATFORMS=all is used.

@oshoval
Copy link
Collaborator

oshoval commented Dec 1, 2024

cc @RamLavi @qinqon
can you take a look please ?

@kubevirt-bot kubevirt-bot added size/S and removed lgtm Indicates that a PR is ready to be merged. size/XS labels Dec 2, 2024
Comment on lines 11 to 12
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || echo "Manifest ${OPERATOR_IMAGE_TAGGED} not found, skipping removal."
podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || echo "Image ${OPERATOR_IMAGE_TAGGED} not found, skipping removal."
Copy link
Collaborator

@oshoval oshoval Dec 2, 2024

Choose a reason for hiding this comment

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

btw i would say 2>/dev/null || true is enough please
(same for the rest of course)

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.

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

Makefile Outdated
# Set the platforms for building a multi-platform supported image.
# Example:
# PLATFORMS ?= linux/amd64,linux/arm64,linux/s390x
# Alternatively, you can export the PLATFORMS variable like this:
# export PLATFORMS=linux/arm64,linux/s390x,linux/amd64
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
# # or export PLATFORMS=all to automatically include all supported platforms.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this feature to PR desc

nit: there are twice #

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.

Comment on lines 11 to 12
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null
podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

you do need || true please, isnt it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in anyways it will suppress the error but let me add || true.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if it suppress the error in case image / manifest not found, no need to add, my mistake then
thanks

@@ -20,7 +21,7 @@ create_or_use_buildx_builder() {

check_buildx

current_builder="$(docker buildx inspect "${builder_name}")"
current_builder="$(docker buildx inspect "${builder_name}" 2>/dev/null)" || echo "Builder '${builder_name}' not found"
Copy link
Collaborator

@oshoval oshoval Dec 2, 2024

Choose a reason for hiding this comment

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

lets just ... 2>/dev/null)" || true please
simpler, more quiet

hmm but wont it mess current_builder ?
maybe here we are not allowed to fail ?

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm but wont it mess current_builder ? maybe here we are not allowed to fail ?

Yes correct, this is fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry i dont understand
it assigns a value to current_builder, and we can't just || echo here in case it fails, because then current_builder will have empty value and the script continue with unexpected empty value isnt it ?

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, you're right; it will have an empty value. However, we handle errors properly later in the script. I don't see any issues with either the failure or success case, so everything looks good.

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.

please correct me if i am wrong,
this is an expression that must success, hence we should fail fast (i.e remove the || echo ... , and the stderr redirection) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, by default, docker buildx inspect <builder-name> will print an error to the console if the builder is not found. Since we want to suppress this error, it's better to use || with an echo statement for debugging purposes.

@@ -14,4 +14,5 @@ if [ ${#PLATFORM_LIST[@]} -eq 1 ]; then
else
./hack/init-buildx.sh "$DOCKER_BUILDER"
docker buildx build --platform "$PLATFORMS" $BUILD_ARGS
docker buildx rm "$DOCKER_BUILDER" 2>/dev/null || echo "Builder ${DOCKER_BUILDER} not found or already removed, skipping."
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets just use 2>/dev/null || true 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.

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we still have the old one it seems :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's better to keep this message, as this is not an expected failure. It will help us with debugging in case an issue arises.

Updated PLATFORMS to automatically include all supported platforms when export PLATFORMS=all is used.
Removed --no-cache to improve build time by leveraging cached layers during the build process.
Enhanced error handling for expected failures.
Added auto-detection of architecture for Docker buildx installation to support multiple platforms.

Signed-off-by: Ashok Pariya [email protected]
Copy link

sonarqubecloud bot commented Dec 2, 2024

Comment on lines +11 to +12
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || true
podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || true
Copy link
Collaborator

@oshoval oshoval Dec 2, 2024

Choose a reason for hiding this comment

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

if podman suppress the error in case the images dont exists, please drop the || true (i dont know if this is the case by heart, but you raised it is, best to double check if you want please)

lets keep the code correct and as minimal as possible please
sorry for the back and forth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's better to keep || true, Below is the reason:
Without || true: The command suppresses the error output but will still fail if there's an issue (e.g., manifest not found).
With || true: The command suppresses the error and ensures the script continues even if there's an issue.

@ashokpariya0
Copy link
Contributor Author

@RamLavi @qinqon @phoracek
Could you please take a look at the PR?

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

@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

@0xFelix
if you can review this one please, thanks

switching labels

/lgtm cancel
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: oshoval

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 3, 2024
Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 4, 2024
@kubevirt-bot kubevirt-bot merged commit 9f14528 into kubevirt:main Dec 4, 2024
15 checks passed
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. release-note-none Denotes a PR that doesn't merit a release note. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants