k3s: set version.UpstreamGolang in binaries

k3s will refuse to start if the golang version it was built
with doesn't match the VERSION_GOLANG linker variable.

As an example: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/61668

We query our version of the compiler and set it in the binaries
to ensure they match.

Note: this may cause issues if you bump the golang compiler, but
k3s doesn't rebuild. We'll worry about that when it happens.

With this change, k3s starts and the node becomes ready.

root@qemux86-64:~# uname -a
Linux qemux86-64 6.6.20-yocto-standard #1 SMP PREEMPT_DYNAMIC Sun Mar  3 16:28:22 UTC 2024 x86_64 GNU/Linux

root@qemux86-64:~# kubectl get nodes
NAME         STATUS   ROLES                  AGE   VERSION
qemux86-64   Ready    control-plane,master   10m   v1.28.7-k3s1

Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
This commit is contained in:
Bruce Ashfield 2024-03-15 19:06:05 +00:00
parent 5984a2e4b6
commit 54f80102b0

View File

@ -76,7 +76,8 @@ do_compile() {
cp ${WORKDIR}/modules.txt vendor/ cp ${WORKDIR}/modules.txt vendor/
${GO} build -trimpath -tags "$TAGS" -ldflags "${GO_BUILD_LDFLAGS} -w -s" -o ./dist/artifacts/k3s ./cmd/server/main.go VERSION_GOLANG="$(go version | cut -d" " -f3)"
${GO} build -trimpath -tags "$TAGS" -ldflags "-X github.com/k3s-io/k3s/pkg/version.UpstreamGolang=$VERSION_GOLANG ${GO_BUILD_LDFLAGS} -w -s" -o ./dist/artifacts/k3s ./cmd/server/main.go
# Use UPX if it is enabled (and thus exists) to compress binary # Use UPX if it is enabled (and thus exists) to compress binary
if command -v upx > /dev/null 2>&1; then if command -v upx > /dev/null 2>&1; then