kubernetes/kops · error

--name is required

Error message

--name is required

What it means

After argument validation, the command resolves the cluster name from rootCommand.ClusterName(true). If it is empty, the command requires the --name flag to identify which cluster's secret to delete. Secrets are cluster-scoped, so the cluster name is mandatory.

Source

Thrown at cmd/kops/delete_secret.go:75

				options.SecretType = args[0]
				return nil
			}

			if len(args) > 0 && args[0] == "secret" {
				args = args[1:]
			}

			if len(args) == 0 {
				return fmt.Errorf("secret name is required")
			}
			if len(args) > 1 {
				return fmt.Errorf("too many arguments")
			}
			options.SecretNames = args
			options.ClusterName = rootCommand.ClusterName(true)

			if options.ClusterName == "" {
				return fmt.Errorf("--name is required")
			}

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

	return cmd
}

func RunDeleteSecret(ctx context.Context, f *util.Factory, out io.Writer, options *DeleteSecretOptions) error {
	if options.SecretType == "sshpublickey" {
		return RunDeleteSSHPublicKey(ctx, f, out, &DeleteSSHPublicKeyOptions{
			ClusterName: options.ClusterName,
		})

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Add --name <cluster> to the command
  2. Set the KOPS_CLUSTER_NAME environment variable in scripts/CI
  3. cd into the cluster's state or use kops export kubecfg so the cluster name can be inferred

Example fix

// before
kops delete secret dockerconfig
// after
kops delete secret dockerconfig --name mycluster.k8s.local
Defensive patterns

Strategy: validation

Validate before calling

CLUSTER=${KOPS_CLUSTER_NAME:?set --name or KOPS_CLUSTER_NAME}
kops delete secret "$SECRET_NAME" --name "$CLUSTER"

Prevention

When it happens

Trigger: `kops delete secret <name>` with no --name flag, no KOPS_CLUSTER_NAME env var, and no cluster set in $KOPS_STATE_STORE/<cluster> context (e.g. not run from within a cluster directory).

Common situations: Running the command outside a kOps context without --name; missing KOPS_CLUSTER_NAME in CI scripts.

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