-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
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]>
Hi @ashokpariya0. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
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
I assume it works for all the platforms mentioned on the comment
@@ -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} |
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.
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
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.
@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.
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.
Updated PLATFORMS to automatically include all supported platforms when export PLATFORMS=all is used.
hack/build-operator-podman.sh
Outdated
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." |
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.
btw i would say 2>/dev/null || true
is enough please
(same for the rest of course)
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.
Done.
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
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. |
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.
Please add this feature to PR desc
nit: there are twice #
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.
Done.
f3ff372
to
81732b6
Compare
hack/build-operator-podman.sh
Outdated
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null | ||
podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null |
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.
you do need || true
please, isnt it ?
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.
in anyways it will suppress the error but let me add || true.
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.
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" |
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.
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 ?
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.
Done.
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.
hmm but wont it mess current_builder ? maybe here we are not allowed to fail ?
Yes correct, this is fine.
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.
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 ?
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.
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.
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.
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) ?
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.
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." |
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.
lets just use 2>/dev/null || true
please
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.
Done.
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.
we still have the old one it seems :)
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.
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]
81732b6
to
b05457d
Compare
Quality Gate passedIssues Measures |
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || true | ||
podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || true |
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.
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
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.
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.
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
@0xFelix switching labels /lgtm cancel |
[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 |
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
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: