Skip to content

Commit

Permalink
Merge pull request #2097 from BenTheElder/slightly-faster-build
Browse files Browse the repository at this point in the history
speed up kubernetes builds
  • Loading branch information
BenTheElder authored Mar 11, 2021
2 parents 7bb7c18 + 496a623 commit a4df15b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pkg/build/nodeimage/internal/kube/builder_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
"sigs.k8s.io/kind/pkg/log"

"k8s.io/apimachinery/pkg/util/version"
)

// TODO(bentheelder): plumb through arch
Expand Down Expand Up @@ -69,6 +71,11 @@ func (b *dockerBuilder) Build() (Bits, error) {
return nil, err
}

kubeVersion, err := version.ParseSemantic(sourceVersionRaw)
if err != nil {
return nil, errors.Wrap(err, "failed to parse source version")
}

// we will pass through the environment variables, prepending defaults
// NOTE: if env are specified multiple times the last one wins
env := append(
Expand All @@ -83,29 +90,35 @@ func (b *dockerBuilder) Build() (Bits, error) {
},
os.Environ()...,
)
// build binaries
// binaries we want to build
what := []string{
// binaries we use directly
"cmd/kubeadm",
"cmd/kubectl",
"cmd/kubelet",
}
cmd := exec.Command(
"build/run.sh",
"make", "all", "WHAT="+strings.Join(what, " "),
).SetEnv(env...)
exec.InheritOutput(cmd)
if err := cmd.Run(); err != nil {
return nil, errors.Wrap(err, "failed to build binaries")
}

// build images
cmd = exec.Command("make", "quick-release-images").SetEnv(env...)
// build images + binaries (binaries only on 1.21+)
cmd := exec.Command("make", "quick-release-images", "KUBE_EXTRA_WHAT="+strings.Join(what, " ")).SetEnv(env...)
exec.InheritOutput(cmd)
if err := cmd.Run(); err != nil {
return nil, errors.Wrap(err, "failed to build images")
}

// KUBE_EXTRA_WHAT added in this commit
// https://github.com/kubernetes/kubernetes/commit/35061acc28a666569fdd4d1c8a7693e3c01e14be
if kubeVersion.LessThan(version.MustParseSemantic("v1.21.0-beta.1.153+35061acc28a666")) {
// on older versions we still need to build binaries separately
cmd = exec.Command(
"build/run.sh",
"make", "all", "WHAT="+strings.Join(what, " "),
).SetEnv(env...)
exec.InheritOutput(cmd)
if err := cmd.Run(); err != nil {
return nil, errors.Wrap(err, "failed to build binaries")
}
}

binDir := filepath.Join(b.kubeRoot,
"_output", "dockerized", "bin", "linux", b.arch,
)
Expand Down

0 comments on commit a4df15b

Please sign in to comment.