Merge pull request #12149 from afbjorklund/build-cp

Build images on the primary control plane
pull/12613/head
Medya Ghazizadeh 2021-09-27 19:11:04 -07:00 committed by GitHub
commit 2fd09e11a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -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",
@ -306,7 +310,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 != "" {
@ -387,6 +391,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)
saveImageCmd.Flags().BoolVar(&imgDaemon, "daemon", false, "Cache image to docker daemon")
saveImageCmd.Flags().BoolVar(&imgRemote, "remote", false, "Cache image to remote registry")

View File

@ -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")
@ -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)

View File

@ -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)
```