Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up kubernetes builds #2097

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why added here and not in env?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's not common across commands and make supports it either way.

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