kubernetes/kops · error
--name is required
Error message
--name is required
What it means
The `kops get secrets` command validates that a cluster name is available before running. kOps stores secrets per-cluster, so without a cluster name it cannot know which secret store to query. The name comes from the --name flag, the --name flag on the command, or the KOPS_CLUSTER_NAME environment variable; if none is set, Args returns this error before RunE executes.
Source
Thrown at cmd/kops/get_secrets.go:65
Type string
SecretNames []string
}
func NewCmdGetSecrets(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {
options := GetSecretsOptions{
GetOptions: getOptions,
}
cmd := &cobra.Command{
Use: "secrets [SECRET_NAME]...",
Aliases: []string{"secret"},
Short: getSecretShort,
Example: getSecretExample,
Args: func(cmd *cobra.Command, args []string) error {
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 RunGetSecrets(cmd.Context(), f, out, &options)
},
}
cmd.Flags().StringVarP(&options.Type, "type", "", "", "Filter by secret type")
cmd.Flags().MarkHidden("type")
return cmd
}
func listSecrets(secretStore fi.SecretStore, names []string) ([]string, error) {
items, err := secretStore.ListSecrets()
if err != nil {View on GitHub (pinned to 4c8573c808)
Solutions
- Pass --name <clustername> to the kops get secrets command
- Export KOPS_CLUSTER_NAME=<clustername> in the environment or CI pipeline
- cd into a directory whose kubectl context maps to the target cluster so kops can infer the name
- Run `kops get clusters` first to list valid cluster names
Example fix
// before kops get secrets // after kops get secrets --name mycluster.example.com
Defensive patterns
Strategy: validation
Validate before calling
clusterName := rootCommand.ClusterName(true)
if clusterName == "" {
return fmt.Errorf("--name is required")
}
// or in shell:
// [ -n "$KOPS_CLUSTER_NAME" ] || KOPS_CLUSTER_NAME=mycluster.example.com Prevention
- Always pass --name explicitly in scripts
- Set KOPS_CLUSTER_NAME in CI environments
- Run `kops get clusters` first to validate the cluster name
When it happens
Trigger: Running `kops get secrets` with no --name flag, no KOPS_CLUSTER_NAME env var, and no cluster configured in the current kops state; also running from a directory where kops cannot infer the cluster from a kubectl context.
Common situations: Scripting kops in CI without KOPS_CLUSTER_NAME set; running against a fresh state store with no default cluster; users who normally rely on kubectl context inference but run from an unrelated directory.
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
- --name is required
- must specify %q label with cluster name to create instanceGr
- error querying cluster %q: %v
- cluster %q not found
- instanceGroup %q already exists
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/a746ca2858c2ad27.
Report an issue: GitHub.