kubebuilder
kubebuilder copied to clipboard
Multi-arch enablement for default templates
Hi, I came across #2697 while investigating the "multi-arch & operator-sdk templates" topic when initializing operators.
I'd propose to delete the TARGET_ARCH var there.
In fact, when the base image, i.e., golang:1.17 as of now, is a ManifestList, and you run with the default parameters (assume the user is not aware of this parameter) in a non-amd64 host, we'd get a non-amd64 image with an amd64 binary built for the manager (assuming all is available to cross-build it).
Therefore, any user should be aware of setting the TARGET_ARCH according to their host's architecture, if different than amd64.
Instead, suppose you build the image with no GOARCH at line 23 in the Dockerfile, in a host having architecture A.
If the base image is a ManifestList and it references a Manifest for architecture A, the builder will use the Manifest for architecture A, the GOARCH environment variable is automatically filled by the go tools themselves, and the binary is built for architecture A as well as the final image will be able to run in a host with architecture A.
cc @camilamacedo86 @gquillar @andymcc
What we need is to find a way here to provide a helper for the authors/users so that they can build their manager images with support to multiple platforms. I am looking at this one.