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

Build images on the primary control plane #12149

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion cmd/minikube/cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import (
docker "k8s.io/minikube/third_party/go-dockerclient"
)

var (
allNodes bool
)

// imageCmd represents the image command
var imageCmd = &cobra.Command{
Use: "image COMMAND",
Expand Down Expand Up @@ -217,7 +221,7 @@ var buildImageCmd = &cobra.Command{
// Otherwise, assume it's a tar
}
}
if err := machine.BuildImage(img, dockerFile, tag, push, buildEnv, buildOpt, []*config.Profile{profile}); err != nil {
if err := machine.BuildImage(img, dockerFile, tag, push, buildEnv, buildOpt, []*config.Profile{profile}, allNodes, nodeName); err != nil {
exit.Error(reason.GuestImageBuild, "Failed to build image", err)
}
if tmp != "" {
Expand Down Expand Up @@ -257,6 +261,8 @@ func init() {
buildImageCmd.Flags().StringVarP(&dockerFile, "file", "f", "", "Path to the Dockerfile to use (optional)")
buildImageCmd.Flags().StringArrayVar(&buildEnv, "build-env", nil, "Environment variables to pass to the build. (format: key=value)")
buildImageCmd.Flags().StringArrayVar(&buildOpt, "build-opt", nil, "Specify arbitrary flags to pass to the build. (format: key=value)")
buildImageCmd.Flags().StringVarP(&nodeName, "node", "n", "", "The node to build on. Defaults to the primary control plane.")
buildImageCmd.Flags().BoolVarP(&allNodes, "all", "", false, "Build image on all nodes.")
imageCmd.AddCommand(buildImageCmd)
imageCmd.AddCommand(listImageCmd)
}
16 changes: 15 additions & 1 deletion pkg/minikube/machine/build_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
var buildRoot = path.Join(vmpath.GuestPersistentDir, "build")

// BuildImage builds image to all profiles
func BuildImage(path string, file string, tag string, push bool, env []string, opt []string, profiles []*config.Profile) error {
func BuildImage(path string, file string, tag string, push bool, env []string, opt []string, profiles []*config.Profile, allNodes bool, nodeName string) error {
api, err := NewAPIClient()
if err != nil {
return errors.Wrap(err, "api")
Expand Down Expand Up @@ -70,9 +70,23 @@ func BuildImage(path string, file string, tag string, push bool, env []string, o
continue
}

cp, err := config.PrimaryControlPlane(p.Config)
if err != nil {
return err
}

for _, n := range c.Nodes {
m := config.MachineName(*c, n)

if !allNodes {
// build images on the primary control plane node by default
if nodeName == "" && n != cp {
continue
} else if nodeName != n.Name && nodeName != m {
continue
}
}

status, err := Status(api, m)
if err != nil {
klog.Warningf("error getting status for %s: %v", m, err)
Expand Down
2 changes: 2 additions & 0 deletions site/content/en/docs/commands/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ minikube image build .
### Options

```
--all Build image on all nodes.
--build-env stringArray Environment variables to pass to the build. (format: key=value)
--build-opt stringArray Specify arbitrary flags to pass to the build. (format: key=value)
-f, --file string Path to the Dockerfile to use (optional)
-n, --node string The node to build on. Defaults to the primary control plane.
--push Push the new image (requires tag)
-t, --tag string Tag to apply to the new image (optional)
```
Expand Down