Skip to contentSkip to conversation

kubernetes: explicitly build for $TARGET_ARCH

PATCH In review Koen Kooi 2 participants 5 messages Jul 23, 2018

lore
Share & tools
lore

Koen Kooi

author
#0 lore raw

PATCH 1/4 kubernetes: explicitly build for $TARGET_ARCH

'make all' uses 'uname' to select the build target, leading to compile failures like this:

| arm-angstrom-linux-gnueabi-gcc: error: unrecognized command line option '-m64'

After providing the proper arch to the makefile it will try to use a hardcoded compiler:

| # runtime/cgo
| exec: "arm-linux-gnueabihf-gcc": executable file not found in $PATH

Fix that up by removing all hardcoded 'CC' entries in golang.sh

---
 ...ack-lib-golang.sh-use-CC-from-environment.patch | 40 ++++++++++++++++++++++
 recipes-containers/kubernetes/kubernetes_git.bb    |  6 ++--
 2 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 recipes-containers/kubernetes/kubernetes/0001-hack-lib-golang.sh-use-CC-from-environment.patch
recipes-containers/kubernetes/kubernetes/0001-hack-lib-golang.sh-use-CC-from-environment.patch new file +40 -0
new file mode 100644
index 0000000..62d0521
@@ -0,0 +1,40 @@
+From 9cbb2d523d481053d405ebac830c2074b00d3417 Mon Sep 17 00:00:00 2001
+From: Koen Kooi <[email protected]>
+Date: Mon, 23 Jul 2018 15:28:02 +0200
+Subject: [PATCH] hack/lib/golang.sh: use CC from environment
+
+Toolchain tupples differs, especially when using vendor provides ones.
+
+Upstream-status: Inappropriate [embedded specific]
+Signed-off-by: Koen Kooi <[email protected]>
+---
+ hack/lib/golang.sh | 4 ----
+ 1 file changed, 4 deletions(-)
+
+diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
+index c5d4634..563e2b4b 100755
+--- a/src/import/hack/lib/golang.sh
++++ b/src/import/hack/lib/golang.sh
+@@ -278,19 +278,15 @@ kube::golang::set_platform_envs() {
+     case "${platform}" in
+       "linux/arm")
+         export CGO_ENABLED=1
+-        export CC=arm-linux-gnueabihf-gcc
+         ;;
+       "linux/arm64")
+         export CGO_ENABLED=1
+-        export CC=aarch64-linux-gnu-gcc
+         ;;
+       "linux/ppc64le")
+         export CGO_ENABLED=1
+-        export CC=powerpc64le-linux-gnu-gcc
+         ;;
+       "linux/s390x")
+         export CGO_ENABLED=1
+-        export CC=s390x-linux-gnu-gcc
+         ;;
+     esac
+   fi
+-- 
+2.9.5
+
recipes-containers/kubernetes/kubernetes_git.bb +4 -2
index 10558ef..33cb933 100644
@@ -7,6 +7,7 @@ maintenance, and scaling of applications. \
 
 SRCREV_kubernetes = "210c9cd7e1782e9fe46938fe0368556f2166a528"
 SRC_URI = "git://github.com/kubernetes/kubernetes.git;branch=release-1.11;name=kubernetes \
+           file://0001-hack-lib-golang.sh-use-CC-from-environment.patch \
           "
 
 DEPENDS += "rsync-native \
@@ -46,6 +47,7 @@ inherit goarch
 
 do_compile() {
 	export GOARCH="${TARGET_GOARCH}"
+	export GOOS="${TARGET_GOOS}"
 	export GOROOT="${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go"
 	export GOPATH="${S}/src/import:${S}/src/import/vendor"
 
@@ -72,7 +74,7 @@ do_compile() {
 
 	cd ${S}/src/import
 	# to limit what is built, use 'WHAT', i.e. make WHAT=cmd/kubelet
-	make all
+	make cross KUBE_BUILD_PLATFORMS=${GOOS}/${GOARCH}
 }
 
 do_install() {
@@ -82,7 +84,7 @@ do_install() {
 
     install -d ${D}${sysconfdir}/kubernetes/manifests/
 
-    install -m 755 -D ${S}/src/import/_output/bin/kube* ${D}/${bindir}
+    install -m 755 -D ${S}/src/import/_output/local/bin/${TARGET_GOOS}/${TARGET_GOARCH}/* ${D}/${bindir}
 
     install -m 0644 ${S}/src/import/build/debs/kubelet.service  ${D}${systemd_unitdir}/system/
     install -m 0644 ${S}/src/import/build/debs/10-kubeadm.conf  ${D}${systemd_unitdir}/system/kubelet.service.d/
Signature · 1 line
2.9.5
author
#1 lore raw

PATCH 2/4 kubernetes: build host tools using host toolchain

From: Jagadeesh Krishnanjanappa <[email protected]>

Compile host tools such as deepcopy-gen, defaulter-gen, openapi-gen
for host architecture, to solve below error:
-- snip --

| +++ [0117 05:31:35] Building go targets for linux/arm64:
|     ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
| touch: cannot touch '_output/bin/deepcopy-gen': No such file or directory
| make[1]: *** [Makefile.generated_files:323: _output/bin/deepcopy-gen] Error 1
| make: *** [Makefile:478: generated_files] Error 2
---
 recipes-containers/kubernetes/kubernetes_git.bb | 6 ++++++
 1 file changed, 6 insertions(+)
recipes-containers/kubernetes/kubernetes_git.bb +6 -0
index 33cb933..f23721c 100644
@@ -73,6 +73,12 @@ do_compile() {
 	export CGO_LDFLAGS="${LDFLAGS} --sysroot=${STAGING_DIR_TARGET}"
 
 	cd ${S}/src/import
+	# Build the host tools first, using the host compiler
+	export GOARCH="${BUILD_GOARCH}"
+	make generated_files KUBE_BUILD_PLATFORMS="${HOST_GOOS}/${BUILD_GOARCH}"
+
+	# Reset GOARCH to the target one
+	export GOARCH="${TARGET_GOARCH}"
 	# to limit what is built, use 'WHAT', i.e. make WHAT=cmd/kubelet
 	make cross KUBE_BUILD_PLATFORMS=${GOOS}/${GOARCH}
 }
Signature · 1 line
2.9.5
author
#2 lore raw

PATCH 3/4 kubernetes: package remaining files into PN-misc

In reply to Koen Kooi

A previous commit changed do_installed to install everything, not just kube*, adjust PACKAGES to keep ${PN} empty as it was before.

---
 recipes-containers/kubernetes/kubernetes_git.bb | 3 +++
 1 file changed, 3 insertions(+)
recipes-containers/kubernetes/kubernetes_git.bb +3 -0
index f23721c..bb80c3f 100644
@@ -14,6 +14,7 @@ DEPENDS += "rsync-native \
             coreutils-native \
            "
 
+PACKAGES =+ "${PN}-misc"
 PACKAGES =+ "kubeadm"
 PACKAGES =+ "kubectl"
 PACKAGES =+ "kubelet"
@@ -100,11 +101,13 @@ SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','kubelet','
 SYSTEMD_SERVICE_kubelet = "${@bb.utils.contains('DISTRO_FEATURES','systemd','kubelet.service','',d)}"
 SYSTEMD_AUTO_ENABLE_kubelet = "enable"
 
+FILES_${PN}-misc = "${bindir}"
 FILES_kubeadm = "${bindir}/kubeadm ${systemd_unitdir}/system/kubelet.service.d/*"
 FILES_kubectl = "${bindir}/kubectl"
 FILES_kube-proxy = "${bindir}/kube-proxy"
 FILES_kubelet = "${bindir}/kubelet ${systemd_unitdir}/system/kubelet.service ${sysconfdir}/kubernetes/manifests/"
 
+
 INHIBIT_PACKAGE_STRIP = "1"
 INSANE_SKIP_${PN} += "ldflags already-stripped"
 
Signature · 1 line
2.9.5
author
#3 lore raw

PATCH 4/4 kubernetes: OE styleguide fixes

In reply to Koen Kooi

* Keep variables close to the function they are used in, so R(untime)DEPENDS goes below do_install, PV next to SRCREV, etc.
* Don't use =+ as multiline seperator, it's a *very* heavy bitbake operation.

---
 recipes-containers/kubernetes/kubernetes_git.bb | 51 +++++++++++--------------
 1 file changed, 23 insertions(+), 28 deletions(-)
recipes-containers/kubernetes/kubernetes_git.bb +23 -28
index bb80c3f..4dbd080 100644
@@ -5,7 +5,11 @@ applications across multiple hosts, providing basic mechanisms for deployment, \
 maintenance, and scaling of applications. \
 "
 
+# Note: 1.11+ requires go 1.10.2+, so the following must be set
+#       in your configuration: GOVERSION = "1.10%"
+PV = "1.11.0+git${SRCREV_kubernetes}"
 SRCREV_kubernetes = "210c9cd7e1782e9fe46938fe0368556f2166a528"
+
 SRC_URI = "git://github.com/kubernetes/kubernetes.git;branch=release-1.11;name=kubernetes \
            file://0001-hack-lib-golang.sh-use-CC-from-environment.patch \
           "
@@ -14,34 +18,11 @@ DEPENDS += "rsync-native \
             coreutils-native \
            "
 
-PACKAGES =+ "${PN}-misc"
-PACKAGES =+ "kubeadm"
-PACKAGES =+ "kubectl"
-PACKAGES =+ "kubelet"
-PACKAGES =+ "kube-proxy"
-
-ALLOW_EMPTY_${PN} = "1"
-
-# Note: we are explicitly *not* adding docker to the rdepends, since we allow
-#       backends like cri-o to be used.
-RDEPENDS_${PN} += "kubeadm \
-                   kubectl \
-                   kubelet \
-                   cni"
-
-RDEPENDS_kubeadm = "kubelet kubectl"
-RDEPENDS_kubelet = "iptables socat util-linux ethtool iproute2 ebtables iproute2-tc"
-
 LICENSE = "Apache-2.0"
 LIC_FILES_CHKSUM = "file://src/import/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
 
 GO_IMPORT = "import"
 
-
-# Note: 1.11+ requires go 1.10.2+, so the following must be set
-#       in your configuration: GOVERSION = "1.10%"
-PV = "1.11.0+git${SRCREV_kubernetes}"
-
 inherit systemd
 inherit go
 inherit goarch
@@ -97,18 +78,32 @@ do_install() {
     install -m 0644 ${S}/src/import/build/debs/10-kubeadm.conf  ${D}${systemd_unitdir}/system/kubelet.service.d/
 }
 
+PACKAGES =+ "kubeadm kubectl kubelet kube-proxy ${PN}-misc"
+
+ALLOW_EMPTY_${PN} = "1"
+INSANE_SKIP_${PN} += "ldflags already-stripped"
+
+# Note: we are explicitly *not* adding docker to the rdepends, since we allow
+#       backends like cri-o to be used.
+RDEPENDS_${PN} += "kubeadm \
+                   kubectl \
+                   kubelet \
+                   cni"
+
+RDEPENDS_kubeadm = "kubelet kubectl"
+FILES_kubeadm = "${bindir}/kubeadm ${systemd_unitdir}/system/kubelet.service.d/*"
+
+RDEPENDS_kubelet = "iptables socat util-linux ethtool iproute2 ebtables iproute2-tc"
+FILES_kubelet = "${bindir}/kubelet ${systemd_unitdir}/system/kubelet.service ${sysconfdir}/kubernetes/manifests/"
+
 SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','kubelet','',d)}"
 SYSTEMD_SERVICE_kubelet = "${@bb.utils.contains('DISTRO_FEATURES','systemd','kubelet.service','',d)}"
 SYSTEMD_AUTO_ENABLE_kubelet = "enable"
 
-FILES_${PN}-misc = "${bindir}"
-FILES_kubeadm = "${bindir}/kubeadm ${systemd_unitdir}/system/kubelet.service.d/*"
 FILES_kubectl = "${bindir}/kubectl"
 FILES_kube-proxy = "${bindir}/kube-proxy"
-FILES_kubelet = "${bindir}/kubelet ${systemd_unitdir}/system/kubelet.service ${sysconfdir}/kubernetes/manifests/"
-
+FILES_${PN}-misc = "${bindir}"
 
 INHIBIT_PACKAGE_STRIP = "1"
-INSANE_SKIP_${PN} += "ldflags already-stripped"
 
 deltask compile_ptest_base
Signature · 1 line
2.9.5
#4 lore raw
In reply to Koen Kooi

I had to add a QA skip for PN-misc, since in my config it was throwing a GNU_HASH error.

This is now pushed, thanks for the cleanups.

Cheers,

Bruce

Quoted 105 lines · Koen Kooi

'make all' uses 'uname' to select the build target, leading to compile failures like this:

| arm-angstrom-linux-gnueabi-gcc: error: unrecognized command line option '-m64'

After providing the proper arch to the makefile it will try to use a hardcoded compiler:

| # runtime/cgo
| exec: "arm-linux-gnueabihf-gcc": executable file not found in $PATH

Fix that up by removing all hardcoded 'CC' entries in golang.sh

---
 ...ack-lib-golang.sh-use-CC-from-environment.patch | 40 ++++++++++++++++++++++
 recipes-containers/kubernetes/kubernetes_git.bb    |  6 ++--
 2 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 recipes-containers/kubernetes/kubernetes/0001-hack-lib-golang.sh-use-CC-from-environment.patch
recipes-containers/kubernetes/kubernetes/0001-hack-lib-golang.sh-use-CC-from-environment.patch new file +40 -0
new file mode 100644
index 0000000..62d0521
@@ -0,0 +1,40 @@
+From 9cbb2d523d481053d405ebac830c2074b00d3417 Mon Sep 17 00:00:00 2001
+From: Koen Kooi <[email protected]>
+Date: Mon, 23 Jul 2018 15:28:02 +0200
+Subject: [PATCH] hack/lib/golang.sh: use CC from environment
+
+Toolchain tupples differs, especially when using vendor provides ones.
+
+Upstream-status: Inappropriate [embedded specific]
+Signed-off-by: Koen Kooi <[email protected]>
+---
+ hack/lib/golang.sh | 4 ----
+ 1 file changed, 4 deletions(-)
+
+diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
+index c5d4634..563e2b4b 100755
+--- a/src/import/hack/lib/golang.sh
++++ b/src/import/hack/lib/golang.sh
+@@ -278,19 +278,15 @@ kube::golang::set_platform_envs() {
+     case "${platform}" in
+       "linux/arm")
+         export CGO_ENABLED=1
+-        export CC=arm-linux-gnueabihf-gcc
+         ;;
+       "linux/arm64")
+         export CGO_ENABLED=1
+-        export CC=aarch64-linux-gnu-gcc
+         ;;
+       "linux/ppc64le")
+         export CGO_ENABLED=1
+-        export CC=powerpc64le-linux-gnu-gcc
+         ;;
+       "linux/s390x")
+         export CGO_ENABLED=1
+-        export CC=s390x-linux-gnu-gcc
+         ;;
+     esac
+   fi
+--
+2.9.5
+
recipes-containers/kubernetes/kubernetes_git.bb +4 -3
index 10558ef..33cb933 100644
@@ -7,6 +7,7 @@ maintenance, and scaling of applications. \
 
 SRCREV_kubernetes = "210c9cd7e1782e9fe46938fe0368556f2166a528"
 SRC_URI = "git://github.com/kubernetes/kubernetes.git;branch=release-1.11;name=kubernetes \
+           file://0001-hack-lib-golang.sh-use-CC-from-environment.patch \
           "
 
 DEPENDS += "rsync-native \
@@ -46,6 +47,7 @@ inherit goarch
 
 do_compile() {
        export GOARCH="${TARGET_GOARCH}"
+       export GOOS="${TARGET_GOOS}"
        export GOROOT="${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go"
        export GOPATH="${S}/src/import:${S}/src/import/vendor"
 
@@ -72,7 +74,7 @@ do_compile() {
 
        cd ${S}/src/import
        # to limit what is built, use 'WHAT', i.e. make WHAT=cmd/kubelet
-       make all
+       make cross KUBE_BUILD_PLATFORMS=${GOOS}/${GOARCH}
 }
 
 do_install() {
@@ -82,7 +84,7 @@ do_install() {
 
     install -d ${D}${sysconfdir}/kubernetes/manifests/
 
-    install -m 755 -D ${S}/src/import/_output/bin/kube* ${D}/${bindir}
+    install -m 755 -D ${S}/src/import/_output/local/bin/${TARGET_GOOS}/${TARGET_GOARCH}/* ${D}/${bindir}
 
     install -m 0644 ${S}/src/import/build/debs/kubelet.service  ${D}${systemd_unitdir}/system/
     install -m 0644 ${S}/src/import/build/debs/10-kubeadm.conf  ${D}${systemd_unitdir}/system/kubelet.service.d/
--

2.9.5

Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end"