mirror of
https://github.com/kubernetes-sigs/kind.git
synced 2025-12-01 07:26:05 +07:00
Allow overriding image name in 'kind create'
This commit is contained in:
committed by
Benjamin Elder
parent
6d93e34400
commit
84eac63e7c
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user