kubernetes/kops · error
--name is required
Error message
--name is required
What it means
`kops toolbox instance-selector` needs to know which cluster to compute instance types for. The command resolves the cluster name from rootCommand.ClusterName(true) (the --name flag or context). If it resolves to empty, Args validation returns this error before any cluster access.
Source
Thrown at cmd/kops/toolbox_instance-selector.go:126
toolboxInstanceSelectorShort = i18n.T(`Generate instance-group specs by providing resource specs such as vcpus and memory.`)
)
// NewCmdToolboxInstanceSelector defines the cobra command for the instance-selector tool
func NewCmdToolboxInstanceSelector(f commandutils.Factory, out io.Writer) *cobra.Command {
options := &InstanceSelectorOptions{}
commandline := cli.New(
"instance-selector INSTANCE_GROUP",
toolboxInstanceSelectorShort,
toolboxInstanceSelectorLong,
toolboxInstanceSelectorExample,
nil,
)
commandline.Command.Args = func(cmd *cobra.Command, args []string) error {
options.ClusterName = rootCommand.ClusterName(true)
if options.ClusterName == "" {
return fmt.Errorf("--name is required")
}
if len(args) == 0 {
return fmt.Errorf("must specify name of instance group to create")
}
options.InstanceGroupName = args[0]
if len(args) != 1 {
return fmt.Errorf("can only create one instance group at a time")
}
if err := processAndValidateFlags(&commandline); err != nil {
return err
}
setInstanceSelectorOpts(options, &commandline)
return nilView on GitHub (pinned to 4c8573c808)
Solutions
- Pass the cluster explicitly: kops toolbox instance-selector --name <cluster> nodes
- Or set KOPS_CLUSTER_NAME in the environment
- Verify with `kops get clusters` that the intended cluster exists and use its full name
Example fix
// before kops toolbox instance-selector nodes // after kops toolbox instance-selector --name mycluster.k8s.local nodes
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "${KOPS_CLUSTER_NAME:-}" ] && [[ "$*" != *--name* ]]; then
echo "--name is required" >&2; exit 2
fi Prevention
- Export KOPS_CLUSTER_NAME in CI
- Always pass --name explicitly
- Verify with kops get clusters
When it happens
Trigger: Running `kops toolbox instance-selector <ig-name>` without --name and without a kops context/default cluster configured.
Common situations: Scripts running outside a directory/context that supplies a cluster name; forgetting --name; KOPS_CLUSTER_NAME unset; using kubectl-style context assumptions that kops doesn't share.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- must specify name of instance group to create
- can only create one instance group at a time
- unsupported output format: %q
- at least one channel URL is required
- unsupported output type %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/c3e60bf5a173f20a.
Report an issue: GitHub.