kubernetes/kops · error

--name is required

Error message

--name is required

What it means

The `kops delete instance` command's Args validator sets options.ClusterName from the root command's cluster name resolution; if it is empty the command is rejected with this error before any deletion attempt.

Source

Thrown at cmd/kops/delete_instance.go:124

		# Delete an instance from the currently active cluster without
		validation or draining.
		kops delete instance --cloudonly i-0a5ed581b862d3425 --yes
		`))

	deleteInstanceShort := i18n.T(`Delete an instance.`)

	var options DeleteInstanceOptions
	options.initDefaults()

	cmd := &cobra.Command{
		Use:     "instance INSTANCE|NODE",
		Short:   deleteInstanceShort,
		Long:    deleteInstanceLong,
		Example: deleteInstanceExample,
		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 ID of instance or name of node to delete")
			}
			options.InstanceID = args[0]

			if len(args) != 1 {
				return fmt.Errorf("can only delete one instance at a time")
			}

			return nil
		},
		ValidArgsFunction: completeInstanceOrNode(f, &options),
		RunE: func(cmd *cobra.Command, args []string) error {
			return RunDeleteInstance(cmd.Context(), f, out, &options)
		},
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass `--name <cluster.example.com>` to the command.
  2. Export KOPS_CLUSTER_NAME=<cluster.example.com>.
  3. Ensure KOPS_STATE_STORE is set so the cluster name can be resolved.

Example fix

// before
kops delete instance i-0abc123
// after
kops delete instance i-0abc123 --name cluster.example.com
Defensive patterns

Strategy: validation

Validate before calling

if clusterName == "" {
    return fmt.Errorf("--name or KOPS_CLUSTER_NAME must be set for kops delete instance")
}
args = append(args, "--name", clusterName)

Prevention

When it happens

Trigger: Running `kops delete instance <id>` without --name, KOPS_CLUSTER_NAME, or a kops-configured default cluster so rootCommand.ClusterName(true) returns "".

Common situations: Scripted deletions in CI without env vars; fresh machines without kops state store context; typos in the --name flag.

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/aa69ef7055943599. Report an issue: GitHub.