Tuesday, 16 June 2020

Building Kubernetes - Getting it to Go right ....

I'm currently building Kubernetes from source, on an Ubuntu box.

Having cloned the repo: -

mkdir -p $(go env GOPATH)/src/k8s.io
cd $(go env GOPATH)/src/k8s.io
git clone https://github.com/kubernetes/kubernetes.git
cd kubernetes


I was looking at a specific version of K8s - v1.16.2 : -

git checkout tags/v1.16.2

but, when I started to build any of the K8s binaries e.g. kubectl I saw this: -

make kubectl

cannot find module providing package k8s.io/kubernetes: unrecognized import path "k8s.io": parse https://k8s.io/?go-get=1: no go-import meta tags (meta tag k8s.io/ did not match import path k8s.io)
+++ [0616 01:06:04] Building go targets for linux/amd64:
    ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
go: finding module for package k8s.io/kubernetes/vendor/k8s.io/code-generator/cmd/deepcopy-gen
can't load package: package k8s.io/kubernetes/vendor/k8s.io/code-generator/cmd/deepcopy-gen: no matching versions for query "latest"
!!! [0616 01:06:07] Call tree:
!!! [0616 01:06:07]  1: /root/go/src/k8s.io/kubernetes/hack/lib/golang.sh:714 kube::golang::build_some_binaries(...)
!!! [0616 01:06:07]  2: /root/go/src/k8s.io/kubernetes/hack/lib/golang.sh:853 kube::golang::build_binaries_for_platform(...)
!!! [0616 01:06:07]  3: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
!!! [0616 01:06:07] Call tree:
!!! [0616 01:06:07]  1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
!!! [0616 01:06:07] Call tree:
!!! [0616 01:06:07]  1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
Makefile.generated_files:200: recipe for target '_output/bin/deepcopy-gen' failed
make[1]: *** [_output/bin/deepcopy-gen] Error 1
Makefile:559: recipe for target 'generated_files' failed
make: *** [generated_files] Error 2


This led me here: -

can't load package: package k8s.io/kubernetes: cannot find module providing package k8s.io/kubernetes #84224

and here: -

switch build scripts to use go modules, stop requiring $GOPATH #82531

and made me realise that I had a disparity between the version of Go I was using: -

go version

go version go1.14.3 linux/amd64

and the version of K8s itself.

In other words, I was trying to build K8s 1.16.2 using Go 1.14.3

Thankfully, the K8s repo has the answer: -



Once I realised this, and switched back to the main branch of K8s, which is the latest 

Cloning into 'kubernetes'...
remote: Enumerating objects: 229, done.
remote: Counting objects: 100% (229/229), done.
remote: Compressing objects: 100% (136/136), done.
remote: Total 1118551 (delta 115), reused 95 (delta 93), pack-reused 1118322
Receiving objects: 100% (1118551/1118551), 688.00 MiB | 25.10 MiB/s, done.
Resolving deltas: 100% (800101/800101), done.
Updating files: 100% (22439/22439), done.


cd kubernetes/
git branch

* master

all was good

make kubectl

+++ [0616 01:15:05] Building go targets for linux/amd64:
    ./vendor/k8s.io/code-generator/cmd/prerelease-lifecycle-gen
+++ [0616 01:15:15] Building go targets for linux/amd64:
    ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
+++ [0616 01:15:31] Building go targets for linux/amd64:
    ./vendor/k8s.io/code-generator/cmd/defaulter-gen
+++ [0616 01:15:45] Building go targets for linux/amd64:
    ./vendor/k8s.io/code-generator/cmd/conversion-gen
+++ [0616 01:16:08] Building go targets for linux/amd64:
    ./vendor/k8s.io/kube-openapi/cmd/openapi-gen
+++ [0616 01:16:27] Building go targets for linux/amd64:
    ./vendor/github.com/go-bindata/go-bindata/go-bindata
+++ [0616 01:16:30] Building go targets for linux/amd64:
    cmd/kubectl


No comments:

Reminder - installing podman and skopeo on Ubuntu 22.04

This follows on from: - Lest I forget - how to install pip on Ubuntu I had reason to install podman  and skopeo  on an Ubuntu box: - lsb_rel...