kubernetes/kops · error

--name is required

Error message

--name is required

What it means

`kops get instancegroups` requires a target cluster, resolved from the global --name flag (or KOPS_CLUSTER_NAME env) via rootCommand.ClusterName(true). The Args validator returns '--name is required' when neither is set, because instance groups can only be listed within a specific cluster.

Source

Thrown at cmd/kops/get_instancegroups.go:74

	*GetOptions
	InstanceGroupNames []string
}

func NewCmdGetInstanceGroups(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {
	options := GetInstanceGroupsOptions{
		GetOptions: getOptions,
	}

	cmd := &cobra.Command{
		Use:     "instancegroups [INSTANCE_GROUP]...",
		Aliases: []string{"instancegroup", "ig"},
		Short:   getInstancegroupsShort,
		Long:    getInstancegroupsLong,
		Example: getInstancegroupsExample,
		Args: func(cmd *cobra.Command, args []string) error {
			options.ClusterName = rootCommand.ClusterName(true)
			if options.ClusterName == "" {
				return fmt.Errorf("--name is required")
			}

			options.InstanceGroupNames = args
			return nil
		},
		ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
			return completeInstanceGroup(f, &args, nil)(cmd, nil, toComplete)
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			return RunGetInstanceGroups(cmd.Context(), f, out, &options)
		},
	}

	return cmd
}

func RunGetInstanceGroups(ctx context.Context, f commandutils.Factory, out io.Writer, options *GetInstanceGroupsOptions) error {
	clientset, err := f.KopsClient()

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass the cluster explicitly: `kops get instancegroups --name mycluster.example.com`.
  2. Export KOPS_CLUSTER_NAME=mycluster.example.com for the session/script.
  3. Set --state together with --name if the cluster lives in a non-default state store.

Example fix

// before
kops get instancegroups
// after
kops get instancegroups --name mycluster.example.com
Defensive patterns

Strategy: validation

Validate before calling

[ -n "${KOPS_CLUSTER_NAME:-}" ] || set -- "--name" "${1:-$(kops get clusters -o json | jq -r '.items[0].metadata.name')}"
kops get instancegroups "$@"

Type guard

null

Try / catch

if ! kops get instancegroups 2>err.txt; then
  grep -q -- '--name is required' err.txt && \
    echo "pass --name <cluster> or export KOPS_CLUSTER_NAME"
fi

Prevention

When it happens

Trigger: `kops get instancegroups` (optionally with group names) run without --name and without KOPS_CLUSTER_NAME exported.

Common situations: Forgetting to export KOPS_CLUSTER_NAME in scripts; running the command in a fresh shell/CI job; using the kubecfg current-context expectation where kops actually needs an explicit name.

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


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