Skip to content

Commit 2fd09e1

Browse files
authored
Merge pull request #12149 from afbjorklund/build-cp
Build images on the primary control plane
2 parents 0542f47 + 2ab5c86 commit 2fd09e1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Diff for: cmd/minikube/cmd/image.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import (
3535
docker "k8s.io/minikube/third_party/go-dockerclient"
3636
)
3737

38+
var (
39+
allNodes bool
40+
)
41+
3842
// imageCmd represents the image command
3943
var imageCmd = &cobra.Command{
4044
Use: "image COMMAND",
@@ -306,7 +310,7 @@ var buildImageCmd = &cobra.Command{
306310
// Otherwise, assume it's a tar
307311
}
308312
}
309-
if err := machine.BuildImage(img, dockerFile, tag, push, buildEnv, buildOpt, []*config.Profile{profile}); err != nil {
313+
if err := machine.BuildImage(img, dockerFile, tag, push, buildEnv, buildOpt, []*config.Profile{profile}, allNodes, nodeName); err != nil {
310314
exit.Error(reason.GuestImageBuild, "Failed to build image", err)
311315
}
312316
if tmp != "" {
@@ -387,6 +391,8 @@ func init() {
387391
buildImageCmd.Flags().StringVarP(&dockerFile, "file", "f", "", "Path to the Dockerfile to use (optional)")
388392
buildImageCmd.Flags().StringArrayVar(&buildEnv, "build-env", nil, "Environment variables to pass to the build. (format: key=value)")
389393
buildImageCmd.Flags().StringArrayVar(&buildOpt, "build-opt", nil, "Specify arbitrary flags to pass to the build. (format: key=value)")
394+
buildImageCmd.Flags().StringVarP(&nodeName, "node", "n", "", "The node to build on. Defaults to the primary control plane.")
395+
buildImageCmd.Flags().BoolVarP(&allNodes, "all", "", false, "Build image on all nodes.")
390396
imageCmd.AddCommand(buildImageCmd)
391397
saveImageCmd.Flags().BoolVar(&imgDaemon, "daemon", false, "Cache image to docker daemon")
392398
saveImageCmd.Flags().BoolVar(&imgRemote, "remote", false, "Cache image to remote registry")

Diff for: pkg/minikube/machine/build_images.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
var buildRoot = path.Join(vmpath.GuestPersistentDir, "build")
4141

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

73+
cp, err := config.PrimaryControlPlane(p.Config)
74+
if err != nil {
75+
return err
76+
}
77+
7378
for _, n := range c.Nodes {
7479
m := config.MachineName(*c, n)
7580

81+
if !allNodes {
82+
// build images on the primary control plane node by default
83+
if nodeName == "" && n != cp {
84+
continue
85+
} else if nodeName != n.Name && nodeName != m {
86+
continue
87+
}
88+
}
89+
7690
status, err := Status(api, m)
7791
if err != nil {
7892
klog.Warningf("error getting status for %s: %v", m, err)

Diff for: site/content/en/docs/commands/image.md

+2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ minikube image build .
5656
### Options
5757

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

0 commit comments

Comments
 (0)