Skip to content

Commit

Permalink
switch off of the bazel debs
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Feb 23, 2019
1 parent 6f430d3 commit e43cdf2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
86 changes: 55 additions & 31 deletions pkg/build/kube/bazelbuildbits.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package kube

import (
"fmt"
"os"
"path"
"path/filepath"
"runtime"

log "github.com/sirupsen/logrus"
"github.com/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
)

Expand Down Expand Up @@ -56,16 +58,19 @@ func (b *BazelBuildBits) Build() error {
// make sure we cd back when done
defer os.Chdir(cwd)

// TODO(bentheelder): we assume the host arch, but cross compiling should
// be possible now
bazelGoosGoarch := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)

// build artifacts
cmd := exec.Command(
"bazel", "build",
// TODO(bentheelder): we assume linux amd64, but we could select
// this based on Arch etc. throughout, this flag supports GOOS/GOARCH
"--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64",
fmt.Sprintf("--platforms=@io_bazel_rules_go//go/toolchain:%s", bazelGoosGoarch),
// we want the debian packages
"//build/debs:debs",
//"//build/debs:debs",
// host installed binaries
"//cmd/kubeadm:kubeadm", "//cmd/kubectl:kubectl", "//cmd/kubelet:kubelet",
// and the docker images
//"//cluster/images/hyperkube:hyperkube.tar",
"//build:docker-artifacts",
)
exec.InheritOutput(cmd)
Expand All @@ -82,48 +87,67 @@ func (b *BazelBuildBits) Paths() map[string]string {
// https://docs.bazel.build/versions/master/output_directories.html
binDir := filepath.Join(b.kubeRoot, "bazel-bin")
buildDir := filepath.Join(binDir, "build")
bazelGoosGoarch := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
return map[string]string{
// debians
filepath.Join(buildDir, "debs", "kubeadm.deb"): "debs/kubeadm.deb",
filepath.Join(buildDir, "debs", "kubelet.deb"): "debs/kubelet.deb",
filepath.Join(buildDir, "debs", "kubectl.deb"): "debs/kubectl.deb",
filepath.Join(buildDir, "debs", "kubernetes-cni.deb"): "debs/kubernetes-cni.deb",
filepath.Join(buildDir, "debs", "cri-tools.deb"): "debs/cri-tools.deb",
// host binaries
filepath.Join(
binDir, "cmd", "kubeadm",
// pure-go binary
fmt.Sprintf("%s_pure_stripped", bazelGoosGoarch), "kubeadm",
): "bin/kubeadm",
filepath.Join(
binDir, "cmd", "kubelet",
// cgo binary
fmt.Sprintf("%s_stripped", bazelGoosGoarch), "kubelet",
): "bin/kubelet",
filepath.Join(
binDir, "cmd", "kubectl",
// pure-go binary
fmt.Sprintf("%s_pure_stripped", bazelGoosGoarch), "kubectl",
): "bin/kubectl",
// docker images
filepath.Join(buildDir, "kube-apiserver.tar"): "images/kube-apiserver.tar",
filepath.Join(buildDir, "kube-controller-manager.tar"): "images/kube-controller-manager.tar",
filepath.Join(buildDir, "kube-scheduler.tar"): "images/kube-scheduler.tar",
filepath.Join(buildDir, "kube-proxy.tar"): "images/kube-proxy.tar",
// version file
filepath.Join(b.kubeRoot, "_output", "git_version"): "version",
// borrow kubelet service files from bazel debians
// TODO(bentheelder): probably we should use our own config instead :-)
filepath.Join(b.kubeRoot, "build", "debs", "kubelet.service"): "systemd/kubelet.service",
filepath.Join(b.kubeRoot, "build", "debs", "10-kubeadm.conf"): "systemd/10-kubeadm.conf",
}
}

// Install implements Bits.Install
func (b *BazelBuildBits) Install(install InstallContext) error {
base := install.BasePath()

// install debians
debs := path.Join(base, "debs", "*.deb")
if err := install.Run("/bin/sh", "-c", "dpkg -i "+debs); err != nil {
log.Errorf("Debian install failed! %v", err)
return err
kindBinDir := path.Join(install.BasePath(), "bin")

// symlink the kubernetes binaries into $PATH
binaries := []string{"kubeadm", "kubelet", "kubectl"}
for _, binary := range binaries {
if err := install.Run("ln", "-s",
path.Join(kindBinDir, binary),
path.Join("/usr/bin/", binary),
); err != nil {
return errors.Wrap(err, "failed to symlink binaries")
}
}

// clean up after debian install
if err := install.Run("/bin/sh", "-c",
"rm -rf /kind/bits/debs/*.deb"+
" /var/cache/debconf/* /var/lib/apt/lists/* /var/log/*kg",
); err != nil {
log.Errorf("Debian cleanup failed! %v", err)
return err
// enable the kubelet service
kubeletService := path.Join(install.BasePath(), "systemd/kubelet.service")
if err := install.Run("systemctl", "enable", kubeletService); err != nil {
return errors.Wrap(err, "failed to enable kubelet service")
}

// enable kubelet service
if err := install.Run("systemctl", "enable", "kubelet.service"); err != nil {
log.Errorf("Enabling kubelet.service failed! %v", err)
return err
// setup the kubelet dropin
kubeletDropinSource := path.Join(install.BasePath(), "systemd/10-kubeadm.conf")
kubeletDropin := "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
if err := install.Run("mkdir", "-p", path.Dir(kubeletDropin)); err != nil {
return errors.Wrap(err, "failed to configure kubelet service")
}
if err := install.Run("cp", kubeletDropinSource, kubeletDropin); err != nil {
return errors.Wrap(err, "failed to configure kubelet service")
}

return nil
}
2 changes: 2 additions & 0 deletions pkg/build/kube/bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type Bits interface {
Paths() map[string]string
// Install should install the built sources on the node, assuming paths
// have been populated
// TODO(bentheelder): eliminate install, make install file-copies only,
// support cross-building
Install(InstallContext) error
}

Expand Down

0 comments on commit e43cdf2

Please sign in to comment.