Allow overriding image name in 'kind create'

This commit is contained in:
James Munnelly
2018-09-07 18:11:16 +01:00
committed by Benjamin Elder
parent 6d93e34400
commit 84eac63e7c

View File

@@ -27,8 +27,9 @@ import (
)
type flags struct {
Name string
Config string
Name string
Config string
ImageName string
}
// NewCommand returns a new cobra.Command for cluster creation
@@ -45,6 +46,7 @@ func NewCommand() *cobra.Command {
}
cmd.Flags().StringVar(&flags.Name, "name", "1", "the cluster name")
cmd.Flags().StringVar(&flags.Config, "config", "", "path to create config file")
cmd.Flags().StringVar(&flags.ImageName, "image", "", "name of the image to use for booting the cluster. If this is non-empty, it will override the value specified in the --config file.")
return cmd
}
@@ -70,7 +72,16 @@ func run(flags *flags, cmd *cobra.Command, args []string) {
if err != nil {
log.Fatalf("Failed to create cluster context! %v", err)
}
err = ctx.Create(cfg.ToCurrent())
convertedCfg := cfg.ToCurrent()
if flags.ImageName != "" {
convertedCfg.Image = flags.ImageName
err := convertedCfg.Validate()
if err != nil {
log.Errorf("Invalid flags, configuration failed validation: %v", err)
log.Fatal("Aborting due to invalid configuration.")
}
}
err = ctx.Create(convertedCfg)
if err != nil {
log.Fatalf("Failed to create cluster: %v", err)
}