Merge pull request #12149 from afbjorklund/build-cp
Build images on the primary control planepull/12613/head
commit
2fd09e11a8
|
@ -35,6 +35,10 @@ import (
|
||||||
docker "k8s.io/minikube/third_party/go-dockerclient"
|
docker "k8s.io/minikube/third_party/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
allNodes bool
|
||||||
|
)
|
||||||
|
|
||||||
// imageCmd represents the image command
|
// imageCmd represents the image command
|
||||||
var imageCmd = &cobra.Command{
|
var imageCmd = &cobra.Command{
|
||||||
Use: "image COMMAND",
|
Use: "image COMMAND",
|
||||||
|
@ -306,7 +310,7 @@ var buildImageCmd = &cobra.Command{
|
||||||
// Otherwise, assume it's a tar
|
// 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)
|
exit.Error(reason.GuestImageBuild, "Failed to build image", err)
|
||||||
}
|
}
|
||||||
if tmp != "" {
|
if tmp != "" {
|
||||||
|
@ -387,6 +391,8 @@ func init() {
|
||||||
buildImageCmd.Flags().StringVarP(&dockerFile, "file", "f", "", "Path to the Dockerfile to use (optional)")
|
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(&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().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(buildImageCmd)
|
||||||
saveImageCmd.Flags().BoolVar(&imgDaemon, "daemon", false, "Cache image to docker daemon")
|
saveImageCmd.Flags().BoolVar(&imgDaemon, "daemon", false, "Cache image to docker daemon")
|
||||||
saveImageCmd.Flags().BoolVar(&imgRemote, "remote", false, "Cache image to remote registry")
|
saveImageCmd.Flags().BoolVar(&imgRemote, "remote", false, "Cache image to remote registry")
|
||||||
|
|
|
@ -40,7 +40,7 @@ import (
|
||||||
var buildRoot = path.Join(vmpath.GuestPersistentDir, "build")
|
var buildRoot = path.Join(vmpath.GuestPersistentDir, "build")
|
||||||
|
|
||||||
// BuildImage builds image to all profiles
|
// 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()
|
api, err := NewAPIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "api")
|
return errors.Wrap(err, "api")
|
||||||
|
@ -70,9 +70,23 @@ func BuildImage(path string, file string, tag string, push bool, env []string, o
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cp, err := config.PrimaryControlPlane(p.Config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, n := range c.Nodes {
|
for _, n := range c.Nodes {
|
||||||
m := config.MachineName(*c, n)
|
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)
|
status, err := Status(api, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Warningf("error getting status for %s: %v", m, err)
|
klog.Warningf("error getting status for %s: %v", m, err)
|
||||||
|
|
|
@ -56,9 +56,11 @@ minikube image build .
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
|
--all Build image on all nodes.
|
||||||
--build-env stringArray Environment variables to pass to the build. (format: key=value)
|
--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)
|
--build-opt stringArray Specify arbitrary flags to pass to the build. (format: key=value)
|
||||||
-f, --file string Path to the Dockerfile to use (optional)
|
-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)
|
--push Push the new image (requires tag)
|
||||||
-t, --tag string Tag to apply to the new image (optional)
|
-t, --tag string Tag to apply to the new image (optional)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue