kubernetes/kops · error

--name is required (for safety)

Error message

--name is required (for safety)

What it means

RunDeleteCluster refuses to proceed without an explicit cluster name. Because cluster deletion is destructive and operates on the state store, kOps requires --name (or the -n flag / KOPS_CLUSTER_NAME) so the exact cluster being destroyed is unambiguous.

Source

Thrown at cmd/kops/delete_cluster.go:108

	cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Specify --yes to delete the cluster")
	cmd.Flags().BoolVar(&options.Unregister, "unregister", options.Unregister, "Don't delete cloud resources, just unregister the cluster")
	cmd.Flags().BoolVar(&options.External, "external", options.External, "Delete an external cluster")

	cmd.Flags().StringVar(&options.Region, "region", options.Region, "External cluster's cloud region")
	cmd.RegisterFlagCompletionFunc("region", completeRegion)

	cmd.Flags().DurationVar(&options.wait, "wait", options.wait, "Amount of time to wait for the cluster resources to de deleted")
	cmd.Flags().IntVar(&options.count, "count", options.count, "Number of consecutive failures to make progress deleting the cluster resources")
	cmd.Flags().DurationVar(&options.interval, "interval", options.interval, "Time in duration to wait between deletion attempts")

	return cmd
}

func RunDeleteCluster(ctx context.Context, f *util.Factory, out io.Writer, options *DeleteClusterOptions) error {
	clusterName := options.ClusterName
	if clusterName == "" {
		return fmt.Errorf("--name is required (for safety)")
	}

	var cloud fi.Cloud
	var cluster *kopsapi.Cluster
	var err error

	if options.External {
		region := options.Region
		if region == "" {
			return fmt.Errorf("--region is required (when --external)")
		}

		tags := map[string]string{"KubernetesCluster": clusterName}
		cloud, err = awsup.NewAWSCloud(region, tags)
		if err != nil {
			return fmt.Errorf("error initializing AWS client: %v", err)
		}
	} else {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Add `--name <cluster.example.com>` to the `kops delete cluster` command.
  2. Set the KOPS_CLUSTER_NAME environment variable before running the command.
  3. In code/tests calling RunDeleteCluster directly, set options.ClusterName before invoking.

Example fix

// before
kops delete cluster --yes
// after
kops delete cluster --name cluster.example.com --yes
Defensive patterns

Strategy: validation

Validate before calling

name := os.Getenv("KOPS_CLUSTER_NAME")
if name == "" {
    return fmt.Errorf("pass --name or set KOPS_CLUSTER_NAME before deleting a cluster")
}
args = append(args, "--name", name)

Prevention

When it happens

Trigger: Running `kops delete cluster` without --name, without a KOPS_CLUSTER_NAME environment variable, and without a cluster set in the kops context so options.ClusterName is empty.

Common situations: Scripted/CI jobs where the env var is unset; users relying on `kubectl` context that kOps does not read; running from a directory without a kops default cluster 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/9452a05683cec993. Report an issue: GitHub.