kubernetes/kops · error

can only create one instance group at a time

Error message

can only create one instance group at a time

What it means

Argument-count guard in the cobra Args validator of `kops toolbox instance-selector`: more than one positional instance-group name was supplied. The command accepts exactly one instance group name per invocation.

Source

Thrown at cmd/kops/toolbox_instance-selector.go:136

		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 nil
	}
	commandline.Command.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		commandutils.ConfigureKlogForCompletion()
		if len(args) == 1 && rootCommand.ClusterName(false) == "" {
			return []string{"--name"}, cobra.ShellCompDirectiveNoFileComp
		}
		return nil, cobra.ShellCompDirectiveNoFileComp
	}
	commandline.Command.RunE = func(cmd *cobra.Command, args []string) error {
		return RunToolboxInstanceSelector(cmd.Context(), f, out, &commandline, options)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Run the command once per instance group
  2. Quote a single argument if it contains spaces (rare): "my ig"
  3. Check shell variable quoting in scripts so an empty variable doesn't shift positions

Example fix

// before
kops toolbox instance-selector nodes bastions --name mycluster.k8s.local
// after
kops toolbox instance-selector nodes --name mycluster.k8s.local
kops toolbox instance-selector bastions --name mycluster.k8s.local
Defensive patterns

Strategy: validation

Validate before calling

set -- ${EXTRA_ARGS:-}
if [ "$#" -gt 1 ]; then
  echo "only one instance group per invocation" >&2
  exit 2
fi

Prevention

When it happens

Trigger: Running `kops toolbox instance-selector nodes bastions --name <cluster>` or otherwise passing two or more positional names.

Common situations: Trying to update several instance groups in one command; leftover args in a loop script; quoting mistakes splitting an argument into multiple positionals.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/3baf0022f4d79fc2. Report an issue: GitHub.